Skip to content

fix(ci): a matrix job's per-leg names cannot be required status checks - #365

Merged
athvin merged 1 commit into
mainfrom
bm/infra-plan-gate-aggregator
Nov 1, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/infra-plan-gate-aggregator

Conversation

@athvin

@athvin athvin commented Nov 1, 2026

Copy link
Copy Markdown
Owner

I made plan (state-backend), plan (core), plan (dev) and plan (prod) required after #360. The next non-infra PR — #359, the agentic workflows — went unmergeable with all four stuck on "Expected — waiting for status to be reported". The four contexts are already removed from branch protection, so #359 is unblocked; this PR is the proper fix.

The behaviour, stated exactly

While a matrix job runs, it reports one check-run per leg — plan (core), plan (dev), … — which look like perfectly good contexts. When the job is skipped by its if:, GitHub reports a single check-run under the literal, uninterpolated name plan (${{ matrix.key }}).

Observed on #359's head:

skipped   plan comment
skipped   plan (${{ matrix.key }})
skipped   apply (${{ matrix.key }})

So the per-leg contexts never report at all on a PR that skips the tier — and a required context that never reports blocks the PR forever. That is the same failure mode as a paths: filter, which is precisely what this workflow's detect job exists to avoid. I replaced one trap with another wearing a different hat.

fmt + validate (credential-free) was fine throughout, and the contrast is the diagnosis: it isn't a matrix job, so it reports skipped under its own name and branch protection accepts that.

The fix

A non-matrix aggregator job, context terraform plan, which needs: plan and inspects needs.plan.result — the aggregate, success only if every leg succeeded. Being non-matrix, it reports skipped when the tier is skipped, so it's safe to require in the legs' place.

Two details:

  • skipped is accepted. Exactly one thing produces it: a fork PR, which is issued no id-token and so cannot assume the plan role at all (the plan job skips itself for that reason). Treating it as a failure would make every fork PR unmergeable — this same bug pointed the other way.
  • Anything unrecognised fails, including an empty result.

Verified against all five values needs.*.result can take, by extracting the step's shell from the YAML:

needs.plan.result exit
success 0
skipped 0
failure 1
cancelled 1
(empty) 1

Documented where the next person hits it

The ci-and-supply-chain skill now carries this as the third "a job's name: is its context" failure mode, alongside renaming and adding-before-it-exists. And the generated job table — which displays plan (${{ matrix.key }}) verbatim, i.e. the trap itself — gained a preamble line saying a context containing ${{ matrix.* }} cannot be required and to require an aggregator instead.

Branch protection is not touched here

That comes after this reports green on main — the only safe order. The intended end state for infra is three contexts, all non-matrix: fmt + validate (credential-free) (already required), terraform plan, and terraform ci helpers (self-test).

One bug caught while verifying, in the gate's own message: a backticked word inside a double-quoted shell string is command substitution, so the first draft ran validate and printed its empty output in place of the word. Single-quoted now.

required-checks.md and skills-check.sh will conflict with #359 — both PRs touch them. Whoever merges second re-runs scripts/skills-check.sh regen.

🤖 Generated with Claude Code

I made `plan (state-backend)`, `plan (core)`, `plan (dev)` and
`plan (prod)` required in #360's follow-up. The next non-infra PR — #359,
the agentic workflows — went unmergeable, with all four stuck on
"Expected — waiting for status to be reported", and the four contexts have
been removed from branch protection to unblock it.

The behaviour, stated exactly, because it is genuinely surprising:

  While a matrix job RUNS it reports one check-run per leg —
  `plan (core)`, `plan (dev)`, … — which look like perfectly good
  contexts. When the job is SKIPPED by its `if:`, GitHub reports a single
  check-run under the literal, uninterpolated name
  `plan (${{ matrix.key }})`.

So per-leg contexts never report at all on a PR that skips the tier, and a
required context that never reports blocks the PR forever — the same
failure mode as a `paths:` filter, which is precisely what this workflow's
`detect` job exists to avoid. I replaced one trap with another wearing a
different hat.

`fmt + validate (credential-free)` was fine throughout, and the contrast is
the diagnosis: it is not a matrix job, so it reports `skipped` under its own
name and branch protection accepts that.

The fix is a non-matrix aggregator, `terraform plan`, which `needs: plan`
and inspects `needs.plan.result` — the aggregate, `success` only if every
leg succeeded. It reports `skipped` when the tier is skipped, so it is
safe to require in the legs' place.

Two details in it:

- `skipped` is ACCEPTED. Exactly one thing produces it: a fork PR, which
  is issued no `id-token` and so cannot assume the plan role (the `plan`
  job skips itself for that reason). Treating it as failure would make
  every fork PR unmergeable — this same bug pointed the other way.
- anything unrecognised, including an empty result, FAILS. Verified
  against all five values `needs.*.result` can take.

Documented where the next person will hit it: the `ci-and-supply-chain`
skill now carries it as the third `name:`-is-a-context failure mode, and
the generated job table — which displays `plan (${{ matrix.key }})`
verbatim, i.e. the trap itself — gained a preamble line saying a context
containing `${{ matrix.* }}` cannot be required.

Nothing is added to branch protection here. That comes after this reports
green on `main`, which is the only safe order.

One bug caught while verifying, in the gate's own message: a backticked
word inside a double-quoted shell string is command substitution, so the
first draft ran `validate` and printed its empty output in place of the
word. Single-quoted now.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

terraform plan

469cd5d · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 0 0
dev 0 0 0
prod 0 0 0

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

@athvin
athvin merged commit cf137e7 into main Nov 1, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants