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:
- it is the merge commit (merge, squash or rebase) of a pull request merged into
main: a direct push is refused; - 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;
- 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.
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.shIf 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
| 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.
| Code | Meaning |
|---|---|
0 |
allowed |
1 |
refused |
2 |
usage error |
3 |
refused, GitHub API unavailable (fail closed) |
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.
Pure Python 3 standard library, one file. Tests run against a fake GitHub API:
pip install pytest && pytestMIT