Bypass required Status Checks in GitHub

Viewed 1057

I am trying to use GitHub Actions to automatically increment the version of my project while building the artifact and check the new changes back into the main branch.

The workflow pushes the commit using a PAT for an account that is used only for this purpose so I was able to exclude that user from the branch protection rule requiring a PR for the main branch.

Because there is also a Required Status check for that branch the push fails with

remote: error: GH006: Protected branch update failed for refs/heads/main.        
remote: error: Required status check "build / tests" is expected.   

How can I have the version commits skip this check while enforcing this check for all other commits?

2 Answers

I faced the same problem few days back. In case you're using standard-version then in the package.json you can do something like:

"standard-version": {
    "releaseCommitMessageFormat": "chore(release): {{currentTag}}\n[ci skip]",
  },

and in the Github Workflow build / tests you can add a condition to skip tests in case a push is tagged with [ci skip] like this:

if: "!contains(github.event.head_commit.message, '[ci skip]')"

Reference

I had the same issue and tried many different potential solutions. The only thing I could do to get it to work was to create an account with admin permissions, allow force pushes only for that account, not enforce branch protection rules for admins, and then force push the changes (I'm using this action).

The workflow basically looks like this:

jobs:
  update-config:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.head_ref }}
        token: ${{ secrets.SERVICE_ACCOUNT_GITHUB }}
        submodules: true
        fetch-depth: 0
    ## do my update ##
    - name: Add and commit change
      run: |
        git config --local user.email "github-actions[bot]@users.noreply.github.com"
        git config --local user.name "github-actions[bot]"
        git commit -m "Bump version" -a
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.head_ref }}
        force: true
Related