Protected branch with PR requirement prevents release
See original GitHub issueHello 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:
- Created 4 years ago
- Reactions:29
- Comments:41 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anybody using GitHub Actions, you need to set the
token
option of theactions/checkout
action so that GitHub would authorize local Git with the necessary push permissions.Your
CI_GITHUB_TOKEN
secret should equal your GitHub Personal Access Token with therepo
permissions scope. That scope would authorize pushes to protected branches, given you don’t have “Include administrators” set in the protected branch’s settings.@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 forsemantic-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
andCHANGELOG.md
file). In order to do this you need to provide aGITHUB_TOKEN
with write permissions.You will still get the issue you described before.
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: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.
Hope this is useful to you too and helps u with
semantic-release
integration on your protected branch.