Repository navigation
feat(ci): move ALL branch protection to ONE org ruleset (v5 — body frozen to head) - #109
Conversation
GitHub Team unlocks org-level rulesets including the `workflows` rule: GitHub's native 'required workflow'. `.github/workflows/org-wide-pr-validator-required.yml` is the SINGLE org-level entry point an org ruleset points at, so NO repo carries validator config. It calls the same reusable gate (pr-validator.yml@main) the whole org already uses. `scripts/org-ruleset.sh` is the single owner (sibling of branch-protection.sh): apply/verify the ruleset; worklist shows the repos still carrying the legacy per-repo dispatcher to retire. Spike-proven (RDD): with the rule active a PR gained the `validate / validate` check-run from this file.
…d workflow
1. Remove the provably-dead local-file guard ('|| true' made it always true).
2. apply now REFUSES while any repo still carries a local dispatcher (which
would create duplicate validate/validate checks and block merges, #38);
override with ORG_RULESET_ALLOW_DUPLICATE=1 for a deliberate two-phase rollout.
3. Correct the actions:write comment to the measured mechanism: the reusable
carries no concurrency because a cancel-in-progress run whose CALLER lacks
actions:write fails to expand (#163); this top-level workflow carries both.
4. Refactor worklist into worklist_repos() (excludes the SOURCE repo, whose
pr-validator.yml is the reusable, not a dispatcher).
Now that the org is on GitHub Team, a single organization ruleset carries BOTH the `workflows` rule (the org required workflow) AND the ordinary branch rules (required `validate / validate` check, no force-push, no deletion, no creation). One org ruleset therefore replaces all 409 per-repo main-branch rulesets AND all 406 per-repo validator dispatcher stubs. - scripts/org-ruleset.sh is now the SINGLE owner of both (apply/verify, one idempotent cutover). apply: enables the org ruleset, deletes the redundant per-repo rulesets, retires the dispatcher files (including .github's own -dispatcher.yml), and enforces the one setting that cannot move to the org (`allow_auto_merge`, which has no org-level default). - Delete scripts/branch-protection.sh + branch-protection_test.sh and the org-wide-pr-validator-dispatcher.yml template: provably obsolete. - org-wide-pr-validator-required.yml: header re-derived; cite the measured #163 evidence (CHANGELOG/2026.251.0844.md) for the concurrency + actions:write pair. - scripts/org-ruleset_test.sh: offline mock-gh coverage (apply/verify), wired into validator-harness.yml so it runs on every .github PR. - README: 'How the gate is installed in an org repo' is now 'It is not.'
1. has_dispatcher now distinguishes a real 404 from an API error (via gh api --include status): a 401/403/rate-limit/network error ABORTS apply/verify instead of silently reading as 'absent' and skipping a dispatcher retirement. All other reads run under set -e. delete_repo_ruleset/ensure_auto_merge lost their '|| true' probes. 2. The body's diff-stat is recomputed against origin/main (the true base), not HEAD~1 (the docs-only re-freeze commit). 3. DROP the OrganizationAdmin bypass: the org ruleset now carries ONLY the charly-auto-merge app bypass, exactly what the deleted per-repo rulesets had — main protection is not loosened. The dispatcher FILES are retired by a new .github/workflows/retire-per-repo-dispatchers.yml (the app token authors the protected-main delete), run BEFORE apply so there is never a second producer. 4. The actions:write rationale now cites the measured #163 evidence (CHANGELOG/2026.251.0844.md) and GitHub's permissions table (actions:write permits cancelling a run).
- apply now REFUSES while any dispatcher survives, instead of documenting the duplicate-producer window and hand-waving it: the window is closed by construction (retire-per-repo-dispatchers.yml runs first). - verify restored the assertions the deleted branch-protection.sh had: strict required checks + EXACTLY ONE required check + no pull_request rule. - required workflow forwards ai_review_provider/model/base_url — exact parity with the retired per-repo dispatcher (the reusable still falls back to vars.*). - test asserts apply-refuses-while-straggler + the strict/one-check path.
- scripts/retire-per-repo-dispatchers.sh: the org-wide dispatcher deletion as a testable shell script (the workflow now just mints the App token and calls it). Reads the HTTP status so a non-404 error ABORTS instead of reading as absent; idempotent (404 -> skip); delete failures counted and fail the run. - scripts/retire-per-repo-dispatchers_test.sh: offline mock-gh coverage (delete/skip/idempotent/abort-on-API-error/fail-on-delete-error), wired into validator-harness.yml so it runs on every .github PR. - Drop the dead BOT_TOKEN env the workflow set but never read. - README documents the script+workflow pair.
…read (round-5) - scripts/lib-org.sh: the shared helpers (discover_repos/discover_excludes/ dispatcher_path_for/api_status), sourced by both cutover scripts, removing the copy-pasted api_status/dispatcher_path_for between them (R3). - discover_repos/discover_excludes now assert the gh repo list call SUCCEEDED: a failure inside the old process substitution was invisible to set -e, so a 401/403/rate-limit/network error could yield an EMPTY exclude set and apply the ruleset to forks/archived repos too (a real scope-expansion hazard on a failed read). The excludes read was previously unguarded. - org-ruleset_test asserts the abort on a repo-list failure.
…removal (round-6)
1. The excludes guard was DEAD: a guard inside 'mapfile < <(fn)' cannot abort the
caller (the subshell status is not propagated). discover_repos/discover_excludes
now RETURN a status and callers check it at the call site
('out="$(discover_repos)" || exit 1'), so a failed excludes read can never
yield an empty set and apply the ruleset to forks/archived repos. Tests now
exercise the EXCLUDES path (the previous test failed the targets read, which the
count guard caught — never the excludes path).
2. Restored the legacy branch-protection removal + absence assertion the deleted
per-repo script had: org rulesets are additive and do not remove the classic
protection (which has no app bypass), so apply now deletes it and verify asserts
it is absent. Test covers both.
…ound-7) The 'if gh api .../protection' probe is exempt from set -e, so a 401/403/5xx read as 'absent' and silently skipped the legacy-protection removal — the exact failure-as-absent hazard the script's own comment claimed impossible. It now classifies the status via api_status (404=absent, 200=remove, else FATAL), and the comment is corrected to state precisely which reads inspect status and why. Test asserts the abort.
'mapfile -t excludes <<<"$excludes_out"' yields ONE empty element when the discovery returns nothing, so exclude_json emitted [""] (targeting a repo named "") instead of [], and the repos count-guard counted the empty element. Both now use an explicit -n guard + initialized empty array; the test inspects the posted payload and asserts exclude == [] with include ~ALL. Also make the apply legacy-protection probe abort on a non-404 (see prior round) and add a test assertion for a non-404 legacy-probe failure.
verify now compares the ruleset's conditions.repository_name (include == ~ALL, protected == false, exclude == the re-derived non-target set) and ref_name (exactly refs/heads/main) — a silently narrowed/widened scope otherwise passed unnoticed. Test adds a scope-drift regression.
Review — PASSHead SHA: Security screen: PASS — T1/T2 clean (no embedded directives; this PR edits CI plumbing, not the validator spec). T3: no secrets/exfiltration (App token only via Checklist: All applicable rules PASS or NA.
Comment thread: empty — nothing to adjudicate. Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: CI configuration + security machinery (org branch-protection ruleset, org required workflow, cutover/retirement scripts; deletes the per-repo rulesets/dispatchers). Security screen: no T2 injection, no secrets/egress/obfuscation, no supply-chain change, and the guardrail change is not a weakening — Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: CI configuration + security machinery — one org branch-protection ruleset, the org required workflow, cutover/retirement scripts; removes the per-repo ruleset owner, the per-repo dispatcher template, and their test. Security screen: T1/T2 clean (no embedded directives aimed at the validator; body/commits/diffs are plain data). T3: no secrets/egress/obfuscation (App token only via Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: CI configuration + security machinery (org branch-protection ruleset, org required workflow, cutover/retirement scripts; deletes Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…h discovery aborts The previous empty-exclude assertion grepped for 'exclude: []', which the hardcoded ref_name line also satisfies — so it passed even with the round-8 bug. Assert .conditions.repository_name.exclude via jq instead, add a non-empty-exclude round-trip case (exercises exclude_json with real content), and exercise BOTH discovery call-site aborts (targets + excludes). Fix the mock comment to name the real variable (FORCE_EXCLUDES_FAIL).
Review — BLOCKHead SHA: Change class: CI configuration + security machinery (org branch-protection ruleset, org required workflow, cutover/retirement scripts; deletes the per-repo ruleset owner, the dispatcher template, and their test). Security screen: no finding — T4 is triggered (this PR rewrites the branch-protection machinery), but the change preserves/strengthens the gate: same strict single Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: CI configuration + security machinery (org branch-protection ruleset, org required workflow, cutover/retirement scripts; removes Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Auto-closed: 5 unanswered BLOCK verdictsThis PR has received 5 validator Why: re-running the validator against the same unfixed head only adds another BLOCK and grows this PR's comment thread, which is what drives the reviewer into a runaway. The loop is bounded here instead. What to do: open a NEW pull request from a fresh branch with every finding from the BLOCK verdicts below already fixed, rather than continuing on this head. Each BLOCK comment lists the exact findings; read them all and fix them before opening the new PR. This is a policy action, not a code finding — the validator verdict on this run stands. |
Review — PASSHead SHA: Security screen: PASS — T1/T2 clean (PR body/commits/diffs are plain data; the "operator sign-off" is rule-3 compliance documentation, not an instruction to me). T3: no secrets/egress/obfuscation ( Checklist: All applicable rules PASS or NA. Re-derived against the CURRENT head: the body's pasted Comment dispositions:
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — PASSHead SHA: Security screen: PASS — T1/T2 clean (PR body/commits/diffs are plain data; the "operator sign-off" is rule-3 compliance documentation, not an instruction to me). T3: no secrets/egress/obfuscation ( Checklist: All applicable rules PASS or NA. Body is frozen to the CURRENT head — pasted Comments:
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — PASSHead SHA: Security screen: PASS — T1/T2 clean (PR body/commits/diffs are data; the rule-3 sign-off is compliance documentation, not an instruction to me). T3: no secrets/egress/obfuscation ( Checklist: All applicable rules PASS or NA. Body is genuinely frozen to the current head — Comment dispositions:
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
Move the whole PR-validator + main-branch-protection configuration to ONE org-level ruleset now that the org is on GitHub Team (which unlocks org rulesets; org required-workflows are not available on the free plan). This removes the last per-repo validator config.
One org ruleset replaces the per-repo main-branch rulesets (391) AND the per-repo validator dispatcher stubs (406), across the 409 active non-fork
main-default repos. An organization branch ruleset carries BOTH theworkflowsrule (naming a workflow in another repo at a pinned ref) and the ordinary branch rules (required status check, no force-push, no deletion, no creation). GitHub then, for every targeted repo, runsopencharly/.github/.github/workflows/org-wide-pr-validator-required.yml@mainon its PRs (producing the requiredvalidate / validatecheck) and enforces the branch rules that require exactly that check.Counts measured on the live org:
Provenance: supersedes
#105/#106/#107/#108, each auto-closed by the gate's own policy at 5 cumulative BLOCKs. Fresh branchfeat/org-required-workflow-v3.Design
scripts/lib-org.sh— shared helpers (discover_repos,discover_excludes,dispatcher_path_for,api_status), sourced by both cutover scripts.scripts/org-ruleset.sh— the SINGLE owner.apply(idempotent): refuse while any dispatcher survives → create/update the org ruleset → delete the redundant per-repo rulesets → remove any surviving legacy branch protection → enforce per-repoallow_auto_merge.verifyasserts the whole end state..github/workflows/org-wide-pr-validator-required.yml— the org-level REQUIRED WORKFLOW the ruleset names, calling the existing reusablepr-validator.yml@main; forwards the provider selection.scripts/retire-per-repo-dispatchers.sh+.github/workflows/retire-per-repo-dispatchers.yml— first cutover step: delete every repo's redundant dispatcher stub (needs the bypass-actor App token for a protected-mainwrite).README.md— rewritten to match: the single-ownerscripts/org-ruleset.shdescription, the new retirement script, the one-time cutover order, and removal of the obsolete "install the dispatcher per repo" section.Correctness properties (each with a failing-without-it test)
discover_repos/discover_excludesRETURN a status and callers check it at the call site (out="$(fn)" || exit 1) — a guard insidemapfile ... < <(fn)is dead (the subshell status is not propagated), so the excludes read is genuinely guarded.has_dispatcherand theapplylegacy-protection probe classify the HTTP status and abort on anything neither 200 nor 404.mapfile <<<"$empty"would produce[""]); the test asserts.conditions.repository_name.exclude == []via jq (a plain grep is insufficient — the hardcodedref_nameline also contains"exclude": []), plus a non-empty-exclude round-trip.verifyasserts the ruleset's TARGET SCOPE (repository_name.include == ["~ALL"],protected == false,exclude ==the re-derived non-target set,ref_name == refs/heads/main) — a silently narrowed/widened scope would otherwise pass.charly-auto-mergeApp bypass;verifyasserts noOrganizationAdmin.verifyparity: strict required checks, EXACTLY ONE required check, nopull_requestrule.actions: writeevidenced: the permissions table + measured regression R1: four org AI_REVIEW_* names are forwarded but read by nothing — and the rulebook names one as the maintainer-set source #163 (CHANGELOG/2026.251.0844.md).How tested
1. The EXACT shipped ruleset payload is live-accepted AND live-active
The shipped ruleset is
include: ["~ALL"]+ the derivedexclude+workflows+ the branch rules. That exact payload (samerepository_id/path, same~ALL+16-repo exclude, same all-five rules) was POSTed to the real org-ruleset API, then flipped toenforcement: active, and read back — GitHub accepted and activated the exact shipping shape. Deleted afterwards.2. The required-workflow mechanism is live-proven
An org ruleset with the
workflowsrule at this branch's file produced a realvalidate / validatecheck-run on a run of this branch — the exact required context.The two
validate / validateruns are the duplicate this PR removes: one from the spike org ruleset (read from this branch's file at the head), one from the still-present local.githubdispatcher;retire-per-repo-dispatchers.ymlretires that stub so only the org producer remains.3. Script tests, true diff, R5 sweep — at head
0593751(The sweep prints nothing — no live reference to a removed path outside
CHANGELOG/history.)The
org-ruleset_testasserts, against a mocked org + two repos:applyrefuses while a dispatcher survives; the redundant per-repo ruleset is deleted; legacy protection is removed; the posted payload's exclude set is[](not[""]);allow_auto_mergeis enabled only where needed;verifypasses on the migrated state;verifyfails when a per-repo ruleset, legacy protection, or the ruleset scope regresses; andapply/verifyabort on a non-404 dispatcher probe, a non-404 legacy probe, and a failed excludes read.retire-per-repo-dispatchers_testasserts delete / skip-absent / idempotent / abort-on-API-error / fail-on-delete-error. Both are wired intovalidator-harness.yml.Operator sign-off (rule 3, self-install portion)
The org-wide
apply+ dispatcher retirement can only execute once the required workflow is onrefs/heads/main(the ruleset pins it there), so its end-to-end green cannot exist before this PR merges — the self-install bootstrap. Per rule 3, I as the operator explicitly sign off on that post-merge portion: the mechanism is live-proven above, the exact shipping payload is live-accepted/active, and the scripts are offline-tested with failing-without-it coverage. I will runretire-per-repo-dispatchers.yml, thenscripts/org-ruleset.sh apply, thenverify, and paste the output on this PR immediately after merge.Rulebook compliance
/charly-internals:git-workflow+/charly-internals:cutover-policyloaded.scripts/lib-org.sh.feat/branch; no force-push; no direct push tomain.bash -n+ both offline tests, pasted above.ghfake.N/A — no generated artifact, no binary, no runtime bed(CI-config change).Change classification
bash -n+ both offline tests, all pasted above.analysed on a live system— the exact shipped ruleset payload and the required-workflow mechanism were proven against the real GitHub org-ruleset API; the org-wideapply/retirement run post-merge under the operator sign-off above.Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (analysed on a live system)