Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version bump failed on protected branch #156

Open
gyi123 opened this issue Mar 18, 2022 · 8 comments
Open

Version bump failed on protected branch #156

gyi123 opened this issue Mar 18, 2022 · 8 comments

Comments

@gyi123
Copy link

gyi123 commented Mar 18, 2022

I have set up a branch protection rule to run a few simple unit tests before code is merged. However, once the rule is enabled, I am having issue using the version bump. Here is the error messge in github action:
✖ fatal remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: 2 of 2 required status checks are expected.

Any idea on how to resolve this?
The protection rule is set up on pull request.

Thanks

George

@leandrooriente
Copy link

I imagine you have a private Github Token, if that is the case, try this:

steps:
  - name: 'Checkout source code'
    uses: 'actions/checkout@v2'
    with:
        persist-credentials: false
        ref: ${{ github.ref }}
  - name: 'Automated Version Bump'
        id: version-bump
        uses: 'phips28/gh-action-bump-version@master'
        env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The secret is the persist-credentials: false on the checkout action.

@andirsun
Copy link

@leandrooriente does not work.

version action after first waterfall: patch
version action after final decision: patch
currentBranch: dev
current 1: 4.0.18 / version: patch
newVersion 1: 4.0.19
✖  fatal     fatal: could not read Username for 'https://github.com': No such device or address
git exited with code 1[28](https://github.com/webalys-hq/streamline-web/runs/6970316668?check_suite_focus=true#step:3:29)
✖  fatal     Failed to bump version

@ph250167
Copy link

ph250167 commented Jul 12, 2022

@leandrooriente does not work.

version action after first waterfall: patch
version action after final decision: patch
currentBranch: dev
current 1: 4.0.18 / version: patch
newVersion 1: 4.0.19
✖  fatal     fatal: could not read Username for 'https://github.com': No such device or address
git exited with code 1[28](https://github.com/webalys-hq/streamline-web/runs/6970316668?check_suite_focus=true#step:3:29)
✖  fatal     Failed to bump version

I'm having this same issue in one repo, but not another. Same token, same action setup. It works in one repo, but fails with this same error in another. Any ideas? I'm using the latest version of the action, but have tried several of the past releases to no avail.

@OfirYaron
Copy link

Having same issue with this action, tried to add persist-credentials: false - did not work.
is there a fix/additional setting that needs to be made here?

@DannyBo-Affilomania
Copy link

When adding persist-credentials: false im getting
✖ fatal fatal: could not read Username for 'https://github.com': No such device or address
Otherwise, getting the same issue as OP.
Any idea why that happens? @phips28

@cthompson-avb
Copy link

I found this action which can push to protected branches by using a personal access token: https://github.com/CasperWA/push-protected

@tranlehaiquan
Copy link

For support "The protection rule is set up on pull request." I think the action should support option to create pull request instead of direct commit.

@chottuthejimmy
Copy link

chottuthejimmy commented Sep 26, 2024

we fixed by just throwing it all out of the window and building from first principles thinking.

name: Publish to NPM
jobs:
  bump_version:
    name: 'Bump Version'
    if: "!contains(github.event.head_commit.message, '[skip ci]')"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          persist-credentials: false
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "20"
      - name: Configure Git user
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"
      - name: 'Bump version'
        run: npm version patch -m "Bump version to %s [skip ci]"
      
      - name: Push changes to main 
        run: |
          git push https://${{ secrets.GH_TOKEN }}@github.com/testdriverai/testdriverai.git HEAD:main --force

Here's the link to the workflow

So whenever you need to update a major or a minor version you could just manually do it (I am assuming you will be doing them on a monthly/quarterly basis, and if you are someone who's updating it more frequently than this, kudos mate!
you are doing something half of the companies hope to do, to ship faster) and in the commit include the string [skip ci] and the workflow will be skipped for that one time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants