check-git-status-action

Do you check in dependency packages or build artefacts? If yes this GitHub Action helps you ensure they are not out-of-sync.

MIT License

Stars
4
Committers
2

check-git-status-action

Do you check in dependency packages or build artefacts? If yes this GitHub Action helps you ensure they are not out-of-sync. Examples:

  1. 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 run yarn install and then use this Action to check if the offline mirror is changed.
  2. 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.

Usage

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.

Options

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.

FAQ

The commit created by this Action doesn't trigger any Workflow.

When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_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]
Package Rankings
Top 17.46% on Github actions
Badges
Extracted from project README's
Test Release
Related Projects