From b56f558255f3535f2d6ff94f0a9fa315e84fb997 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 20:11:53 +0000 Subject: [PATCH] fix(required-contexts): refuse workflow_run branch filters on a status publisher GitHub applies workflow_run branches/branches-ignore to the triggering run's branch, so a filtered CI/gate publisher never posts the status on a PR head and the PR waits for ever. The checker now refuses any branch filter on the publisher except branches: ["**"], with negative fixtures for both keys. Ported from hyperpolymath/rsr-template-repo#481; raised by CodeRabbit on hyperpolymath/mathesis#106. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDg8YzLVHtwwDfcY3J9 --- CHANGELOG.adoc | 6 ++++++ scripts/check-required-contexts.sh | 12 ++++++++++++ tests/workflows/squabble_gate_test.sh | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 6c34f17..4303884 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -513,6 +513,12 @@ https://semver.org/spec/v2.0.0.html[Semantic Versioning]. ==== Fixed +* **A `CI/gate` publisher may not filter `workflow_run` by branch.** + GitHub applies `branches` and `branches-ignore` to the triggering run's + branch, so a filtered publisher never posts the status on a PR head and the + PR waits for ever. `check-required-contexts.sh` now refuses any such filter + except `branches: ["**"]`; negative fixtures cover both keys. Ported from + rsr-template-repo#481. * Julia mints start with Lock Sync green. The julia-library overlay shipped its own `actions.lock`, which replaced the spine's at mint, so every spine workflow lost its records. The records now ship beside the diff --git a/scripts/check-required-contexts.sh b/scripts/check-required-contexts.sh index 41ffe16..8ed6938 100644 --- a/scripts/check-required-contexts.sh +++ b/scripts/check-required-contexts.sh @@ -189,6 +189,18 @@ function verifyStatusPublisher(ctx, relWf, fullWf) { if (!Array.isArray(types) || !types.includes("completed")) { fail(`status context '${ctx}' publisher '${relWf}' workflow_run types do not include 'completed' (types: ${JSON.stringify(types ?? null)})`); } + // GitHub applies workflow_run branch filters to the TRIGGERING run's branch, so a filter + // keeps the publisher from running for PR-branch workflows and strands the PR head + // without the status (#219 defect class). Only an all-branches filter is harmless. + if (wr && typeof wr === "object" && Object.hasOwn(wr, "branches")) { + const b = wr.branches; + if (!(Array.isArray(b) && b.length === 1 && b[0] === "**")) { + fail(`status context '${ctx}' publisher '${relWf}' filters workflow_run by branches (${JSON.stringify(b ?? null)}) — strands PR heads whose workflows run on other branches`); + } + } + if (wr && typeof wr === "object" && Object.hasOwn(wr, "branches-ignore")) { + fail(`status context '${ctx}' publisher '${relWf}' filters workflow_run by branches-ignore (${JSON.stringify(wr["branches-ignore"] ?? null)}) — strands PR heads on the ignored branches`); + } } const jobs = doc?.jobs && typeof doc.jobs === "object" ? doc.jobs : {}; const callers = []; diff --git a/tests/workflows/squabble_gate_test.sh b/tests/workflows/squabble_gate_test.sh index 59b2827..53a4843 100644 --- a/tests/workflows/squabble_gate_test.sh +++ b/tests/workflows/squabble_gate_test.sh @@ -392,6 +392,13 @@ fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n pull_request:' assert_rc 1 'status mapping: no workflow_run trigger fails' check_status fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**"]\n types: [in_progress]' assert_rc 1 'status mapping: workflow_run without the completed type fails' check_status +# A workflow_run branch filter applies to the triggering run's branch: it strands PR heads. +fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**", "!CI gate"]\n types: [completed]\n branches: [main]' +assert_rc 1 'status mapping: a completed-only publisher filtered to main fails' check_status +fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**", "!CI gate"]\n types: [completed]\n branches-ignore: ["dependabot/**"]' +assert_rc 1 'status mapping: a publisher with workflow_run branches-ignore fails' check_status +fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**", "!CI gate"]\n types: [completed]\n branches: ["**"]' +assert_rc 0 'status mapping: an all-branches workflow_run filter passes' check_status fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/other' assert_rc 1 'status mapping: a wrong with.context fails' check_status fresh_status "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate ' @@ -420,6 +427,8 @@ status_says 'wrong context' 'wrong with.context' "$SUITE_REUSABLE@$SUITE_PIN" 'C status_says 'foreign reusable' 'has no job whose uses:' "hyperpolymath/other-repo/.github/workflows/ci-gate.yml@$SUITE_PIN" status_says 'no workflow_run' 'does not trigger on workflow_run' "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n pull_request:' status_says 'no completed type' "do not include 'completed'" "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**"]\n types: [in_progress]' +status_says 'branch filter' 'filters workflow_run by branches' "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**"]\n types: [completed]\n branches: [main]' +status_says 'branches-ignore filter' 'filters workflow_run by branches-ignore' "$SUITE_REUSABLE@$SUITE_PIN" 'CI/gate' $'on:\n workflow_run:\n workflows: ["**"]\n types: [completed]\n branches-ignore: [main]' fresh_status rm "$status_tree/.github/workflows/ci-gate.yml" check_status >"$WORK/status-msg" 2>&1 || true