All Projects → benjefferies → branch-protection-bot

benjefferies / branch-protection-bot

Licence: MIT license
A bot tool to disable and re-enable "Include administrators" option in branch protection

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to branch-protection-bot

changed-files
Github action to retrieve all (added, copied, modified, deleted, renamed, type changed, unmerged, unknown) files and directories.
Stars: ✭ 733 (+1185.96%)
Mutual labels:  ci, actions, github-actions
action-junit-report
Reports junit test results as GitHub Pull Request Check
Stars: ✭ 103 (+80.7%)
Mutual labels:  ci, actions, github-actions
xray-action
... a GitHub action to import test results into "Xray" - A complete Test Management tool for Jira.
Stars: ✭ 16 (-71.93%)
Mutual labels:  ci, actions, github-actions
overview
Automate your workflows with GitHub actions for MATLAB.
Stars: ✭ 40 (-29.82%)
Mutual labels:  ci, actions, github-actions
github-act-runner
act as self-hosted runner
Stars: ✭ 68 (+19.3%)
Mutual labels:  ci, actions, github-actions
qodana-action
⚙️ Scan your Java, Kotlin, PHP, Python, JavaScript, TypeScript projects at GitHub with Qodana
Stars: ✭ 112 (+96.49%)
Mutual labels:  ci, actions, github-actions
release-helper
🤖 A GitHub Action that help you publish release.
Stars: ✭ 27 (-52.63%)
Mutual labels:  ci, actions, github-actions
Android-CICD
This repo demonstrates how to work on CI/CD for Mobile Apps 📱 using Github Actions 💊 + Firebase Distribution 🎉
Stars: ✭ 37 (-35.09%)
Mutual labels:  ci, actions, github-actions
branch-names
Github action to retrieve branch or tag names with support for all events.
Stars: ✭ 99 (+73.68%)
Mutual labels:  actions, branch, github-actions
github-action-scp
⬆️ Copy a folder to a remote server using SSH
Stars: ✭ 123 (+115.79%)
Mutual labels:  actions, github-actions
rubocop-linter-action
Rubocop Linter Action: A GitHub Action to run Rubocop against your code!
Stars: ✭ 86 (+50.88%)
Mutual labels:  actions, github-actions
setup-just
🤖 GitHub Action to install the just command runner
Stars: ✭ 21 (-63.16%)
Mutual labels:  actions, github-actions
actions
A Collection of GitHub Actions
Stars: ✭ 91 (+59.65%)
Mutual labels:  ci, github-actions
generate-og-image
Generate open graph images with Github Action from Markdown files
Stars: ✭ 32 (-43.86%)
Mutual labels:  actions, github-actions
mylib
Шаблон кросплатформенного CMake-проекта для языка C++ 🇬🇧 Modern CMake crossplatform project template for C++
Stars: ✭ 49 (-14.04%)
Mutual labels:  ci, github-actions
pin-github-action
Pin your GitHub actions to a specific hash
Stars: ✭ 38 (-33.33%)
Mutual labels:  actions, github-actions
actions
Collection of repetitive GitHub Actions
Stars: ✭ 12 (-78.95%)
Mutual labels:  actions, github-actions
code-owner-self-merge
A GitHub Action for letting CODEOWNERS merge PRs via green PR reviews
Stars: ✭ 43 (-24.56%)
Mutual labels:  actions, github-actions
nextjs-github-pages
🚀 Deploy a Next.js app to Github Pages via Github Actions.
Stars: ✭ 89 (+56.14%)
Mutual labels:  actions, github-actions
ghaction-chocolatey
GitHub Action for Chocolatey, the package manager for Windows
Stars: ✭ 58 (+1.75%)
Mutual labels:  actions, github-actions

Branch Protection Bot

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.

Tutorial

How it works

  1. Your automated pipeline is kicked off
  2. Before you push to github you run this tool to disable Include administrators
  3. Push to the repository
  4. After you push to github you run this tool to enable Include administrators

Example usage

Docker

docker run -e ACCESS_TOKEN=abc123 -e BRANCH=master -e REPO=branch-protection-bot -e OWNER=benjefferies benjjefferies/branch-protection-bot

Github Actions

- name: Temporarily disable "include administrators" branch protection
  uses: benjefferies/branch-protection-bot@master
  if: always()
  with:
    access_token: ${{ secrets.ACCESS_TOKEN }}
    branch: ${{ github.event.repository.default_branch }}
    
- 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
    branch: ${{ github.event.repository.default_branch }}

Inputs

access_token

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

owner

For example benjefferies for https://github.com/benjefferies/branch-protection-bot. If not set with repo GITHUB_REPOSITORY variable will be used

repo

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

Branch name. Default "master"

retries

Number of times to retry before exiting. Default 5.

enforce_admins

If you want to pin the state of Include administrators for a step in the workflow.

Outputs

initial_status

Output the current branch protection status of Include administrators prior to any change. You can retrieve it from any next step in your job using: ${{ steps.disable_include_admins.outputs.initial_status }}. This would help you to restore the initial setting this way:

steps:
    - name: "Temporarily disable 'include administrators' default branch protection"
    id: disable_include_admins
    uses: benjefferies/branch-protection-bot@master
    if: always()
    with:
        access_token: ${{ secrets.ACCESS_TOKEN }}
        branch: ${{ github.event.repository.default_branch }}
        enforce_admins: false
    
    - ...

    - name: "Restore 'include administrators' default 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 }}
        branch: ${{ github.event.repository.default_branch }}
        enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}

Github repository settings

The Bot account must be an administrator.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].