Skip to content

Commit 3688e5c

Browse files
ci(repo-gates): restore the build's turbo cache, save and prune on push only (#13360)
Closes #13348 Clause-②: no ## Governed surface `.github/workflows/**` is on objectui's governed surface (`node scripts/check-governed-queue-guard.mjs --test .github/workflows/repo-gates.yml` → GOVERNED). This PR stays **draft** until an approval from a governed approver (`os-zhuang` / `hotlong`) is on record. ## What changed (3 files) - **`.github/workflows/repo-gates.yml`**: the build step now has a Turbo cache, set up the same way as `performance-budget.yml`'s `bundle-analysis` cache (objectui#12276): - **Restore Turbo Cache** runs before "Build every package the gates below read". It uses `actions/cache/restore@v6` on `.turbo/cache`, with the key `turbo-${{ runner.os }}-repo-gates-${{ github.sha }}` and one restore key, `turbo-${{ runner.os }}-repo-gates-`. It runs on the same condition as the build: `!cancelled() && steps.install.outcome == 'success'`. - The build step sets `TURBO_RUN_SUMMARY: 'true'`. The build command and its filter set are unchanged, and it is still never an unfiltered `turbo run build` (header, `repo-gates.yml:55`). - Three bookkeeping steps run after the last gate, all bounded and `continue-on-error`: - **Report what the turbo cache replayed** runs on every run (`!cancelled()`). - **Prune the turbo cache to what this run used** runs on push only. - **Save Turbo Cache** runs on push only, and only when `cache-hit != 'true'`, with a 5 min bound. The existing save of the pinned `@objectstack` build stays the last step. - Pull-request and merge-group runs restore the cache and never save it. - **`scripts/__tests__/check-action-ref-convention.test.ts`**: this test pins the exact list of `uses:` refs in `repo-gates.yml`. The new restore and save add two refs, so the list now has them, in file order. - **`content/docs/guide/ci-cd-pipeline.md`**: the Repo Gates section now names the cache and `scripts/report-turbo-cache.mjs`. `ci-cd-pipeline-doc.test.ts` requires the page to name every first-party command a workflow runs, and it has no exception list. ## `$SKILL_FILTER` / `$SNIPPET_FILTER` On this PR's base, the two derived filters add no tasks to the build. Checked with `turbo run build --dry=json`: `--filter='./packages/*'` alone gives 40 tasks, and adding both derived filters gives the same 40. That is also the task set `bundle-analysis` builds. The filters are derived on every run, so they could change it later. If one ever names a package outside `packages/`, that run gets fewer cache hits. It does not break the cache. ## How acceptance will be measured - **Baseline:** the latest `main` push run, 39921589107: the build step took 247 s and the job took 419 s. - **This PR's own run will miss the cache.** Pull requests restore from `main`'s entry, and no `repo-gates-` entry exists yet. The ≤90 s build step can only show up after a push to `main` has saved an entry. To read it: - check the `::notice` that "Report what the turbo cache replayed" writes on the first PR run after that push; - check that the push run's prune and save steps ran. - **Caveat on push runs:** push runs share the ref's concurrency group with `cancel-in-progress: true`, so a merge can cancel the previous merge's run before it saves. Of the 20 newest `main` push runs, 18 succeeded and 2 were cancelled, so the save should land on most merges. ## Judgment calls 1. **The restore is gated on the install outcome**, the same condition as the build it serves, so a run that will not build does not spend a restore. `bundle-analysis`'s restore has no `if:`, and the turbo cache policy test does not constrain this. 2. **The save's 5 min bound is not yet derived from this step's own runs**, because no run of this job has saved this cache. The workflow comment says so. The bound rests on the nearest measured save of the same 40-task entry, `bundle-analysis`'s 1 s save (objectui#7048's arithmetic), and the comment says to re-derive it from this step's own runs. Including the pinned build's 2 min save, this job's save bounds total 7 of its 30 minutes. ## Checks run - All 90 `scripts/__tests__/*.test.ts` files that read workflows, `repo-gates` or the CI/CD page pass. This includes `report-turbo-cache.test.ts` (each job has its own prefix and only one restore key, only push saves, the prune runs before the save, the report reads the summary) and `workflow-cache-save-bound.test.ts` (saves use the split form, run after the last command and stay within the job ceiling). Before the 2 pin updates, those 2 tests failed. - `check-governed-queue-guard --test` → GOVERNED. - `repo-gates.yml` parses with the `yaml` package. - These checks pass: `check-action-ref-convention`, `check-pre-install-import-graph`, `check-control-bytes`, `check-doc-links`, `check-new-cross-file-line-citations` (0 new) and `check-changeset-presence` (no changeset owed: no released package source changed). - actionlint is not installed and the repo has no wrapper for it, so it was not run. ## Checklist - [x] Adds no product-specific widget, dialog, hook or string (see AGENTS.md › Product-neutral renderer) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj Co-authored-by: Claude <noreply@anthropic.com>
1 parent f3044f7 commit 3688e5c

