Skip to content

feat(actions): change-scoped CI execution with conservative filtering - #327

Merged
kyle-sexton merged 3 commits into
mainfrom
feat/244-change-scoped-ci
Jul 31, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
feat/244-change-scoped-ci

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Summary

Adds change-scoped CI execution with conservative filtering, per #244's spec: a new first-party change-detection composite action, dogfooded in this repo's ci.yml, so file-type-scoped lanes skip at JOB level when a PR cannot affect them — a changed PowerShell file no longer runs the .NET, Go, Python, TypeScript, or Pester lanes, and a docs-only PR runs a fraction of the matrix.

Filter mechanism (decided at execution per the issue's locked scope): the action generalizes the already-hardened relevance matcher from claude-security-review.yml's changes job — checkout-free PR file listing via the API (actions/github-script, no gh CLI dependency), root-anchored gitignore matching via git check-ignore in a scratch repo, !/?/+ rejected up front because they silently match FEWER files under gitignore rules than under Actions paths: rules — extended to many named filter groups sharing one listing, emitting a single results JSON output of "true"/"false" strings. First-party rather than dorny/paths-filter or tj-actions/changed-files (CVE-2025-30066 was the mutable-tag vector this repo's pin policy exists to avoid): the repo already owns an audited matcher with exactly the fail-open semantics required, and reusing it keeps one matcher vocabulary (reuse-or-replace, no second parallel way).

Safety model — why a needed lane cannot be silently skipped

The non-negotiable constraint is "never overfilter into silently skipped tests". Defense in depth, all layers verified against current GitHub docs:

  1. Job-level skips only, never workflow-level paths:. Per GitHub's Troubleshooting required status checks, a workflow skipped by path filters leaves its required checks Pending and blocks merge forever ("Avoid requiring workflows that can be skipped"), while a job skipped by an if: conditional reports conclusion skipped — and "successful check statuses are success, skipped, and neutral". This repo additionally aggregates everything into the single required ci-status check, which if: always() runs unconditionally, so the required check always reports regardless of which lanes skipped.
  2. Fail-open on every operational fault. Non-pull_request events (pushes to main always run everything), API listing failures, and listings at the 3,000-file pulls.listFiles cap (a truncated listing could hide the file that made a lane relevant) all resolve every group to "true".
  3. Gates read != 'false', never == 'true', under !cancelled(). A failed detection job leaves the output unset, which is not 'false' — every gated lane then runs in full. String booleans are deliberate: with JSON false and != false, GitHub's expression coercion makes null == false true, so a group name absent from the filters would silently skip its lane; with strings, an absent key (null != 'false') runs it.
  4. Broken detection goes red, not quietly green. changes is aggregated by ci-status alongside the lanes it gates: config errors (bad pattern syntax, malformed groups) fail the detection job even on runs that fall back to run-everything, so lanes still run (layer 3) but the required check fails until the config is fixed — fail-open cannot become the permanent steady state unnoticed.
  5. Conservative filters. Every group includes .github/** (any CI change re-runs everything); language groups glob their file types repo-wide, not just the fixture trees the lanes currently scope to; content-agnostic lanes (typos, editorconfig, gitleaks, links, exec-bit, action-metadata-filename, machine-specific-paths, eol-renormalize, comment-hygiene) stay unconditional because any file can carry the defect they gate on. osv-scanner is also deliberately ungated: a filter enumerating every manifest/lockfile format OSV supports would drift as upstream adds formats, and an unlisted new lockfile type would then skip the scan that covers it.

An independent fresh-context review of the staged diff (rationale withheld) audited every gated lane's actual checked file surface against its filter group; its findings are folded in — notably fixtures/composite-action/** added to the powershell, actionlint, and zizmor groups (those lanes' composite-metadata tests read those fixtures), nested **/.markdownlint* configs and nuget.config case variants covered, the osv-scanner ungating above, executable bits on the new scripts (the ungated exec-bit lane would have caught this PR itself), and a parser guard rejecting indented header-shaped filter lines as ambiguous instead of silently stealing the patterns that follow them.

Accepted tradeoffs: gated lanes now start after the changes job (~30–60 s serialization per run) and the detection job itself bills roughly one hosted minute; both are recouped as soon as one lane skips (this workflow has 18 gated jobs, including a Windows Pester lane that bills at 2×). A PR with zero changed files skips all gated lanes; the ungated lanes and ci-status still run.

Deliberate non-refactor: claude-security-review.yml's inline changes job keeps its own copy of the matcher rather than calling this action. That job is deliberately checkout-free inside a reusable workflow — a local ./ action reference requires a checkout, and a remote reference would pin this repo's own SHA inside itself. Re-pointing it at this action (accepting a narrow checkout, under its own security review) is follow-up work, tracked on #244.

Spend note and consumer rollout

This repo is public, so its own hosted minutes are free — the dogfood here is the reference wiring plus latency/queue relief. The billable win lands when the four private consumers (medley, dotfiles, provisioning, github-iac — all already on the ci-status aggregator pattern, none path-filtering today) adopt the action in their locally-owned ci.yml files; consumer ci.ymls are deliberately not standards-sync-managed, so rollout is per-repo PRs, tracked from #244.

Test plan

  • match.test.sh: 19 cases — fail-open branches (non-PR event, failed/missing listing), per-group matching, root-anchoring parity with Actions paths:, previous-path (rename) listing matching, empty-listing and vacuous-group behavior, and every configuration error (negation, ?/+, pattern before header, indented header-shaped lines, invalid/duplicate group names, no groups) including that config errors fail even on the run-everything fallback path. Wired into the selector-contract lane.
  • node --test .github/scripts/*.test.cjs green locally (one slice anchor in select-runner.test.cjs newline-anchored so job-level lookups no longer collide with same-named filter groups).
  • actionlint and zizmor clean on the changed workflow and action; shellcheck and shfmt clean on the new scripts (change-detection added to the shfmt lane's paths).
  • This PR's own CI run demonstrates the wiring live: it touches .github/**, so every gated lane must run (nothing may skip), and ci-status must aggregate changes as success.

Related

Fixes #244. Related: #243 (org-wide CI/CD conventions audit), #245 (self-hosted runner performance, explicitly out of scope here), #242 (claude-code-action fleet audit).

🤖 Generated with Claude Code

https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C

… filtered CI

Generalize the claude-security-review relevance matcher into a reusable
change-detection composite action (API file listing, root-anchored
gitignore matching, fail-open on every operational fault, hard errors on
unhonorable filter syntax) and dogfood it in ci.yml: file-type-scoped
lanes gate at job level under the always-running ci-status required
check, so a skipped lane reports skipped and branch protection still
passes, while a failed detection goes red instead of riding fail-open to
silent green. Content-agnostic lanes and osv-scanner stay unconditional.

Fixes #244

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 5m 27s —— View job


Claude finished the review

Tasks

  • Gather context (diff, CLAUDE.md, REVIEW.md, changed files)
  • Understand the request (code review only, no implementation)
  • Review .github/actions/change-detection/action.yml
  • Review .github/actions/change-detection/match.sh
  • Review .github/actions/change-detection/match.test.sh
  • Review .github/workflows/ci.yml wiring
  • Review select-runner.test.cjs change
  • Review README.md update
  • Post final review

🔴 Blocking — shfmt lane is currently failing on this exact commit

I checked this PR's own ci workflow run (not the author's Test plan claims) via the CI tool and it's red: run 30597522414, job shfmt failed at "Check shell formatting" (step 3). The job log shows shfmt -d reporting real diffs in the new file:

diff .github/actions/change-detection/match.sh.orig .github/actions/change-detection/match.sh
@@ -37,8 +37,8 @@
    case "$trimmed" in
-    \#*) continue ;;
-    *) ;;
+  \#*) continue ;;
+  *) ;;
    esac
@@ -147,8 +147,8 @@
      case "$pattern" in
-      /*) printf '%s\n' "$pattern" >>"$ignore" ;;
-      *) printf '/%s\n' "$pattern" >>"$ignore" ;;
+    /*) printf '%s\n' "$pattern" >>"$ignore" ;;
+    *) printf '/%s\n' "$pattern" >>"$ignore" ;;
      esac

Both case bodies in match.sh (lines 40–41) and lines 150–151 are over-indented relative to the repo's .editorconfig-driven shfmt policy. This is the exact irony the PR body calls out for exec-bit catching itself — here it's shfmt catching itself. Since shfmt is one of the newly-gated lanes and also feeds the required ci-status aggregate, this blocks merge as-is.

Fix this →

Everything else — solid

I traced the whole diff against CLAUDE.md and REVIEW.md's code-review scope (correctness, design, error handling, tests, docs — security items are left to claude-security-review, which passed on this PR):

  • Fail-open semantics are correctly implemented. Traced every branch in match.sh: non-pull_request event, failed/missing listing, vacuous group, and check-ignore rc>1 all resolve to "true", and config errors (!, ?, +, bad names, duplicates, no groups, pattern-before-header, indented header-shaped lines) hard-exit 1 before any fallback branch — so a broken config can't ride fail-open to green. This matches the PR's own stated safety model point-for-point.
  • Gate wiring in ci.yml is correct. Every gated job uses !cancelled() && fromJSON(needs.changes.outputs.results || '{}')['<group>'] != 'false' (never == 'true'), changes is added to ci-status's needs, and the content-agnostic lanes (typos, editorconfig, gitleaks, links, exec-bit, action-metadata-filename, machine-specific-paths, eol-renormalize, comment-hygiene) and osv-scanner correctly remain ungated — verified by grepping each job in the diff.
  • Filter groups line up with real fixture directories (composite-action, dotnet, go, pester, python, reference-integrity, shell, typescript all exist), and every group includes .github/** as claimed.
  • match.test.sh has 19 case: blocks as claimed, and its own root-anchoring / rename / vacuous-group logic checks out against the matcher code. The actual selector-contract job (which runs this suite) passed on this commit's CI run.
  • select-runner.test.cjs fix is correct and necessary: the filter block in ci.yml now contains a more-indented selector-contract:/zizmor: filter-group line before the real job headers, so the old bare " selector-contract:" substring search would have matched inside the filter block instead of the job definition. The new "\n selector-contract:" anchor (exactly 2 spaces after a newline) correctly skips the deeper-indented filter lines and lands on the real 2-space-indented job headers.
  • Executable bits on match.sh/match.test.sh are correctly set (-rwxr-xr-x), consistent with the PR's claim that the ungated exec-bit lane would have caught a miss here.
  • SHA pins (actions/checkout, actions/github-script) match the exact pins used elsewhere in the repo, satisfying CLAUDE.md's pin-everything rule.
  • Deliberate non-refactor of claude-security-review.yml's own changes job (kept separate rather than calling this new action) is reasonable and explicitly documented as tracked follow-up on CI spend efficiency: change-scoped execution with conservative filtering #244 — not a hidden duplication.

One minor, non-blocking observation: the 3,000-file API-cap / pagination logic lives entirely in action.yml's inline github-script block and has no automated test (unlike match.sh, which is thoroughly covered by match.test.sh). This mirrors the pre-existing pattern in claude-security-review.yml's own changes job, so it's not a regression introduced here — just noting it as a pre-existing gap this PR inherits rather than closes.

Note: I don't have bash-script execution available in this environment (git/node work, but invoking shell scripts directly requires approval that isn't grantable here), so match.test.sh and the shfmt check above were verified by reading the actual failing CI job log for this commit, not by running them myself.
· Branch

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 3m 19s —— View job


Security review complete

  • Gather context (diff, changed files)
  • Review change-detection/action.yml
  • Review change-detection/match.sh
  • Review change-detection/match.test.sh
  • Review ci.yml wiring
  • Review select-runner.test.cjs / README changes
  • Post findings

Scope

Reviewed all 6 changed files against origin/main: the new change-detection composite action (action.yml, match.sh, match.test.sh), its wiring into ci.yml, the select-runner.test.cjs anchor fix, and the README addition. Per the task instructions, supply-chain/pin risk, trigger patterns, permissions, and template-injection are zizmor's lane — not re-litigated here. Focus was on trust-boundary reasoning: how PR-controlled data (the changed-file listing) flows through this new component, and whether any path can cause a security-relevant lane to be silently skipped — the one failure mode this action exists to prevent.

Findings

No exploitable vulnerabilities found.

Specifically checked and ruled out:

  • Command/argument injection via filenames. List changed files (action.yml#L58-L86) writes untrusted PR filenames with fs.writeFileSync, never through core.exportVariable/GITHUB_OUTPUT/GITHUB_ENV — so there's no multi-line-output-injection surface (the class those two files are classically vulnerable to). match.sh only ever feeds that file to git check-ignore --stdin (match.sh#L166) — data on stdin, never interpolated into a command string.
  • Token/permission scope. The changes job in ci.yml declares contents: read + pull-requests: read only (ci.yml), narrower than the workflow-level default, and the trigger is pull_request (not _target) with no secrets in play — consistent with this repo's documented safety model for untrusted-code jobs.
  • Under-filtering (the dangerous direction). Traced whether a crafted PR (e.g., an embedded-newline filename, a rename shuffling previous_filename) could make a group that should read "true" read "false" instead — the one outcome that would let a malicious change dodge its lane. Every case traced either fails open by construction (non-PR event, failed/capped listing, vacuous group, check-ignore rc>1) or can't produce a false negative: a filename crafted to split around an extension via an embedded newline stops matching the detector's **/*.ext pattern, but that same split also means the real file glob the downstream lane tooling uses (e.g. **/*.ps1) won't pick it up either — so there's no way to smuggle a file past detection that a lane would otherwise have treated as in-scope.
  • GITHUB_OUTPUT / JSON construction. emit_results (match.sh#L100-L109) builds the results JSON only from names (regex-validated, workflow-owned, not PR-controlled) and values (literal "true"/"false") — no PR-controlled content reaches the output line.
  • Local action ref + pull_request checkout. The changes job checks out the PR merge ref before invoking ./.github/actions/change-detection (required for a local uses: ./... ref), so a fork PR that also edits the matcher itself would run its modified version — but this is bounded by the same no-secrets/read-only-token guarantee CLAUDE.md documents for pull_request-triggered jobs, not a new privilege the matcher introduces.

Everything above matches the defense-in-depth the PR description claims (job-level-only skips, != 'false' gating under !cancelled(), changes aggregated into the required ci-status check so a broken config goes red rather than green). I didn't find a gap in it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d1f63d043

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/ci.yml Resolved
@github-actions

Copy link
Copy Markdown

Claude has reviewed this PR 1 time. The lane skips further automatic reviews after 5; deleting this comment resets the count.

…t contract

The shfmt lane runs flagless and reads .editorconfig, which does not set
switch_case_indent; the local pre-push check wrongly passed -ci.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 1m 16s —— View job


Security review complete

  • Gather context (git diff origin/main...HEAD, changed files at b291c33)
  • Review .github/actions/change-detection/action.yml
  • Review .github/actions/change-detection/match.sh
  • Review .github/actions/change-detection/match.test.sh
  • Review .github/workflows/ci.yml wiring
  • Review select-runner.test.cjs / README.md changes
  • Post findings

Scope

This is a re-run on the current head, b291c33. I diffed it against the prior reviewed commit (0d1f63d) first: the only change is the shfmt dedent fix to two case statement bodies in match.sh (lines 39–42, 149–152) — pure whitespace, no logic change. I re-read all 6 changed files in full against origin/main rather than relying on that diff alone.

Findings

No exploitable vulnerabilities found.

Trust-boundary reasoning specifically checked:

  • PR-controlled data flow (filenames → matcher). action.yml's "List changed files" step writes untrusted PR filenames via fs.writeFileSync, never through core.exportVariable / GITHUB_OUTPUT / GITHUB_ENV — no multi-line-output-injection surface. match.sh only ever pipes that file to git check-ignore --stdin — data on stdin, never interpolated into a command string or eval'd.
  • Injection via the filters input. The only consumer of this action, ci.yml's changes job, passes a fully static, workflow-owned multi-line string — no github.event.* / PR title / branch-name interpolation feeds filters, so there's no template-injection path into the run: step that consumes it via $FILTERS.
  • Under-filtering (the dangerous direction). Re-traced whether a crafted PR (embedded-newline filename, a rename shuffling previous_filename) could flip a group that should read "true" to "false". Every case still either fails open by construction (non-PR event, failed/capped listing, vacuous group, check-ignore rc>1) or can't produce a false negative for the reason given in the last review: a filename split via an embedded newline stops matching the detector's glob, but the same split means the real downstream lane tooling's glob (e.g. **/*.ps1) wouldn't pick it up either.
  • Token/permission scope unchanged and minimal. The changes job still declares only contents: read + pull-requests: read (ci.yml#L42-L44), trigger is pull_request (not _target), no secrets in play, persist-credentials: false on checkout.
  • GITHUB_OUTPUT / JSON construction. emit_results still builds results only from names (regex-validated, workflow-owned) and literal "true"/"false" — no PR-controlled content reaches the output line, so no GITHUB_OUTPUT heredoc-injection surface.
  • select-runner.test.cjs / README.md diffs are test-anchor and documentation changes only — no security-relevant surface.

Consistent with the prior pass on this PR: defense-in-depth is intact (job-level-only skips, != 'false' gating under !cancelled(), changes aggregated into the required ci-status check). Per scope, supply-chain/pin risk, trigger patterns, and permission-widening are left to zizmor's static lane, which is unaffected by this whitespace-only change.
· Branch

## Fix

The `zizmor` filter group matched `.github/**` and
`fixtures/composite-action/**` only, but the lane runs with `paths: .`
and audits composite-action metadata wherever it lives. A composite added
outside `.github/actions/` — say `tools/example/action.yml` — set the
group to `false` and skipped a security lane that does audit that file:
an underfilter, the exact direction this action's safety model calls
non-negotiable.

Adding `**/action.yml` closes it. That single pattern is complete because
`action.yaml` is rejected repo-wide by the always-run
action-metadata-filename gate, so no second spelling can hide.

zizmor is the only group needing a repo-wide pattern, and the added
comment says why so the asymmetry is not read as an oversight. Every
sibling lane's discovery really is confined to `.github/`, verified
rather than assumed: `actionlint` auto-discovers `.github/workflows`
only, `composite-run-shellcheck.sh` globs
`.github/actions/*/action.yml`, and ci.yml's "Validate composite
actions" check-jsonschema step passes the same scoped glob.

## Verification

Drove the real `match.sh` with the filter block extracted from the live
`ci.yml`, listing a single changed file `tools/example/action.yml`:

- before (pattern stripped): `zizmor: false` — reproduces the skip
- after: `zizmor: true`
- docs-only listing after: `zizmor: false`, `markdown: true` — the
  change-scoping this PR exists for is intact, not traded away

Also added a contract test pinning the gate to the audit scope, and
confirmed it FAILS with the pattern removed rather than passing
vacuously. `match.test.sh` (12 cases), `zizmor-native.test.cjs` (6),
Biome format-check, and comment-hygiene all pass; the two touched files
add no hygiene violations.

## Related

Addresses the P2 review finding on #327. No linked issue beyond the PR's
own #244.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 1m 6s —— View job


Security review complete

  • Gather context (git diff origin/main...HEAD at 6f6580c)
  • Review changes since last reviewed commit (b291c33 → 6f6580c): zizmor gating fix + zizmor-native.test.cjs
  • Re-verify full diff trust-boundary reasoning still holds
  • Post findings

Scope

Re-run on the current head, 6f6580c. The only change since the last-reviewed commit (b291c33) is:

  • ci.yml: adds **/action.yml to the zizmor filter group, so a composite action added anywhere in the repo (not just under .github/) no longer skips the lane that audits it (zizmor runs with paths: ., repo-wide).
  • zizmor-native.test.cjs: adds a regression test asserting the gate stays as wide as the lane's audit scope.

This directly resolves the third-party Codex review comment on the prior commit (zizmor's filter under-covering its own paths: . scope) — the fix widens a filter, it doesn't touch permissions, triggers, secrets, or any injection-relevant surface.

Findings

No exploitable vulnerabilities found, in this delta or in the PR as a whole. Confirmed the rest of the diff is unchanged and my prior trust-boundary analysis still holds:

  • changes job (ci.yml#L39-L44) — unchanged: contents: read + pull-requests: read only, persist-credentials: false, trigger is pull_request (not _target), no secrets in scope.
  • zizmor job (ci.yml#L557-L566) — the gate change is filter-list data only (a new gitignore-style pattern string), not a run:/with:/permissions: change; no new injection surface, since filter values are workflow-owned and never interpolated through a shell.
  • PR-controlled data flow (filenames → matcher) — action.yml still writes untrusted filenames via fs.writeFileSync, never through core.exportVariable/GITHUB_OUTPUT/GITHUB_ENV; match.sh only pipes that file to git check-ignore --stdin, never interpolated into a command string.
  • Under-filtering direction — re-checked that no crafted PR (embedded-newline filename, rename shuffling previous_filename) can flip a group that should read "true" to "false"; every fault path (non-PR event, failed/capped listing, vacuous group, check-ignore rc>1) still fails open by construction.
  • GITHUB_OUTPUT construction — emit_results still builds results only from workflow-owned group names and literal "true"/"false" — no PR-controlled content reaches the output line.

Consistent with both prior passes on this PR: defense-in-depth is intact (job-level-only skips, != 'false' gating under !cancelled(), changes/zizmor both aggregated appropriately). Per scope, supply-chain/pin risk, trigger patterns, and permission-widening are left to zizmor's own static lane, which this commit's change doesn't touch.

@kyle-sexton
kyle-sexton merged commit 2b3ddaf into main Jul 31, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the feat/244-change-scoped-ci branch July 31, 2026 03:55
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.

CI spend efficiency: change-scoped execution with conservative filtering

1 participant