Skip to content

Commit 312875d

Browse files
authored
ci: run CI on merge groups, and drop the Codecov upload token (#469)
* ci: report CI on merge groups A merge queue grades the merge commit it builds against the same required checks the pull request carries. A check whose workflow has no `merge_group` trigger never reports there, and that is a hang rather than a failure: the entry waits out the status-check timeout and is evicted. codeql.yml gets no `merge_group` trigger. Its analysis would run there, but the code-scanning roll-up check that branch protection names reports only in a pull-request context (github/codeql-action#1537, open and last confirmed 2026-05-22), so the build would gate nothing. Switching the queue on therefore means dropping `CodeQL` from the required contexts, where the ruleset's `code_scanning` rule goes on carrying it for pull requests. * ci: upload to Codecov with OIDC instead of a stored token The action's `use_oidc` input takes the job's own short-lived OIDC token and ignores any token supplied, so `CODECOV_TOKEN` stops being a credential worth stealing. Every same-repo pull request already ran this workflow with that secret in reach; a merge queue widens the set of authors who can reshape the job around it. The coverage job declares `id-token: write` for it, alongside the `contents: read` that job-level permissions otherwise drop. Fork pull requests are unaffected: the action skips OIDC when the head is a fork, which leaves them on the tokenless path an empty `secrets.CODECOV_TOKEN` already gave them. No step in the composite action carries `continue-on-error`, so a job that asks for OIDC without the permission to mint a token fails its upload step, the coverage job, and the aggregate gate behind it — with an error that names neither the input nor the permission.
1 parent af8d12b commit 312875d

3 files changed

Lines changed: 75 additions & 21 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7+
merge_group:
78

89
permissions:
910
contents: read
@@ -135,6 +136,9 @@ jobs:
135136
runs-on: ${{ matrix.os }}
136137
timeout-minutes: 20
137138
needs: test
139+
permissions:
140+
contents: read
141+
id-token: write
138142
strategy:
139143
fail-fast: false
140144
matrix:
@@ -169,7 +173,7 @@ jobs:
169173
uses: codecov/codecov-action@0b35c9ecc4f0529d0eb674914510c22f85b196b4 # v7.1.0
170174
with:
171175
files: coverage.xml
172-
token: ${{ secrets.CODECOV_TOKEN }}
176+
use_oidc: true
173177
fail_ci_if_error: false
174178

175179
- name: Upload test results to Codecov
@@ -178,7 +182,7 @@ jobs:
178182
with:
179183
report_type: test_results
180184
files: ./test-results/*.xml
181-
token: ${{ secrets.CODECOV_TOKEN }}
185+
use_oidc: true
182186

183187
ci:
184188
name: ci (all jobs succeeded)

‎CONTRIBUTING.md‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ whether or not the current shell has `.venv` activated:
102102
| `make mutation-ready` | arm the tree's bytecode for a mutation proof (see [Proving a test can fail](#proving-a-test-can-fail)) |
103103
| `make mutation-check` | verify it is still armed — a clean, a new worktree or a `uv sync` un-arms it silently |
104104

105-
CI runs the same tests on every push and pull request across Python 3.11–3.14
106-
and three operating systems, the same lint and formatting once in the
107-
`pre-commit` job, and the same type checks once per target platform on Python
108-
3.14 in the `types` job — see
109-
[`.github/workflows/ci.yml`](.github/workflows/ci.yml). Type-checking is
110-
deliberately two-tiered: `pyright` in basic mode across the whole tree
111-
(including tests), matching Pylance's VS Code defaults so editor diagnostics
112-
align with CI, plus `mypy --strict` on the state-bearing modules listed in
113-
`[tool.mypy] files` where a type slip would corrupt state.
105+
CI runs the same tests across Python 3.11–3.14 and three operating systems, the
106+
same lint and formatting once in the `pre-commit` job, and the same type checks
107+
once per target platform on Python 3.14 in the `types` job — see
108+
[`.github/workflows/ci.yml`](.github/workflows/ci.yml) for what triggers it.
109+
Type-checking is deliberately two-tiered: `pyright` in basic mode across the
110+
whole tree (including tests), matching Pylance's VS Code defaults so editor
111+
diagnostics align with CI, plus `mypy --strict` on the state-bearing modules
112+
listed in `[tool.mypy] files` where a type slip would corrupt state.
114113

115114
## Tests
116115

‎tests/test_ci_workflow.py‎

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
"""Guards for the aggregate gate in .github/workflows/ci.yml.
1+
"""Guards for .github/workflows/ci.yml.
22
33
Branch protection requires the gate's context in place of one per matrix leg,
44
so its `needs:` list is what decides which jobs can block a merge, and
55
`if: always()` is what makes it report — GitHub counts a skipped job as a pass.
6+
7+
A merge queue gates on that same context, evaluated against the merge group it
8+
builds, which is why the workflow triggers on `merge_group` too: a required
9+
check that never reports there does not fail the entry, it holds the queue
10+
until the status-check timeout evicts it.
11+
12+
The `use_oidc` input and the job's `id-token: write` permission have to travel
13+
together: without the permission the action's token step throws before the
14+
upload runs, and the error it raises names neither of them.
615
"""
716

817
from __future__ import annotations
@@ -17,28 +26,48 @@
1726
with open(_WORKFLOW, encoding="utf-8") as f:
1827
_CI = f.read()
1928

20-
_JOB_ID = re.compile(r"^ ([\w-]+):$", re.M)
29+
_BLOCK_KEY = re.compile(r"^ ([\w-]+):$", re.M)
2130
_INLINE_NEEDS = re.compile(r"^ needs: \[([^\]]+)\]$", re.M)
31+
_USE_OIDC = re.compile(r"^\s+use_oidc:\s*(.+?)\s*$", re.M)
2232

2333
_GATE = "ci"
2434

2535

26-
def _job_ids() -> set[str]:
27-
"""Every job id in the workflow, by its two-space indent under `jobs:`."""
28-
return set(_JOB_ID.findall(_CI.partition("\njobs:\n")[2]))
29-
36+
def _block(key: str) -> str:
37+
"""The lines under `key:`, up to the first one not indented past it."""
38+
body = _CI.partition(f"\n{key}:\n")[2]
39+
assert body, f"`{key.strip()}:` is no longer a block mapping on a line of its own"
3040

31-
def _job_block(job_id: str) -> str:
32-
"""One job's own lines — those indented deeper than its key."""
33-
body = _CI.partition(f"\n {job_id}:\n")[2]
41+
deeper = " " * (len(key) - len(key.lstrip(" ")) + 1)
3442
lines = []
3543
for line in body.splitlines():
36-
if line and not line.startswith(" "):
44+
if line and not line.startswith(deeper):
3745
break
3846
lines.append(line)
3947
return "\n".join(lines)
4048

4149

50+
def _job_ids() -> set[str]:
51+
"""Every job id in the workflow, by its two-space indent under `jobs:`."""
52+
return set(_BLOCK_KEY.findall(_block("jobs")))
53+
54+
55+
def _triggers() -> set[str]:
56+
"""Every event in the workflow's `on:` block, by its two-space indent."""
57+
return set(_BLOCK_KEY.findall(_block("on")))
58+
59+
60+
def _job_block(job_id: str) -> str:
61+
"""One job's own lines — those indented deeper than its key."""
62+
return _block(f" {job_id}")
63+
64+
65+
def _asks_for_oidc(job_block: str) -> bool:
66+
"""Whether a job uploads with OIDC — a value this cannot read counts as yes."""
67+
values = (match.group(1).strip("\"'").lower() for match in _USE_OIDC.finditer(job_block))
68+
return any(value != "false" for value in values)
69+
70+
4271
class AggregateGateTest(unittest.TestCase):
4372
def test_the_gate_needs_every_other_job(self):
4473
needs = _INLINE_NEEDS.search(_job_block(_GATE))
@@ -49,9 +78,31 @@ def test_the_gate_needs_every_other_job(self):
4978
"a job outside the gate's `needs:` can go red without blocking a merge",
5079
)
5180

81+
def test_the_gate_runs_on_a_merge_group(self):
82+
self.assertIn(
83+
"merge_group",
84+
_triggers(),
85+
"a queued pull request builds a merge group this workflow ignores, "
86+
"so the gate never reports and the queue evicts the entry on timeout",
87+
)
88+
5289
def test_the_gate_reports_when_a_dependency_fails(self):
5390
self.assertIn(
5491
"always()",
5592
_job_block(_GATE),
5693
"without `always()` the gate skips, and a skipped check satisfies branch protection",
5794
)
95+
96+
97+
class OidcUploadTest(unittest.TestCase):
98+
def test_a_job_uploading_with_oidc_can_mint_its_token(self):
99+
for job_id in _job_ids():
100+
block = _job_block(job_id)
101+
if not _asks_for_oidc(block):
102+
continue
103+
self.assertIn(
104+
"id-token: write",
105+
block,
106+
f"the `{job_id}` job uploads with OIDC but cannot mint a token, "
107+
"so the action's token step throws before the upload runs",
108+
)

0 commit comments

Comments
 (0)