3 files changed

Lines changed: 101 additions & 2 deletions

File tree

‎.github/workflows/repo-gates.yml‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,43 @@ jobs:
399399
# word-split, so they stay unquoted. A derive step that failed contributes
400400
# nothing here and is red on its own; its gate then reports `unbuilt`
401401
# rather than judging a tree it cannot see.
402+
#
403+
# ── The build's turbo cache: this job's own, and only `main` writes it ──
404+
# (objectui#13348) Until this step the build above ran cold on every
405+
# pull request, push and queue build. The shape is `performance-budget.yml`'s
406+
# `bundle-analysis` cache (objectui#12276), which `report-turbo-cache.test.ts`
407+
# holds every `.turbo/cache` in `.github/workflows/` to: ONE restore key,
408+
# this job's own `repo-gates` prefix, so no other job's entry is ever
409+
# restored here; split restore/save (objectui#6577, objectui#7048), the
410+
# restore UNBOUNDED for the reason written there; pull-request and queue
411+
# runs restore and never save, so on a pull request's ref this key finds
412+
# nothing and falls through to `main`. The report, the prune and the save
413+
# are this job's last steps.
414+
#
415+
# It changes what the build REPLAYS, never what it builds: the filter set
416+
# on the build step is untouched, and the header's "never an unfiltered
417+
# `turbo run build`" holds as before. Gated on the install like the build
418+
# it serves, so a run that will not build does not spend a restore.
419+
- name: Restore Turbo Cache
420+
id: turbo-cache
421+
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
422+
uses: actions/cache/restore@v6
423+
with:
424+
path: .turbo/cache
425+
key: turbo-${{ runner.os }}-repo-gates-${{ github.sha }}
426+
restore-keys: |
427+
turbo-${{ runner.os }}-repo-gates-
428+
429+
# `TURBO_RUN_SUMMARY` makes turbo write its run summary to `.turbo/runs/`;
430+
# it changes nothing turbo runs or caches, and `Report what the turbo
431+
# cache replayed` below reads it (objectui#12276).
402432
- name: Build every package the gates below read
403433
id: build
404434
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
405435
env:
406436
SKILL_FILTER: ${{ steps.skill-filter.outputs.args }}
407437
SNIPPET_FILTER: ${{ steps.snippet-filter.outputs.args }}
438+
TURBO_RUN_SUMMARY: 'true'
408439
run: pnpm exec turbo run build --filter='./packages/*' $SKILL_FILTER $SNIPPET_FILTER
409440

410441
# The self-test runs BEFORE the corpus, and after the build because its
@@ -481,6 +512,66 @@ jobs:
481512
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
482513
run: pnpm check:readme-exports
483514

