Skip to content

Commit 702042b

Browse files
Merge pull request #5 from im-open/build-update
ARCH-1617 - Updating action build
2 parents 25e1a03 + 2998477 commit 702042b

File tree

5 files changed

+74
-70
lines changed

5 files changed

+74
-70
lines changed

.github/workflows/build.yml

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,65 @@ on:
44
# access to the target repository from public forks. This should remain as a pull_request
55
# trigger because checkout, build, format and checking for changes do not need elevated
66
# permissions to the repository. The reduced permissions for public forks is adequate.
7+
# Since this will commit readme/recompile changes back to the branch, special attention
8+
# should be paid to changes made to this workflow when reviewing the PR and granting
9+
# permission to first time contributors to run the workflow.
710
pull_request:
8-
# Don't include any specific paths here so we always get a build that produces a status
9-
# check that our Branch Protection Rules can use. Having a status check also allows us
10-
# to require that branches be up to date before they are merged.
11-
11+
# Don't include any specific paths here so we always get a build that produces a status
12+
# check that our Branch Protection Rules can use. Having a status check also allows us
13+
# to require that branches be up to date before they are merged.
14+
1215
jobs:
1316
build:
14-
runs-on: ${{ matrix.operating-system }}
15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
19-
17+
runs-on: ubuntu-latest
18+
2019
steps:
2120
- name: Checkout
2221
uses: actions/checkout@v3
22+
with:
23+
ref: ${{ github.head_ref }}
24+
fetch-depth: 0
25+
2326
- name: Setup Node.js 16
2427
uses: actions/setup-node@v3
2528
with:
2629
node-version: 16.x
27-
- name: Build
30+
31+
# If this step results in changes, they will be committed in the last step
32+
- name: Recompile and Format action
2833
run: npm run build
29-
- name: Format
30-
run: npm run format
31-
- name: Check for unstaged changes
32-
if: runner.os != 'windows'
33-
run: ./check-for-unstaged-changes.sh
34+
35+
- name: Check for code changes to the action
36+
id: action-code
37+
uses: im-open/did-custom-action-code-change@v1.0.1
38+
with:
39+
files-with-code: 'action.yml,package.json,package-lock.json'
40+
folders-with-code: 'src,dist'
41+
token: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Get the next version for the readme if there are code changes to the action
44+
if: steps.action-code.outputs.HAS_CHANGES == 'true'
45+
id: version
46+
uses: im-open/git-version-lite@v2.1.2
47+
48+
- name: Update readme with next version if there are code changes to the action
49+
if: steps.action-code.outputs.HAS_CHANGES == 'true'
50+
uses: im-open/update-action-version-in-file@v1.0.0
51+
with:
52+
file-to-update: './README.md'
53+
action-name: ${{ github.repository }}
54+
updated-version: ${{ steps.version.outputs.NEXT_VERSION }}
55+
56+
- name: Commit unstaged readme/recompile changes if there are code changes to the action
57+
if: steps.action-code.outputs.HAS_CHANGES == 'true'
58+
run: |
59+
if [[ "$(git status --porcelain)" != "" ]]; then
60+
echo "There are changes to commit"
61+
git config user.name github-actions
62+
git config user.email github-actions@github.com
63+
git add .
64+
git commit -m "Update readme with latest version and/or recompile the action."
65+
git push origin HEAD:${{ github.head_ref }}
66+
else
67+
echo "There were no changes to commit"
68+
fi

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,39 @@ This action does not generate the code coverage reports itself, those must be cr
8282
## Contributing
8383
8484
When creating new PRs please ensure:
85-
1. The action has been recompiled. See the [Recompiling](#recompiling) section below for more details.
86-
2. For major or minor changes, at least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version](#incrementing-the-version).
87-
3. The `README.md` example has been updated with the new version. See [Incrementing the Version](#incrementing-the-version).
88-
4. The action code does not contain sensitive information.
8985
90-
### Recompiling
86+
1. For major or minor changes, at least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version](#incrementing-the-version).
87+
1. The action code does not contain sensitive information.
9188

92-
If changes are made to the action's code in this repository, or its dependencies, you will need to re-compile the action.
89+
When a pull request is created and there are changes to code-specific files and folders, the build workflow will run and it will recompile the action and push a commit to the branch if the PR author has not done so. The usage examples in the README.md will also be updated with the next version if they have not been updated manually. The following files and folders contain action code and will trigger the automatic updates:
90+
91+
- action.yml
92+
- package.json
93+
- package-lock.json
94+
- src/\*\*
95+
- dist/\*\*
96+
97+
There may be some instances where the bot does not have permission to push changes back to the branch though so these steps should be done manually for those branches. See [Recompiling Manually](#recompiling-manually) and [Incrementing the Version](#incrementing-the-version) for more details.
98+
99+
### Recompiling Manually
100+
101+
If changes are made to the action's code in this repository, or its dependencies, the action can be re-compiled by running the following command:
93102

94103
```sh
95104
# Installs dependencies and bundles the code
96105
npm run build
106+
107+
# Bundle the code (if dependencies are already installed)
108+
npm run bundle
97109
```
98110

99-
These commands utilize [ncc](https://github.com/vercel/ncc) to bundle the action and its dependencies into a single file located in the `dist` folder.
111+
These commands utilize [esbuild](https://esbuild.github.io/getting-started/#bundling-for-node) to bundle the action and
112+
its dependencies into a single file located in the `dist` folder.
100113

101114
### Incrementing the Version
102115

116+
Both the build and PR merge workflows will use the strategies below to determine what the next version will be. If the build workflow was not able to automatically update the README.md action examples with the next version, the README.md should be updated manually as part of the PR using that calculated version.
117+
103118
This action uses [git-version-lite] to examine commit messages to determine whether to perform a major, minor or patch increment on merge. The following table provides the fragment that should be included in a commit message to active different increment strategies.
104119
| Increment Type | Commit Message Fragment |
105120
| -------------- | ------------------------------------------- |

check-for-unstaged-changes.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

package-lock.json

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
"description": "",
55
"main": "lib/reportgenerator.js",
66
"scripts": {
7-
"build": "npm ci && tsc && ncc build",
7+
"build": "npm ci && tsc && ncc build && npm run format",
88
"format": "prettier --write **/*.js",
99
"format-check": "prettier --check **/*.js"
1010
},
11-
"husky": {
12-
"hooks": {
13-
"pre-commit": "npm run build && npm run format",
14-
"pre-push": "npm run format-check"
15-
}
16-
},
1711
"keywords": [
1812
"code-coverage",
1913
"testing",
@@ -30,7 +24,6 @@
3024
"devDependencies": {
3125
"@types/node": "^14.11.2",
3226
"@zeit/ncc": "^0.22.3",
33-
"husky": "^7.0.1",
3427
"prettier": "^2.3.2",
3528
"typescript": "^4.0.3"
3629
}

0 commit comments

Comments
 (0)