Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bypass required Status Checks in GitHub

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?

like image 649
Silverblaze Avatar asked Jan 19 '26 01:01

Silverblaze


2 Answers

2023-09-01

A recent feature, rulesets, provides more control, such as allowing specified actors to bypass status check requirements.

like image 115
mightyiam Avatar answered Jan 21 '26 00:01

mightyiam


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
like image 20
tgaddy Avatar answered Jan 20 '26 23:01

tgaddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!