Do you check in dependency packages or build artefacts? If yes this GitHub Action helps you ensure they are not out-of-sync. Examples:
package.json
. We can set up a GitHub Workflow to run yarn install
and then use this Action to check if the offline mirror is changed.Set up a GitHub Action like this:
name: Verify Build
on:
pull_request:
branches: [main] # or [master] if that's name of the main branch
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: |
# replace the following line with the real build script
touch some-build-artefact-newly-generated-in-the-build-process
- uses: CatChen/check-git-status-action@v1
with:
fail-if-not-clean: true # optional
push-if-not-clean: false # optional
request-changes-if-not-clean: true # optional
push-token: ${{ secrets.GITHUB_TOKEN }} # optional
request-changes-token: ${{ secrets.GITHUB_TOKEN }} # optional
commit-message: 'Changes detected by Check Git Status Action' # optional
request-changes-comment: 'Changes detected by Check Git Status Action' # optional
targets: '.' #optional
Save the file to .github/workflows/build.yml
. It will start working on new Pull Requests.
fail-if-not-clean
When this option is set to true
this action will fail if the project directory is no longer clean at the action execution time.
push-if-not-clean
When this option is set to true
this action will commit the new changes in the project directory and push the commit to the origin.
request-changes-if-not-clean
When this option is set to true
and it's run on a Pull Request this action will request change if the project directory isn't clean.
push-token
The default value is ${{ github.token }}
, which is the GitHub token generated for this workflow. This token determines the identity of the user that makes the commit and pushes it to the current branch. By default, it's GitHub Action bot. However, one GitHub Action doesn't trigger another. That means when a GitHub Action bot pushes to a branch it doesn't trigger any other GitHub Actions that are usually triggered by events from this branch or this Pull Request.
You can create a different token to work around this. You can also call other Workflows that aren't being triggered by this Workflow. You can add workflow_run
event to the other Workflows so they are triggered explicitly after a successful run of the current Workflow.
request-changes-token
The default value is ${{ github.token }}
, which is the GitHub token generated for this workflow. This token determines the identity of the user that requests changes. GitHub doesn't allow Pull Request author to request changes. Make sure this token doesn't represent a user that could be the Pull Request author. Usually it's fine to leave it with the default value, unless some Pull Requests are authored by the GitHub Action bot.
commit-message
When push-if-not-clean
is set to true
and git status
is not clean this option will be used as the commit message when committing the changes. Its default value is "Changes detected by Check Git Status Action"
.
request-changes-comment
When request-changes-if-not-clean
is set to true
and git status
is not clean this option will be used as the comment posted to the Pull Request along side with the request changes. Its default value is "Changes detected by Check Git Status Action"
.
targets
The default value is "."
. For example, it could be "src"
or "src/**/*.ts"
for a typical TypeScript project with source code files in the src
directory. Use glob pattern to match multiple directories if necessary, for example "{src,lib}"
instead of "src lib"
or "{src, lib}"
to match both the src
directory and the lib
directory.
github-token
(deprecated)The default value is ${{ github.token }}
, which is the GitHub token generated for this workflow. You can create a different token with a different set of permissions and use it here as well.
When you use the repository's
GITHUB_TOKEN
to perform tasks, events triggered by theGITHUB_TOKEN
will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. -- Source
Use the workflow_run
event in your other Workflows so they are triggered when this Action finishes. For example, if the Workflow running this Action is named as Verify Build
like the example from above use the following code to trigger a follow-up Workflow name Post-Verification
.
name: Post-Verification
on:
workflow_run:
branches: [master]
workflows: ['Verify Build']
types: [completed]