Skip to content

About

Deploy only commits merged through an approved, green pull request: branch protection for the GitHub Free plan

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Approved merge guard

Tests Dependencies License MIT

Review-before-deploy for private repositories on the GitHub Free plan.

On the Free plan, private repositories get no branch protection and no required reviews: anyone with write access can push to main or merge an unreviewed pull request. This action moves the lock to where it matters, the deployment. Put it as the first step of your deploy job and the commit is deployed only if:

  1. it is the merge commit (merge, squash or rebase) of a pull request merged into main: a direct push is refused;
  2. the pull request's last commit was approved by someone other than its author, and no reviewer's latest review requests changes. Approvals from bot accounts never count, and an approval given before a new commit is pushed is stale;
  3. your required check (tests, lint…) is green on that last commit.

It fails closed: if the GitHub API cannot be reached, nothing is deployed.

For real emergencies, a label (emergency by default) set by a member of a list you choose waives the approval (never the check) and leaves a trace as a comment on the pull request.

Usage

name: Deploy

on:
  push:
    branches: [main]

permissions:
  contents: read
  pull-requests: read
  checks: read
  issues: write        # only for the emergency comment

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: raphael-bynome/approved-merge-guard@v1
        with:
          check: tests                  # job name of your PR workflow
          emergency-team: alice,bob     # optional
          bots: my-deploy-bot           # optional
      - uses: actions/checkout@v4
      - run: ./deploy.sh

If the guard refuses, the job stops before anything is touched, with the reason in the logs and in the run summary:

pull request #42 by alice, last commit 3f2a9c1e
Error: Deployment refused: approval by bob is older than the last commit 3f2a9c1e of #42

Inputs

Input Default Meaning
check (required) name of the check run that must be green on the PR's last commit
token github.token token able to read PRs, reviews and checks
sha github.sha commit to verify
base main branch the PR must have been merged into
emergency-label emergency label that waives the approval; empty to disable
emergency-team (empty) logins allowed to set the emergency label
bots (empty) logins whose approvals never count
comment true comment on the PR when the emergency label is used

Output: reason, why the commit was allowed.

Exit codes

Code Meaning
0 allowed
1 refused
2 usage error
3 refused, GitHub API unavailable (fail closed)

Why not just trust the merge button?

Because on the Free plan the merge button does not check anything. This guard has run in front of about twenty production stacks (self-hosted runners, Docker Compose deployments with health checks and automatic rollback) since October 2026: an unreviewed push simply never reaches production.

Development

Pure Python 3 standard library, one file. Tests run against a fake GitHub API:

pip install pytest && pytest

License

MIT

About

Deploy only commits merged through an approved, green pull request: branch protection for the GitHub Free plan

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages