phips28 / gh-action-bump-version

GitHub Action for automated npm version bump.
MIT License
337 stars 252 forks source link

Version bump failed on protected branch #156

Open gyi123 opened 2 years ago

gyi123 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 1 year ago

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 commented 8 months ago

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 commented 6 months ago

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

tranlehaiquan commented 4 months ago

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 commented 2 months ago

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.