question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Protected branch with PR requirement prevents release

See original GitHub issue

Hello we integrated semantic release in our tool chain, but as we tried to release to master the first time, the branch protection of master prevented the release.

The error message from travis:

[9:32:50 AM] [semantic-release] › ✖  An error occurred while running semantic-release: { Error: Command failed: git push --tags https://[secure]@github.com/**/service.git HEAD:master
remote: error: GH006: Protected branch update failed for refs/heads/master.        
remote: error: At least 1 approving review is required by reviewers with write access.        
To https://github.com/**/service.git
 ! [remote rejected] HEAD -> master (protected branch hook declined)
error: failed to push some refs to 'https://[secure]@github.com/**/service.git'

How could I keep the PR rule and enable semantic release?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:29
  • Comments:41 (8 by maintainers)

github_iconTop GitHub Comments

61reactions
kettanaitocommented, May 10, 2022

For anybody using GitHub Actions, you need to set the token option of the actions/checkout action so that GitHub would authorize local Git with the necessary push permissions.

- name: Checkout
  uses: actions/checkout@v3
  with:
    fetch-depth: 0
    token: ${{ secrets.CI_GITHUB_TOKEN }}

Your CI_GITHUB_TOKEN secret should equal your GitHub Personal Access Token with the repo permissions scope. That scope would authorize pushes to protected branches, given you don’t have “Include administrators” set in the protected branch’s settings.

32reactions
cgadamcommented, Apr 19, 2019

@Ninerian, the situation we have which I think it’s similar to yours is this one:

  • We have protected branch rules enabled (like having 2 reviewers per each commit and do not commit directly to master if it’s not via a PR). The protected branch is, at the same time, the release branch for semantic-release. (i.e: master)

  • We want semantic-release to update files when the new version is calculated. (In our case we do update package.json and CHANGELOG.md file). In order to do this you need to provide a GITHUB_TOKEN with write permissions.

You will still get the issue you described before.

[9:32:50 AM] [semantic-release] › ✖  An error occurred while running semantic-release: { Error: Command failed: git push --tags https://[secure]@github.com/**/service.git HEAD:master
remote: error: GH006: Protected branch update failed for refs/heads/master.        
remote: error: At least 1 approving review is required by reviewers with write access.        
To https://github.com/**/service.git
 ! [remote rejected] HEAD -> master (protected branch hook declined)
error: failed to push some refs to 'https://[secure]@github.com/**/service.git'

In the perfect world, we would be able to tell Github, please bypass this type of checking for specific non-admin users (like a bot) but that’s something Github doesn’t support so far. I have confirmed it with support:

image

The way we workaround this was by assigning the bot as Owner. By doing this it do has the power to bypass the protected branch rules (because it’s considered an admin).

The good thing is that the GITHUB_TOKEN we generated for doing this kind of commit doesn’t have any crazy permission like deleting repo or such so we should be OK.

image

Hope this is useful to you too and helps u with semantic-release integration on your protected branch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protected branches - GitLab Documentation
Protected branches can only be deleted by using GitLab either from the UI or API. This prevents accidentally deleting a branch through local...
Read more >
How to push to protected main branches in a GitHub Action?
Open your branch protection rules and add my-org-bot to the rule below: ... If you are using GITHUB_TOKEN then GitHub Actions prevents the ......
Read more >
New Branch Protections: Last Pusher and Locked Branch
Meaning, the most recent user to push their changes will need a pull request approval regardless of the Require approvals branch protection. Or ......
Read more >
Working with Protected Branches
A common branch protection rule is for pull requests (PRs) to be reviewed by at least one other person before they get merged....
Read more >
How to Set Up GitHub Branch Protection Rules - Nira
This rule ensures that collaborators cannot merge their pull requests or push directly to the branch. Instead, users first have to commit to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found