Skip to content

Commit fb63da2

Browse files
Merge pull request #7 from im-open/build-refactor
ARCH-1916 - Workflow Refactor
2 parents d04ea3e + fe48a7a commit fb63da2

File tree

5 files changed

+153
-160
lines changed

5 files changed

+153
-160
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and Review PR
2+
run-name: 'Build and Review PR #${{ github.event.pull_request.number }}'
3+
4+
on:
5+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
6+
#
7+
# This workflow uses the pull_request trigger which prevents write permissions on the
8+
# GH_TOKEN and secrets access from public forks. This should remain as a pull_request
9+
# trigger to minimize the access public forks have in the repository. The reduced
10+
# permissions are adequate but do mean that re-compiles and readme changes will have to be
11+
# made manually by the PR author. These auto-updates could be done by this workflow
12+
# for branches but in order to re-trigger a PR build (which is needed for status checks),
13+
# we would make the commits with a different user and their PAT. To minimize exposure
14+
# and complication we will request those changes be manually made by the PR author.
15+
pull_request:
16+
types: [opened, synchronize, reopened]
17+
# paths:
18+
# Do not include specific paths here. We always want this build to run and produce a
19+
# status check which are branch protection rules can use. If this is skipped because of
20+
# path filtering, a status check will not be created and we won't be able to merge the PR
21+
# without disabling that requirement. If we have a status check that is always produced,
22+
# we can also use that to require all branches be up to date before they are merged.
23+
24+
jobs:
25+
build-and-review-pr:
26+
# This reusable workflow will check to see if an action's source code has changed based on
27+
# whether the PR includes files that match the files-with-code arg or are in one of the
28+
# dirs-with-code directories. If there are source code changes, this reusable workflow
29+
# will then run the action's build (if one was provided) and update the README.md with the
30+
# the latest version of the action. If those two steps result in any changes that need to
31+
# be committed, the workflow will fail because the PR needs some updates. Instructions for
32+
# updating the PR will be available in the build log, the workflow summary and as a PR
33+
# comment if the PR came from a branch (not a fork).
34+
# This workflow assumes:
35+
# - The main README.md is at the root of the repo
36+
# - The README contains a contribution guidelines and usage examples section
37+
uses: im-open/.github/.github/workflows/reusable-build-and-review-pr.yml@v1
38+
with:
39+
action-name: ${{ github.repository }}
40+
default-branch: main
41+
readme-name: 'README.md'
42+
43+
# The id of the contribution guidelines section of the README.md
44+
readme-contribution-id: '#contributing'
45+
46+
# The id of the usage examples section of the README.md
47+
readme-examples-id: '#usage-examples'
48+
49+
# The files that contain source code for the action. Only files that affect the action's execution
50+
# should be included like action.yml or package.json. Do not include files like README.md or .gitignore.
51+
# Files do not need to be explicitly provided here if they fall under one of the dirs in dirs-with-code.
52+
# ** This value must match the same files-with-code argument specified in increment-version-on-merge.yml.
53+
files-with-code: 'action.yml,package.json,package-lock.json'
54+
55+
# The directories that contain source code for the action. Only dirs with files that affect the action's
56+
# execution should be included like src or dist. Do not include dirs like .github or node_modules.
57+
# ** This value must match the same dirs-with-code argument specified in increment-version-on-merge.yml.
58+
dirs-with-code: 'src,dist'
59+
60+
# The npm script to run to build the action. This is typically 'npm run build' if the
61+
# action needs to be compiled. For composite-run-steps actions this is typically empty.
62+
build-command: 'npm run build'

