Do you check in dependency packages or build artefacts? If yes this GitHub Action helps you ensure they are not out-of-sync. Examples:
- Say we run Prettier or
oxfmtin CI and require developers to commit any formatting updates. We can run the formatter and then use this Action to fail the workflow, request changes, or auto-commit the formatting diff when files are out of sync. - Say we set up to run Yarn offline and we check in Yarn offline mirror. We want to make sure the offline mirror is in sync with the dependencies declared in the
package.json. We can set up a GitHub Workflow to runyarn installand then use this Action to check if the offline mirror is changed. - Say we generate TypeScript type definitions from JSON Schemas. The generated TypeScript files are part of the codebase. We want to make sure people remember to regenerate these files when they modify any JSON Schema. We can use a GitHub Workflow to run the code generation and then use this GitHub Action to check if the files are changed. If they are changed this Action can commit the changes and add them to the Pull Request.
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@v6
- name: Build
run: |
yarn prettier -w .
yarn graphql-codegen --config codegen.ts
- uses: CatChen/check-git-status-action@v2
with:
fail-if-not-clean: true # optional
push-if-not-clean: false # optional
request-changes-if-not-clean: true # optional
comment-if-not-clean: false # optional
push-token: ${{ secrets.GITHUB_TOKEN }} # optional
request-changes-token: ${{ secrets.GITHUB_TOKEN }} # optional
commit-message: 'Changes detected by Check Git Status Action' # optional
push-strategy: 'force-with-lease' # optional
request-changes-comment: 'Changes detected by Check Git Status Action' # optional
comment-message: 'Changes detected by Check Git Status Action' # optional
targets: '.' #optionalSave the file to .github/workflows/build.yml. It will start working on new Pull Requests.
When this option is set to true this action will fail if the project directory is no longer clean at the action execution time.
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.
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.
When this option is set to true and it's run on a Pull Request this action will create a comment if the project directory isn't clean.
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.
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.
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".
Controls how this action pushes updates when push-if-not-clean is true. Supported values are:
force-with-lease(default): safer force push that only updates if the remote ref still matches the pull request head SHA from the event payload.normal: regular push without any force flags.force: hard force push (--force).
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".
When comment-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. Its default value is "Changes detected by Check Git Status Action".
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.
For multiple targets, use one target per line:
targets: |
schema.graphql
src/__graphql__
src/**/*.tsUse newline-separated targets when matching multiple files or directories. This action does not perform shell expansion on targets (so brace patterns like "{src,lib}" are passed to git as literal pathspecs), but each target can still use git pathspec/glob syntax such as src/**/*.ts.
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_TOKENto perform tasks, events triggered by theGITHUB_TOKENwill 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]