Skip to content

ARCH-1617 - Updating action build #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,65 @@ on:
# access to the target repository from public forks. This should remain as a pull_request
# trigger because checkout, build, format and checking for changes do not need elevated
# permissions to the repository. The reduced permissions for public forks is adequate.
# Since this will commit readme/recompile changes back to the branch, special attention
# should be paid to changes made to this workflow when reviewing the PR and granting
# permission to first time contributors to run the workflow.
pull_request:
# Don't include any specific paths here so we always get a build that produces a status
# check that our Branch Protection Rules can use. Having a status check also allows us
# to require that branches be up to date before they are merged.
# Don't include any specific paths here so we always get a build that produces a status
# check that our Branch Protection Rules can use. Having a status check also allows us
# to require that branches be up to date before they are merged.

jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Build

# If this step results in changes, they will be committed in the last step
- name: Recompile and Format action
run: npm run build
- name: Format
run: npm run format
- name: Check for unstaged changes
if: runner.os != 'windows'
run: ./check-for-unstaged-changes.sh

- name: Check for code changes to the action
id: action-code
uses: im-open/did-custom-action-code-change@v1.0.1
with:
files-with-code: 'action.yml,package.json,package-lock.json'
folders-with-code: 'src,dist'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Get the next version for the readme if there are code changes to the action
if: steps.action-code.outputs.HAS_CHANGES == 'true'
id: version
uses: im-open/git-version-lite@v2.1.2

- name: Update readme with next version if there are code changes to the action
if: steps.action-code.outputs.HAS_CHANGES == 'true'
uses: im-open/update-action-version-in-file@v1.0.0
with:
file-to-update: './README.md'
action-name: ${{ github.repository }}
updated-version: ${{ steps.version.outputs.NEXT_VERSION }}

- name: Commit unstaged readme/recompile changes if there are code changes to the action
if: steps.action-code.outputs.HAS_CHANGES == 'true'
run: |
if [[ "$(git status --porcelain)" != "" ]]; then
echo "There are changes to commit"
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Update readme with latest version and/or recompile the action."
git push origin HEAD:${{ github.head_ref }}
else
echo "There were no changes to commit"
fi
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,39 @@ This action does not generate the code coverage reports itself, those must be cr
## Contributing

When creating new PRs please ensure:
1. The action has been recompiled. See the [Recompiling](#recompiling) section below for more details.
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).
3. The `README.md` example has been updated with the new version. See [Incrementing the Version](#incrementing-the-version).
4. The action code does not contain sensitive information.

### Recompiling
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).
1. The action code does not contain sensitive information.

If changes are made to the action's code in this repository, or its dependencies, you will need to re-compile the action.
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:

- action.yml
- package.json
- package-lock.json
- src/\*\*
- dist/\*\*

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.

### Recompiling Manually

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:

```sh
# Installs dependencies and bundles the code
npm run build

# Bundle the code (if dependencies are already installed)
npm run bundle
```

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.
These commands utilize [esbuild](https://esbuild.github.io/getting-started/#bundling-for-node) to bundle the action and
its dependencies into a single file located in the `dist` folder.

### Incrementing the Version

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.

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.
| Increment Type | Commit Message Fragment |
| -------------- | ------------------------------------------- |
Expand Down
17 changes: 0 additions & 17 deletions check-for-unstaged-changes.sh

This file was deleted.

22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
"description": "",
"main": "lib/reportgenerator.js",
"scripts": {
"build": "npm ci && tsc && ncc build",
"build": "npm ci && tsc && ncc build && npm run format",
"format": "prettier --write **/*.js",
"format-check": "prettier --check **/*.js"
},
"husky": {
"hooks": {
"pre-commit": "npm run build && npm run format",
"pre-push": "npm run format-check"
}
},
"keywords": [
"code-coverage",
"testing",
Expand All @@ -30,7 +24,6 @@
"devDependencies": {
"@types/node": "^14.11.2",
"@zeit/ncc": "^0.22.3",
"husky": "^7.0.1",
"prettier": "^2.3.2",
"typescript": "^4.0.3"
}
Expand Down