ci: enforce merge source for PRs targeting main#57
Conversation
Only dev and release automation branches (chore-bump-v*, chore/release-*, chore/sync-main-*) can merge into main. Other branches will fail CI. Make this check required in branch protection to fully enforce. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds CI enforcement to restrict which source branches are allowed to open PRs targeting main, so branch protection can require this check before merge.
Changes:
- Introduces a
check-merge-sourcejob gated to PRs where the base branch ismain. - Fails the workflow if the PR source branch name is not in an allowlist (
dev,chore-bump-v*,chore/release-*,chore/sync-main-*).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [[ "$HEAD" == "dev" || "$HEAD" == chore-bump-v* || "$HEAD" == chore/release-* || "$HEAD" == chore/sync-main-* ]]; then | ||
| echo "OK: '$HEAD' is allowed to merge into main." |
There was a problem hiding this comment.
This branch-name-only check can be bypassed by PRs from forks: a fork can open a PR with head_ref set to dev (or another allowed pattern) and this job will pass. If the intent is to restrict merges to branches within this repository, also validate github.event.pull_request.head.repo.full_name == github.repository (or !github.event.pull_request.head.repo.fork) and fail otherwise, or incorporate the owner in the allowlist check.
| if [[ "$HEAD" == "dev" || "$HEAD" == chore-bump-v* || "$HEAD" == chore/release-* || "$HEAD" == chore/sync-main-* ]]; then | |
| echo "OK: '$HEAD' is allowed to merge into main." | |
| HEAD_REPO="${{ github.event.pull_request.head.repo.full_name }}" | |
| REPO="${{ github.repository }}" | |
| if [[ "$HEAD_REPO" != "$REPO" ]]; then | |
| echo "::error::Branch '$HEAD' is from fork repository '$HEAD_REPO' and is not allowed to merge into main. Only branches from '$REPO' may target main." | |
| exit 1 | |
| fi | |
| if [[ "$HEAD" == "dev" || "$HEAD" == chore-bump-v* || "$HEAD" == chore/release-* || "$HEAD" == chore/sync-main-* ]]; then | |
| echo "OK: '$HEAD' from '$HEAD_REPO' is allowed to merge into main." |
Summary
check-merge-sourceCI job that fails PRs tomainfrom unauthorized branchesdev,chore-bump-v*,chore/release-*, andchore/sync-main-*branches are allowedAfter merging, make
check-merge-sourcea required status check in branch protection formainto fully enforce.Test plan
check-merge-sourcedevto main still pass🤖 Generated with Claude Code