.github/workflows/build.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,47 @@
11
name: Increment Version on Merge
2+
run-name: "${{ github.event.pull_request.merged && 'Increment version for' || 'Closing' }} PR #${{ github.event.pull_request.number }}"
23
on:
34
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
4-
# - GitHub’s standard pull_request workflow trigger prevents write permissions and secrets
5-
# access to the target repository from public forks. PRs from a branch in the same repo
6-
# and forks of internal/private repos are not limited the same way for this trigger.
7-
# - The pull_request_target trigger allows the workflow to relax some restrictions to a
8-
# target repository so PRs from forks have write permission to the target repo and have
9-
# secrets access (which we need in order to push a new tag in this workflow).
10-
# - For this workflow, the elevated permissions should not be a problem because:
11-
# - Our im-open repositories do not contain secrets, they are dumb actions
12-
# - Require approval for all outside collaborators' is set at the org level so someone
13-
# with Write access has a chance to review code before allowing any workflow runs
14-
# - This workflow with elevated Write permissions will only run once the code has been
15-
# reviewed, approved by a CODEOWNER and merged
5+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
6+
#
7+
# GitHub's standard pull_request workflow trigger prevents write permissions and
8+
# secrets access when the PR is from a public fork. PRs from branches and forks of
9+
# internal/private repos are not limited the same way for the pull_request trigger.
10+
#
11+
# The pull_request_target trigger (which this workflow is using) relaxes some of those
12+
# restrictions and allows PRs from public forks to have write permissions through the
13+
# GH_TOKEN which we need in order to push new tags to the repo through this workflow.
14+
#
15+
# For this workflow, the elevated permissions should not be a problem because:
16+
# • This workflow is only triggered when a PR is closed and the reusable workflow it
17+
# calls only executes if it has been merged to the default branch. This means the PR
18+
# has been reviewed and approved by a CODEOWNER and merged by someone with Write
19+
# access before this workflow with its elevated permissions gets executed. Any code
20+
# that doesn't meet our standards should be caught before it gets to this point.
21+
# • The "Require approval for all outside collaborators" setting is set at the org-level.
22+
# Before a workflow can execute for a PR generated by an outside collaborator, a user
23+
# with Write access must manually approve the request to execute the workflow run.
24+
# Prior to doing so they should have had a chance to review any changes in the PR
1625
pull_request_target:
1726
types: [closed]
18-
paths:
19-
- 'dist/**'
20-
- 'src/**'
21-
- 'action.yml'
22-
- 'package.json'
23-
- 'package-lock.json'
27+
# paths:
28+
# Do not include specific paths here. reusable-increment-version-on-merge.yml will decide
29+
# if this action should be incremented and if new tags should be pushed to the repo based
30+
# on the same criteria used in the build-and-review-pr.yml workflow.
2431

2532
jobs:
2633
increment-version:
27-
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
34+
uses: im-open/.github/.github/workflows/reusable-increment-version-on-merge.yml@v1
35+
with:
36+
default-branch: main
2837

29-
runs-on: ubuntu-latest
38+
# The files that contain source code for the action. Only files that affect the action's execution
39+
# should be included like action.yml or package.json. Do not include files like README.md or .gitignore.
40+
# Files do not need to be explicitly provided here if they fall under one of the dirs in dirs-with-code.
41+
# ** This value must match the same files-with-code argument specified in increment-version-on-merge.yml.
42+
files-with-code: 'action.yml,package.json,package-lock.json'
3043

31-
steps:
32-
# Generally speaking, when the PR contents are treated as passive data, i.e. not in a
33-
# position of influence over the build/testing process, it is safe to checkout the code
34-
# on a pull_request_target. But we need to be extra careful not to trigger any script
35-
# that may operate on PR controlled contents like in the case of npm install.
36-
- name: Checkout Repository
37-
uses: actions/checkout@v3
38-
with:
39-
ref: main
40-
fetch-depth: 0
41-
42-
# See https://github.com/im-open/git-version-lite for more details around how to increment
43-
# major/minor/patch through commit messages
44-
- name: Increment the version
45-
uses: im-open/git-version-lite@v2
46-
id: version
47-
with:
48-
github-token: ${{ secrets.GITHUB_TOKEN }}
49-
50-
- name: Create version tag, create or update major, and minor tags
51-
run: |
52-
git config user.name github-actions
53-
git config user.email github-actions@github.com
54-
git tag ${{ steps.version.outputs.NEXT_VERSION }} ${{ github.sha }}
55-
git tag -f ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} ${{ github.sha }}
56-
git tag -f ${{ steps.version.outputs.NEXT_MINOR_VERSION }} ${{ github.sha }}
57-
git push origin ${{ steps.version.outputs.NEXT_VERSION }}
58-
git push origin ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} -f
59-
git push origin ${{ steps.version.outputs.NEXT_MINOR_VERSION }} -f
44+
# The directories that contain source code for the action. Only dirs with files that affect the action's
45+
# execution should be included like src or dist. Do not include dirs like .github or node_modules.
46+
# ** This value must match the same dirs-with-code argument specified in increment-version-on-merge.yml.
47+
dirs-with-code: 'src,dist'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vs
22
lib/
33
node_modules
4+
/.vscode/launch.json
45
reportgeneratortool
56
src/*.js

0 commit comments

Comments
 (0)