Skip to content

Enforce branch protection via .github/branch-protection.main.json (Closes #95)#167

Merged
mvillmow merged 1 commit into
mainfrom
95-auto-impl
Jun 29, 2026
Merged

Enforce branch protection via .github/branch-protection.main.json (Closes #95)#167
mvillmow merged 1 commit into
mainfrom
95-auto-impl

Conversation

@mvillmow

@mvillmow mvillmow commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Implement automated, auditable branch protection enforcement for the main
branch by introducing a committed JSON source of truth, apply and verify
scripts, offline regression tests, and a post-merge workflow that
auto-applies the ruleset on changes.

Implementation

Files Created:

  • .github/branch-protection.main.json — committed source of truth with required_approving_review_count=1 and require_code_owner_reviews=true
  • scripts/apply-branch-protection.sh — PUT ruleset to GitHub API
  • scripts/verify-branch-protection.sh — GET and diff against JSON
  • scripts/verify-context-names.sh — validate all contexts map to real workflow jobs
  • tests/branch-protection.test.sh — offline shim-based test suite with 4 test cases
  • .github/workflows/apply-branch-protection.yml — post-merge auto-apply workflow

Files Modified:

  • pixi.toml — add jq dependency and test-branch-protection task
  • justfile — wire 3 new recipes (apply-branch-protection, verify-branch-protection, test-branch-protection) and update check target
  • .github/workflows/_required.yml — add branch-protection-test job
  • docs/branch-protection.md — update with correct job names and enforcement procedure
  • CLAUDE.md — remove "Branch protection partial" defect entry

Verification

✅ All 15 required-status-check contexts map to real workflow job names
✅ JSON validates with jq
✅ Offline test suite passes (clean, drift, missing-token, malformed-JSON cases)
✅ All scripts are executable

Post-Merge Manual Steps

One-time admin setup required:

  1. Create repository secret BRANCH_PROTECTION_PAT with fine-grained PAT scoped to Administration: write on ProjectProteus
  2. When pushed, .github/workflows/apply-branch-protection.yml will fire automatically and apply the ruleset

References

Closes #95

Partially closes #102 (API half only; require_code_owner_reviews=true enforced here; CODEOWNERS coverage audit remains open)

Refs #81 (audit remediation)

Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com

@mvillmow mvillmow force-pushed the 95-auto-impl branch 2 times, most recently from a5a9a87 to 6e12ac8 Compare June 28, 2026 17:12
@mvillmow mvillmow enabled auto-merge (squash) June 28, 2026 18:46
Closes #95

Implement automated, auditable branch protection enforcement for the `main`
branch by introducing a committed JSON source of truth, apply and verify
scripts, offline regression tests, and a post-merge workflow that
auto-applies the ruleset on changes.

Changes:
- Add .github/branch-protection.main.json with required_approving_review_count=1
  and require_code_owner_reviews=true
- Add scripts/apply-branch-protection.sh (PUT ruleset to GitHub API)
- Add scripts/verify-branch-protection.sh (GET and diff against JSON)
- Add scripts/verify-context-names.sh (validate all contexts map to real jobs)
- Add tests/branch-protection.test.sh (offline shim-based test suite)
- Add .github/workflows/apply-branch-protection.yml (post-merge auto-apply)
- Wire branch-protection recipes into justfile
- Add branch-protection-test job to _required.yml CI
- Update pixi.toml to include jq dependency and test-branch-protection task
- Update docs/branch-protection.md with enforcement procedure
- Update CLAUDE.md to remove "Branch protection partial" defect entry
- Update docs/audit-2026-04-28/remediation-plan.md (if exists)

Verification:
- All 15 required-status-check contexts map to real workflow job names
- JSON validates with jq
- Offline test suite passes (clean, drift, missing-token, malformed-JSON cases)
- Scripts pass shellcheck

References: Closes #95. Partially closes #102 (API half only; CODEOWNERS
coverage audit remains open). Refs #81 (audit remediation).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Signed-off-by: mvillmow <4211002+mvillmow@users.noreply.github.com>
@mvillmow mvillmow merged commit 2ea58e7 into main Jun 29, 2026
18 checks passed
@mvillmow mvillmow deleted the 95-auto-impl branch June 29, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MAJOR] §15: CODEOWNERS not enforced in branch protection [MAJOR] §6: PRs require zero code reviews despite CODEOWNERS configuration

1 participant