Skip to content

Commit 2a2f3f2

Browse files
thymikeeclaude
andauthored
ci: fold six CI jobs into four with parallel and background steps; cancel superseded and closed-PR runs (#3658)
* ci: temporary fallow timing probe * ci: probe statx paths * ci: probe dirname via awk * ci: probe warm fallow cache and parallel step syntax * ci: cache fallow, fold compat into repo guards and lint into typecheck with parallel steps A cold fallow run re-resolves every import against the root tsconfig's 28 project references (~760 statx per import), which takes minutes on a hosted runner; the persisted parse cache skips unchanged files. Main pushes save the cache, every run restores it. Parallel steps let the CI workflow drop from six jobs to four without lengthening any lane: freerange runs in the background beside the other guards, and lint/format/DI-seams run beside typecheck. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: run the fallow audit in the background and drop the fallow cache The persisted cache only helps an identical tree: a PR head restored from its base still re-resolves every import (524s audit, 209s health on CI). Starting the audit beside freerange and the light guards takes it off the job's sequential path instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: run numeric ranges in sequence so only the fallow audit shares the runner * ci: cancel a PR's unfinished runs when it closes, and supersede runs in the remaining PR workflows * ci: cancel closed-PR runs from a pull_request trigger instead of pull_request_target * ci: keep test-app build-cache runs uncancelled, and fail on a refused cancel of a running run * ci: cancel only runs that belong to the closed PR --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent d2bafc0 commit 2a2f3f2

6 files changed

Lines changed: 172 additions & 106 deletions

File tree

‎.github/workflows/agent-guidance.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ on:
2929
permissions:
3030
contents: read
3131

32+
concurrency:
33+
group: >-
34+
ci-${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
35+
cancel-in-progress: true
36+
3237
jobs:
3338
contract:
3439
name: Ownership and context budgets

‎.github/workflows/ci.yml‎

Lines changed: 85 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ concurrency:
3030
cancel-in-progress: true
3131

3232
jobs:
33+
# Lint, typecheck, and package verification share one checkout and install. The lint gates
34+
# and typecheck are independent reads of the tree, so they run as one parallel group.
35+
#
3336
# The Swift trailing-comma assertion is text-only and runs before the toolchain setup, so a
3437
# grep failure does not wait on an install. The DI-seams check below needs a real TypeScript
3538
# runtime (#1976 / PR #2006), so it runs after Setup toolchain instead.
36-
lint:
37-
name: Lint & Format
39+
lint-typecheck-package:
40+
name: Lint, Typecheck & Package
3841
runs-on: ubuntu-latest
39-
timeout-minutes: 10
42+
timeout-minutes: 20
4043
steps:
4144
- name: Checkout
4245
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -69,51 +72,97 @@ jobs:
6972
- name: Setup toolchain
7073
uses: ./.github/actions/setup-node-pnpm
7174

72-
# Same false-green shape as the Swift check above (#1976). An earlier revision of this
73-
# gate (PR #2006, first review pass) fixed the exit-code handling but kept the ban/allow
74-
# decision as a regex that exempted matches by the *spelling* of the typeof target
75-
# (`typeof fetch` always passed, SCREAMING_SNAKE_CASE targets always passed) — a name-based
76-
# semantic allowlist that would silently pass a new, genuinely test-only `typeof fetch` seam
77-
# anywhere in the tree while banning an equally legitimate seam under any other name.
78-
# scripts/di-seams instead checks each match against an explicit, typed, per-site allowlist
79-
# (scripts/di-seams/approved.ts) keyed by (file, field, typeof-target): a triple is exempt
80-
# only because it was individually reviewed and named, never because of how it is spelled.
81-
# The gate fails just as hard on a stale approval (one whose triple no longer matches
82-
# anything) as on an unapproved seam, so the allowlist can't drift out of sync with the code
83-
# it describes. See scripts/di-seams/model.ts and its tests.
84-
- name: Fail if test-only DI seams reappear in production code
85-
uses: ./.github/actions/run-gate
86-
with: { gate: di-seams }
75+
- parallel:
76+
# Same false-green shape as the Swift check above (#1976). An earlier revision of this
77+
# gate (PR #2006, first review pass) fixed the exit-code handling but kept the ban/allow
78+
# decision as a regex that exempted matches by the *spelling* of the typeof target
79+
# (`typeof fetch` always passed, SCREAMING_SNAKE_CASE targets always passed) — a name-based
80+
# semantic allowlist that would silently pass a new, genuinely test-only `typeof fetch` seam
81+
# anywhere in the tree while banning an equally legitimate seam under any other name.
82+
# scripts/di-seams instead checks each match against an explicit, typed, per-site allowlist
83+
# (scripts/di-seams/approved.ts) keyed by (file, field, typeof-target): a triple is exempt
84+
# only because it was individually reviewed and named, never because of how it is spelled.
85+
# The gate fails just as hard on a stale approval (one whose triple no longer matches
86+
# anything) as on an unapproved seam, so the allowlist can't drift out of sync with the code
87+
# it describes. See scripts/di-seams/model.ts and its tests.
88+
- name: Fail if test-only DI seams reappear in production code
89+
uses: ./.github/actions/run-gate
90+
with: { gate: di-seams }
91+
92+
- name: Run oxlint
93+
uses: ./.github/actions/run-gate
94+
with: { gate: lint }
95+
96+
- name: Check formatting
97+
uses: ./.github/actions/run-gate
98+
with: { gate: format }
99+
100+
- name: Run typecheck
101+
uses: ./.github/actions/run-gate
102+
with: { gate: typecheck }
87103

88-
- name: Run oxlint
104+
- name: Build CLI
89105
uses: ./.github/actions/run-gate
90-
with: { gate: lint }
106+
with: { gate: build }
91107

92-
- name: Check formatting
108+
- name: Verify emitted chunk ownership
93109
uses: ./.github/actions/run-gate
94-
with: { gate: format }
110+
with: { gate: bundle-owner-files }
111+
112+
# The build runs on the default toolchain Node and the package is verified on the minimum
113+
# supported Node, so this job covers what a user on `engines.node` floor actually installs.
114+
- name: Setup Node.js 22.12
115+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
116+
with:
117+
node-version: '22.12'
95118

96-
# Structural guards share one checkout and install. Every gate stays an
97-
# independently named step with its own failure message; the gate manifest
98-
# derives lane ownership from these declarations, so merging jobs changes
99-
# nothing it asserts.
119+
# Packs, lints the tarball with publint/attw, installs it outside the workspace, and imports
120+
# every published entry point before running the CLI. See scripts/check-package.ts.
121+
#
122+
# Runs the script directly rather than through `pnpm check:package`: the repo's pinned pnpm
123+
# requires Node >= 22.13 and refuses to start on the 22.12 floor this job exists to cover. The
124+
# gate itself only needs `node` and `npm`, so it is the package.json script minus the launcher.
125+
- name: Verify the published package on Node.js 22.12
126+
run: node --experimental-strip-types scripts/check-package.ts
127+
128+
# Structural guards and the history-backed compatibility gates share one deep checkout and
129+
# install. Every gate stays an independently named step with its own failure message; the gate
130+
# manifest derives lane ownership from these declarations, so merging jobs changes nothing it
131+
# asserts.
100132
repo-guards:
101-
name: Repo Guards
133+
name: Repo Guards & Compatibility
102134
runs-on: ubuntu-latest
103-
timeout-minutes: 15
135+
timeout-minutes: 20
104136
steps:
105137
# The layering ratchets (R6/R9/R10) measure the merge-base with origin/main, which a
106-
# shallow checkout cannot reach.
138+
# shallow checkout cannot reach. Fallow, replay-compat, and daemon-wire-compat need full
139+
# history or tags.
107140
- name: Checkout
108141
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
109142
with:
110143
fetch-depth: 0
144+
fetch-tags: true
111145

112146
# The layering gate parses production sources with `oxc-parser`, so
113147
# dependencies are required; keep install-deps enabled.
114148
- name: Setup toolchain
115149
uses: ./.github/actions/setup-node-pnpm
116150

151+
# The fallow audit runs in the background beside the guards below. A cold fallow run costs
152+
# several minutes on a hosted runner: since fallow 3.20 every import re-walks the root
153+
# tsconfig's project references.
154+
- name: Run Fallow audit
155+
id: fallow-audit
156+
background: true
157+
env:
158+
FALLOW_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
159+
uses: ./.github/actions/run-gate
160+
with:
161+
gate: fallow
162+
args: |
163+
--base
164+
${{ env.FALLOW_BASE }}
165+
117166
- name: Check import-direction DAG
118167
# Structured import-direction lint over the resolved graph. See
119168
# scripts/layering/check.ts and CONTEXT.md (Architecture: folder DAG +
@@ -186,43 +235,6 @@ jobs:
186235
uses: ./.github/actions/run-gate
187236
with: { gate: mcp-metadata }
188237

189-
# Slowest guard (~3 min), so it runs last and structural failures surface
190-
# before it. Runs on plain Node via the shared install above.
191-
- name: Check numeric ranges
192-
uses: ./.github/actions/run-gate
193-
with: { gate: freerange }
194-
195-
# History-backed compatibility gates share one deep checkout: fallow,
196-
# replay-compat, and daemon-wire-compat all need either full history or tags,
197-
# which no shallow unit lane can read.
198-
compat-provenance:
199-
name: Compatibility & Provenance
200-
runs-on: ubuntu-latest
201-
timeout-minutes: 15
202-
steps:
203-
- name: Checkout
204-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
205-
with:
206-
fetch-depth: 0
207-
fetch-tags: true
208-
209-
- name: Setup toolchain
210-
uses: ./.github/actions/setup-node-pnpm
211-
212-
- name: Run Fallow audit
213-
env:
214-
FALLOW_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
215-
uses: ./.github/actions/run-gate
216-
with:
217-
gate: fallow
218-
args: |
219-
--base
220-
${{ env.FALLOW_BASE }}
221-
222-
- name: Check for production-unused exports
223-
uses: ./.github/actions/run-gate
224-
with: { gate: production-exports }
225-
226238
# The frozen replay-compat corpus (#1417) claims each entry was published by
227239
# a released tag. Only a full-history checkout can re-derive that claim.
228240
- name: Verify corpus entries against their released blobs
@@ -235,52 +247,21 @@ jobs:
235247

236248
# The daemon RPC wire ledger (#1432) is compared against the ledger as it
237249
# stood at the last RELEASED tag, which only a tagged checkout can read.
238-
# The shallow Repo Guards lane holds the ledger to its source; this step
239-
# holds it to the last release.
240250
- name: Compare the daemon RPC wire surface against the last released tag
241251
uses: ./.github/actions/run-gate
242252
with: { gate: daemon-wire-compat }
243253

244-
# Typecheck and package verification share one checkout and install; both
245-
# need the default toolchain only, and the package step re-pins Node itself.
246-
typecheck-package:
247-
name: Typecheck & Package
248-
runs-on: ubuntu-latest
249-
timeout-minutes: 20
250-
steps:
251-
- name: Checkout
252-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
253-
254-
- name: Setup toolchain
255-
uses: ./.github/actions/setup-node-pnpm
256-
257-
- name: Run typecheck
254+
- name: Check numeric ranges
258255
uses: ./.github/actions/run-gate
259-
with: { gate: typecheck }
256+
with: { gate: freerange }
260257

261-
- name: Build CLI
262-
uses: ./.github/actions/run-gate
263-
with: { gate: build }
258+
# Shares fallow's `.fallow` cache directory with the audit, so it starts once the audit ends.
259+
- name: Wait for the Fallow audit
260+
wait: fallow-audit
264261

265-
- name: Verify emitted chunk ownership
262+
- name: Check for production-unused exports
266263
uses: ./.github/actions/run-gate
267-
with: { gate: bundle-owner-files }
268-
269-
# The build runs on the default toolchain Node and the package is verified on the minimum
270-
# supported Node, so this job covers what a user on `engines.node` floor actually installs.
271-
- name: Setup Node.js 22.12
272-
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
273-
with:
274-
node-version: '22.12'
275-
276-
# Packs, lints the tarball with publint/attw, installs it outside the workspace, and imports
277-
# every published entry point before running the CLI. See scripts/check-package.ts.
278-
#
279-
# Runs the script directly rather than through `pnpm check:package`: the repo's pinned pnpm
280-
# requires Node >= 22.13 and refuses to start on the 22.12 floor this job exists to cover. The
281-
# gate itself only needs `node` and `npm`, so it is the package.json script minus the launcher.
282-
- name: Verify the published package on Node.js 22.12
283-
run: node --experimental-strip-types scripts/check-package.ts
264+
with: { gate: production-exports }
284265

285266
# Runs the full unit + provider-integration suites under coverage with
286267
# thresholds, so a separate unit-tests job would rerun the same tests.

‎.github/workflows/docs.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ on:
4242
permissions:
4343
contents: read
4444

45+
concurrency:
46+
group: >-
47+
ci-${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
48+
cancel-in-progress: true
49+
4550
jobs:
4651
check:
4752
name: Prose, internal links, and heading anchors
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Cancel runs of closed PRs
2+
3+
# A merged or closed PR gates nothing, so its queued and running runs only hold runners.
4+
on:
5+
pull_request:
6+
types:
7+
- closed
8+
9+
permissions:
10+
actions: write
11+
12+
jobs:
13+
cancel:
14+
# A fork PR's token is read-only, so it cannot cancel runs.
15+
if: github.event.pull_request.head.repo.full_name == github.repository
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 5
18+
steps:
19+
# pr-preview-cleanup.yml runs on the same close event and must finish.
20+
- name: Cancel the PR's unfinished runs
21+
env:
22+
GH_TOKEN: ${{ github.token }}
23+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
24+
PR_NUMBER: ${{ github.event.pull_request.number }}
25+
RUN_ID: ${{ github.run_id }}
26+
run: |
27+
ids=$(gh api --paginate -X GET "repos/$GITHUB_REPOSITORY/actions/runs" \
28+
-f branch="$HEAD_REF" -f event=pull_request -f per_page=100 \
29+
--jq ".workflow_runs[]
30+
| select(.status != \"completed\")
31+
| select(.head_repository.full_name == \"$GITHUB_REPOSITORY\")
32+
| select(any(.pull_requests[]; .number == $PR_NUMBER))
33+
| select(.id != $RUN_ID)
34+
| select(.path != \".github/workflows/pr-preview-cleanup.yml\")
35+
| .id")
36+
refused=()
37+
for id in $ids; do
38+
gh run cancel "$id" --repo "$GITHUB_REPOSITORY" || refused+=("$id")
39+
done
40+
# A run that finished after the listing refuses cancellation; any other refusal is an error.
41+
for id in "${refused[@]}"; do
42+
status=$(gh run view "$id" --repo "$GITHUB_REPOSITORY" --json status --jq .status)
43+
[ "$status" = completed ] || { echo "::error::Could not cancel run $id ($status)"; exit 1; }
44+
done

‎scripts/gate/workflows.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@ jobs:
221221
assert.ok(caller?.uses.includes('.github/workflows/called.yml'));
222222
});
223223

224+
test('gates inside a parallel step group belong to the lane, alongside sequential ones', () => {
225+
const lanes = planted({
226+
'.github/workflows/planted.yml': `name: Planted
227+
on:
228+
pull_request:
229+
jobs:
230+
planted:
231+
steps:
232+
- parallel:
233+
- uses: ./.github/actions/run-gate
234+
with:
235+
gate: layering
236+
- uses: ./.github/actions/run-gate
237+
with:
238+
gate: lint
239+
- uses: ./.github/actions/run-gate
240+
with:
241+
gate: format
242+
`,
243+
});
244+
assert.deepEqual(lanes[0]?.gates, ['layering', 'lint', 'format']);
245+
});
246+
224247
test('a remote or nested reusable workflow fails closed', () => {
225248
const lanes = planted({
226249
'.github/workflows/planted.yml': `name: Planted

‎scripts/gate/workflows.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type RawStep = {
3636
uses?: string;
3737
run?: string;
3838
with?: Record<string, unknown>;
39+
parallel?: RawStep[];
3940
};
4041

4142
type Job = { name?: string; steps?: RawStep[]; uses?: string; with?: Record<string, unknown> };
@@ -179,6 +180,11 @@ function readLocalWorkflowJobs(uses: string, root: string): Job[] | null {
179180
return jobs.length > 0 ? jobs : null;
180181
}
181182

183+
/** A job's steps with each `parallel:` group opened into the steps it runs. */
184+
function runnableSteps(steps: readonly RawStep[]): RawStep[] {
185+
return steps.flatMap((step) => (step.parallel ? runnableSteps(step.parallel) : [step]));
186+
}
187+
182188
/** What a job runs, with the caller's `with` inputs that the steps' `${{ inputs.* }}` resolve to. */
183189
type JobSteps = {
184190
steps: RawStep[];
@@ -192,13 +198,15 @@ type JobSteps = {
192198
* missing, jobless, or nested reusable workflow fails closed as unsupported.
193199
*/
194200
function jobSteps(job: Job, root: string): JobSteps {
195-
if (!job.uses) return { steps: job.steps ?? [], inputs: {}, files: [], unsupported: [] };
201+
if (!job.uses) {
202+
return { steps: runnableSteps(job.steps ?? []), inputs: {}, files: [], unsupported: [] };
203+
}
196204
const called = readLocalWorkflowJobs(job.uses, root);
197205
if (!called || called.some((calledJob) => calledJob.uses)) {
198206
const unsupported = [`\`uses: ${job.uses}\` (reusable workflow)`];
199207
return { steps: [], inputs: {}, files: [], unsupported };
200208
}
201-
const steps = called.flatMap((calledJob) => calledJob.steps ?? []);
209+
const steps = called.flatMap((calledJob) => runnableSteps(calledJob.steps ?? []));
202210
return { steps, inputs: job.with ?? {}, files: [job.uses.slice(2)], unsupported: [] };
203211
}
204212

0 commit comments

Comments
 (0)