515+
# ── What the cache replayed, and only `main` writes it (objectui#13348) ──
516+
# `performance-budget.yml`'s two bookkeeping steps (objectui#12276), for
517+
# this job's cache. The report reads the summary the build step asked turbo
518+
# for and puts what the restored cache replayed, what re-ran and the
519+
# restored key on ONE `::notice` annotation, readable through the
520+
# check-runs API by anyone who cannot open this log. The prune deletes
521+
# every entry this run did not use, on `push` only -- the runs that save --
522+
# so `main`'s entry is exactly the current build outputs; pull-request and
523+
# queue runs restore and never save, because what they would save is
524+
# scoped to a ref no other pull request can read, and every build-sized
525+
# entry saved is one more a size-limited cache store can evict `main`'s for.
526+
#
527+
# `push` alone: this workflow has no `schedule`. Read before relying on it
528+
# (objectui#13348): the push concurrency group here is the ref with
529+
# `cancel-in-progress`, so a merge can cancel the previous merge's run, and
530+
# 18 of the 20 newest `main` push runs succeeded (2 cancelled) -- the save
531+
# lands on most merges.
532+
#
533+
# Bookkeeping after the last checking step, bounded and
534+
# `continue-on-error`. `timeout-minutes: 1` each: the script reads one run
535+
# summary and lists one directory (87 ms measured on objectui#12276); a
536+
# minute is several hundred times that.
537+
- name: Report what the turbo cache replayed
538+
if: ${{ !cancelled() }}
539+
timeout-minutes: 1
540+
continue-on-error: true
541+
env:
542+
RESTORED_CACHE_KEY: ${{ steps.turbo-cache.outputs.cache-matched-key }}
543+
run: node scripts/report-turbo-cache.mjs
544+
545+
- name: Prune the turbo cache to what this run used
546+
if: github.event_name == 'push'
547+
timeout-minutes: 1
548+
continue-on-error: true
549+
run: node scripts/report-turbo-cache.mjs --prune
550+
551+
# The bookkeeping half of the split documented at the restore step above,
552+
# placed after every checking step. `cache-hit != 'true'` skips an exact
553+
# primary-key hit; a `restore-keys` prefix match leaves it false and the
554+
# save runs; the implicit `success()` applies; same `path` and `key` as the
555+
# restore. Only `push` saves, after the prune above.
556+
#
557+
# `timeout-minutes: 5` is NOT yet derived from this site's own save: no run
558+
# of this job has saved this cache. What it rests on is the nearest
559+
# measured save of the same entry -- `bundle-analysis` builds the same
560+
# task set (`--filter='./packages/*'`; the two derived filters here add no
561+
# task on objectui#13348's base) and its save measured 1s (objectui#7048
562+
# arithmetic, `performance-budget.yml`). Re-derive it from this step's own
563+
# runs. With the pinned build's 2 below, this job's saves stay at 7 of 30.
564+
- name: Save Turbo Cache
565+
if: >-
566+
steps.turbo-cache.outputs.cache-hit != 'true'
567+
&& github.event_name == 'push'
568+
uses: actions/cache/save@v6
569+
timeout-minutes: 5
570+
continue-on-error: true
571+
with:
572+
path: .turbo/cache
573+
key: turbo-${{ runner.os }}-repo-gates-${{ github.sha }}
574+
484575
# The pinned @objectstack build, saved only when this job built it (a cache
485576
# miss) and whatever the verdict above was -- it does not depend on it.
486577
# Bookkeeping: bounded and non-fatal (objectui#6577, objectui#7048). The bound

‎content/docs/guide/ci-cd-pipeline.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,11 @@ import graph free of `node_modules`. The three gates that judge the *published*
636636
one build: `turbo run build` over every package under `packages/` (the README export check reads
637637
each package's declared type entry), in union with the closures the two snippet gates derive with
638638
`--build-filter`. ⛔ It is never an unfiltered workspace build, and a derived filter that names no
639-
package is refused at the step that derives it.
639+
package is refused at the step that derives it. That build restores this job's own turbo cache
640+
(key prefix `turbo-<os>-repo-gates-`, [#13348](https://github.com/objectstack-ai/objectui/issues/13348)):
641+
pull-request and queue runs restore and never save; a push saves it after pruning it to what the
642+
run used, and every run reports what it replayed — bookkeeping only, after the verdict —
643+
with `scripts/report-turbo-cache.mjs`.
640644

641645
The sections below are the fifteen gates, each under the name its step carries.
642646

‎scripts/__tests__/check-action-ref-convention.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,12 @@ describe('prose cannot be mistaken for a reference', () => {
268268
expect(parseRefs(source, 'repo-gates.yml').map((r: { ref: string }) => r.ref)).toEqual([
269269
'actions/checkout@v7',
270270
'actions/setup-node@v7',
271-
// The pinned @objectstack build's restore and save (objectui#12957).
271+
// In file order: the pinned @objectstack build's restore (objectui#12957),
272+
// the build's turbo cache restore and save (objectui#13348), then the
273+
// pinned build's save.
272274
'actions/cache/restore@v6',
275+
'actions/cache/restore@v6',
276+
'actions/cache/save@v6',
273277
'actions/cache/save@v6',
274278
]);
275279
});

0 commit comments

Comments
 (0)