A bot tool to temporarily disable and re-enable "Include administrators" option in branch protection
Github doesn't have a way to give a Bot access to override the branch protection, specifically if you include administrators.
The only possible solution is to disable the include administrators
option. This increases risk of accidental pushes to master from administrators (I've done it a few times).
This tool doesn't completely solve the problem of accidents happening but reduces the chances by closing the window.
The intended use of this tool is to is in a CI/CD pipeline where you require temporary access to allow a administrator Bot push to a branch.
- Your automated pipeline is kicked off
- Before you push to github you run this tool to disable
Include administrators
- Push to the repository
- After you push to github you run this tool to enable
Include administrators
docker run -e ACCESS_TOKEN=abc123 -e BRANCH=master -e REPO=branch-protection-bot -e OWNER=benjefferies benjjefferies/branch-protection-bot
- name: Temporarily disable "include administrators" branch protection
uses: benjefferies/branch-protection-bot@master
if: always()
with:
access-token: ${{ secrets.ACCESS_TOKEN }}
- name: Deploy
run: |
mvn release:prepare -B
mvn release:perform -B
- name: Enable "include administrators" branch protection
uses: benjefferies/branch-protection-bot@master
if: always() # Force to always run this step to ensure "include administrators" is always turned back on
with:
access-token: ${{ secrets.ACCESS_TOKEN }}
owner: benjefferies
repo: branch-protection-bot
Required Github access token. https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line. Requires full repository access scope
For example benjefferies for https://github.com/benjefferies/branch-protection-bot. If not set with repo GITHUB_REPOSITORY variable will be used
For example branch-protection-bot for https://github.com/benjefferies/branch-protection-bot. If not set with repo GITHUB_REPOSITORY variable will be used
Branch name. Default "master"
Number of times to retry before exiting. Default 5
.
If you want to pin the state of "Include administrators" for a step in the workflow.
The Bot account must be an administrator.