Giter Club home page Giter Club logo

stop-merging's Introduction

Stop Merging

This action performs a status check to prevent merging pull requests into the main branch when it is in a broken state.

Problem statement

When multiple developers are simultaneously working on the same repository, it can occur that developer A breaks the main branch, but developers B and C continue to merge their PRs into the same branch. This can result in developers B and C being unaware if they have introduced additional bugs, since the main branch is already broken by developer A.

To prevent the above scenario, it may be useful to implement a code freeze on the main branch, allowing developer A to resolve the issue without encountering additional merge conflicts or bugs introduced by developers B and C.

This GitHub action represents such code freeze by using a status check that blocks all pull request merges unless they comply with a specific prefix (i.e. "fix").

What means "broken"?

When the latest commit on your main branch has a failed status check, it is considered to be in a broken state.

How to install?

  1. Install this action from the GitHub Marketplace
  2. Add branch protection rule to your GitHub repository
  3. Require status checks to pass before merging

1. Install this action

It's as simple as creating this file:

.github/workflows/stop-merging.yml

name: 'Check Mergeability'

on:
  pull_request:
    # With "edited" it runs on PR title updates
    types: [opened, edited, synchronize, reopened]

jobs:
  check-main:
    runs-on: ubuntu-latest
    steps:
      - uses: bennycode/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GIT_BRANCH: 'main'
          BYPASS_PREFIX: 'fix'

2. Add branch protection

Equip your base branch with branch protection rules:

3. Require status checks

Enable "Require status checks to pass before merging" and make sure to have at least two status checks:

  1. A test suite to determine if your branch is broken (i.e. "test")
  2. The "Stop Merging" check (i.e. "check-main")

It is also recommended to enable "Require branches to be up to date before merging". This will handle the following scenario:

  • Main branch is okay
  • Coder A creates a PR that passes the "Stop Merging" check
  • Coder B breaks the main branch
  • Coder A's merge would still be possible if there was no requirement to keep the branch up to date

Screenshot:

How to use?

When configured as a status check, this action will make your open pull requests fail when your configured main branch is broken. Only pull requests matching a specific title (for example "fix: Main branch") will be allowed to be merged in order to recover the health of your main branch. Once your main branch is green again, you can rerun the failing Stop Merging status checks to also become green again or update your branch which will automatically trigger this action.

Configuration

The following parameters can be configured:

  • BYPASS_PREFIX: Prefix for commit messages that can bypass the status check (defaults to fix)
  • GIT_BRANCH: Git branch to check for status (defaults to main)
  • GITHUB_TOKEN: Token to be used by the Stop Merging action to authenticate with your repository
  • INTERVAL_RETRIES: How many times should this action perform a check for a suite to see if it's finished, within a 1-minute interval? (defaults to Infinity)

Example:

steps:
  - uses: bennycode/stop-merging
    with:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      GIT_BRANCH: 'main'
      BYPASS_PREFIX: 'important'

stop-merging's People

Contributors

dependabot[bot] avatar bennycode avatar

Stargazers

David Rapson avatar  avatar

Watchers

 avatar  avatar

stop-merging's Issues

There are no completed check suites

The action can fail if a check suite is still pending but not finished (neither failed nor successful). The error will be the following:

There are no completed (still pending or not created at all) check suites on branch "main".

The solution here would be to implement an interval which retries until a certain timeout.

Handle case where all check suites can be queued

This scenario can happen:

Error: There are no completed check suites on branch "main". Check suites are either pending or didn't run at all. You can read more about check suites here: https://docs.github.com/en/rest/guides/getting-started-with-the-checks-api#about-check-suites
Found "7" check suite(s) (queued, queued, queued, queued, queued, queued, queued) for repository "dcs-calculate" owned by "southpolecarbon".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.