From 7a040c1f3bf5733f6526a7cf6b6e83b70f72c121 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 16:02:38 +0000 Subject: [PATCH] ci: the Workspace gate keeps compiled workspace crates on its Linux leg The Linux leg restores the newest rolling cache entry of the workspace crates (cache-workspace-crates), so a pull request rebuilds only the crates its change reaches. Each main run saves an entry of its own and cache-prune deletes the older ones; the midnight scheduled run builds from source and starts the entry afresh. gate.yml's cache-workspace-crates covers a whole call, so the macOS and Windows legs move to a call of their own with dependency-only entries. A select platforms job decides whether that call runs, since an empty leg list would fail it. To fit the 10 GB cache budget, the lint legs and the sonarcloud instrumented build keep no cache. --- .github/workflows/actions.lock | 10 ++- .github/workflows/sonarcloud.yml | 3 + .github/workflows/workspace.yml | 143 +++++++++++++++++++++++++------ scripts/test-workspace-tests.py | 15 +++- 4 files changed, 144 insertions(+), 27 deletions(-) diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index e78310f7f..5996d0d2f 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -108,7 +108,10 @@ workflows: - 'actions/checkout@v7.0.1' - 'step-security/dtolnay-rust-toolchain@v1.0.0' - 'step-security/harden-runner@v2.22.4' - '.github/workflows/workspace.yml': [] + '.github/workflows/workspace.yml': + - 'actions/checkout@v7.0.1' + - 'step-security/harden-runner@v2.22.4' + - 'storytold/craft-common-actions@d65d611f0ef67eaa94039351be5afce61102dbb0' dependencies: 'actions/cache@v6.1.0': ref: 'v6.1.0' @@ -150,3 +153,8 @@ dependencies: commit: 'sha1-76747d22a7567cc4438546a84f11bdf18e670ab8' owner_id: 88700172 repo_id: 1382753260 + 'storytold/craft-common-actions@d65d611f0ef67eaa94039351be5afce61102dbb0': + ref: 'main' + commit: 'sha1-d65d611f0ef67eaa94039351be5afce61102dbb0' + owner_id: 76897702 + repo_id: 1414429108 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e40c1b4bc..c03a3a076 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -20,6 +20,9 @@ jobs: uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main with: pdf-test-fonts: true + # The instrumented build runs without a dependency cache: its 1.2 GB entry does not fit the + # repository's 10 GB cache budget beside the Workspace gate's. It runs on main only. + build-cache: false # The codec and format code behind features that are off by default. Without these the # coverage build never compiles it, and new code there reads as untested. cargo-features: >- diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index ff1d7ff5a..e13d290a6 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -7,9 +7,10 @@ on: pull_request: workflow_dispatch: # A full run on main every 6 hours that is never cancelled, so the caches are saved while pushes - # to main cancel each other. + # to main cancel each other. The midnight run builds the Linux leg from source (`native`). schedule: - - cron: "17 */6 * * *" + - cron: "17 0 * * *" + - cron: "17 6,12,18 * * *" permissions: contents: read @@ -23,46 +24,73 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main' }} jobs: + # Whether this run needs the macOS and Windows legs. On a pull request they run only when it can + # change platform behaviour: a crate with platform cfg code or one that depends on it, the build + # setup, or a file outside the crates (craft-common-actions' select-platforms). The full-ci label + # runs them anyway from the next push or manual run; every other event runs them. + platforms: + name: select platforms + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + platform: ${{ steps.select.outputs.platform }} + steps: + - name: Harden runner + uses: step-security/harden-runner@v2.22.4 + with: + egress-policy: audit + # The merge commit and its first parent. + - uses: actions/checkout@v7.0.1 + if: github.event_name == 'pull_request' + with: + persist-credentials: false + fetch-depth: 2 + - id: select + uses: storytold/craft-common-actions/actions/select-platforms@d65d611f0ef67eaa94039351be5afce61102dbb0 + with: + os: '["ubuntu-latest","windows-latest","macos-latest"]' + select-os: '["windows-latest","macos-latest"]' + label: full-ci + + # The Linux leg keeps the compiled workspace crates between runs (`cache-workspace-crates`): each + # main run saves a rolling cache entry of its own, every run restores the newest one, and Cargo + # rebuilds only the crates a change reaches. `cache-prune` keeps the newest entry. The midnight + # scheduled run builds from source (`cold-build`) and starts the entry afresh. The macOS and + # Windows legs keep a dependency-only entry: their workspace crates would not fit the 10 GB cache + # budget beside Linux's. The lint legs keep no cache (`lint-cache: false`) for the same reason; a + # cold lint leg is still shorter than its gate leg. native: name: Workspace uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: - os: '["ubuntu-latest","windows-latest","macos-latest"]' - # On a pull request, macOS and Windows run only when it can change platform behaviour: a - # crate with platform cfg code or one that depends on it, the build setup, or a file outside - # the crates (craft-common-actions' select-platforms). The full-ci label runs them anyway - # from the next push or manual run; pushes to main always run every leg. - select-os: '["windows-latest","macos-latest"]' - timeout-minutes: 120 + os: '["ubuntu-latest"]' + cache-workspace-crates: true + cold-build: ${{ github.event.schedule == '17 0 * * *' }} + lint-cache: false + timeout-minutes: &timeout 120 # Every leg runs its tests with nextest, and its doctests with cargo test (.config/nextest.toml). - tools: cargo-nextest@0.9.150 + tools: &tools cargo-nextest@0.9.150 packages: mesa-vulkan-drivers libvulkan1 - craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 + craft-fonts-ref: &craft-fonts b076417b5880bd4154bd22f00695b1d28c6bea83 linux-env: WGPU_BACKEND=vulkan # Test binaries without debug info or symbols: about a third of the size, and a panic still # names its file and line. dev-strip: true - # No debuginfo on Windows: writing PDBs for every test binary is a large part of its link - # time. A panic still names its file and line; only backtrace frames lose theirs, and the - # Linux and macOS legs keep line tables. - windows-env: | - CRAFT_PRINT_REQUIRE_QUEUE=1 - CARGO_PROFILE_DEV_DEBUG=0 # The fuzz-style tests run a fraction of their cases here: every hostile-input hammer and # sweep 1/8 (craft-testkit's CRAFT_HOSTILE_DIVISOR), every proptest without its own case # count 64 cases instead of 256. nightly.yml runs them all in full. - env: | + env: &env | CRAFT_PRINT_REQUIRE_QUEUE=0 CRAFT_HOSTILE_DIVISOR=8 PROPTEST_CASES=64 - setup-command: bash scripts/ci-test-inputs.sh + setup-command: &setup bash scripts/ci-test-inputs.sh # The PhotoCraft corpora, keyed on the script that pins them: a hit skips the PhotoCraft # checkout and its xtask build (1:51 on Windows). - cache-paths: .test-inputs/photocraft/corpus - cache-key: photocraft-corpus - cache-key-files: scripts/ci-test-inputs.sh + cache-paths: &cache-paths .test-inputs/photocraft/corpus + cache-key: &cache-key photocraft-corpus + cache-key-files: &cache-key-files scripts/ci-test-inputs.sh # A `lint ()` leg beside each `gate ()` leg, so clippy is off the tests' critical path. - lint-command: | + lint-command: &lint | if [ "$RUNNER_OS" = Linux ]; then python3 scripts/test-workspace-concurrency.py python3 scripts/test-workspace-tests.py @@ -75,7 +103,7 @@ jobs: fi cargo clippy --workspace --all-targets --locked -- -D warnings cargo clippy --workspace --all-targets --all-features --locked -- -D warnings - command: | + command: &command | # The tests run once, with every feature, in parallel across test binaries; nextest skips # doctests, so `cargo test --doc` runs them. Examples are not built, except the two whose # tests run (stubicc, h264_h264enc_bench); clippy in the lint leg covers the rest. The default-feature compile is the lint leg's @@ -85,6 +113,34 @@ jobs: cargo nextest run -p craft-aep -p craft-video --all-features --locked --profile ci --example stubicc --example h264_h264enc_bench cargo test --workspace --doc --all-features --locked cargo nextest run -p craft-image-codecs -p craft-text --locked --profile ci --lib --bins --tests + + # The macOS and Windows legs, when `platforms` says this run needs them, with the Linux leg's + # inputs. + native-platforms: + name: Workspace + needs: platforms + if: needs.platforms.outputs.platform == 'true' + uses: storytold/craft-common-actions/.github/workflows/gate.yml@main + with: + os: '["windows-latest","macos-latest"]' + lint-cache: false + timeout-minutes: *timeout + tools: *tools + craft-fonts-ref: *craft-fonts + dev-strip: true + # No debuginfo on Windows: writing PDBs for every test binary is a large part of its link + # time. A panic still names its file and line; only backtrace frames lose theirs, and the + # Linux and macOS legs keep line tables. + windows-env: | + CRAFT_PRINT_REQUIRE_QUEUE=1 + CARGO_PROFILE_DEV_DEBUG=0 + env: *env + setup-command: *setup + cache-paths: *cache-paths + cache-key: *cache-key + cache-key-files: *cache-key-files + lint-command: *lint + command: *command windows-command: | powershell.exe -NoProfile -Command '$ErrorActionPreference = "Stop"; Start-Service Spooler; Add-PrinterDriver -Name "Generic / Text Only"' cargo nextest run --workspace --all-features --locked --profile ci --lib --bins --tests @@ -92,6 +148,45 @@ jobs: cargo test --workspace --doc --all-features --locked cargo nextest run -p craft-image-codecs -p craft-text --locked --profile ci --lib --bins --tests + # Each main run's Linux leg saves a rolling cache entry of its own (`cache-workspace-crates`), and + # every run restores only the newest. This deletes the older ones as soon as the Linux leg is + # done, instead of leaving them to the 10 GB budget's eviction, which would evict other entries + # too. The only job with `actions: write`; it checks out and runs nothing from the repository. + cache-prune: + name: cache prune + needs: native + if: ${{ !cancelled() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: write + steps: + - name: Harden runner + uses: step-security/harden-runner@v2.22.4 + with: + egress-policy: audit + - name: Delete all but the newest rolling entry of each job and runner + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + # `-rust---crates-----...`, newest first. + gh cache list --repo "$REPO" --ref refs/heads/main --limit 100 --sort created_at --order desc --json id,key \ + --jq '.[] | "\(.id) \(.key)"' > "$RUNNER_TEMP/caches" + declare -A kept + while read -r id key; do + [[ "$key" =~ ^.+-rust-[0-9a-f]{64}-(.+-crates-[A-Za-z_]+-[a-z0-9]+)-[0-9]+-[0-9]+- ]] || continue + entry=${BASH_REMATCH[1]} + if [ -n "${kept[$entry]:-}" ]; then + echo "delete $key" + gh cache delete "$id" --repo "$REPO" + else + kept[$entry]=1 + echo "keep $key" + fi + done < "$RUNNER_TEMP/caches" + msrv: name: Rust 1.95 uses: storytold/craft-common-actions/.github/workflows/gate.yml@main diff --git a/scripts/test-workspace-tests.py b/scripts/test-workspace-tests.py index a50d2370c..711c8f1cd 100644 --- a/scripts/test-workspace-tests.py +++ b/scripts/test-workspace-tests.py @@ -13,7 +13,9 @@ WORKFLOW = ROOT / ".github/workflows/workspace.yml" def block(text, name): - match = re.search(r"^ " + re.escape(name) + r": \|\n((?: .*\n|\n)+)", text, re.M) + # The Linux call names each shared block with a YAML anchor (`command: &command |`), and the + # macOS and Windows call refers to it, so this first block is the one every leg runs. + match = re.search(r"^ " + re.escape(name) + r": (?:&[\w-]+ )?\|\n((?: .*\n|\n)+)", text, re.M) if match is None: raise AssertionError(f"missing command block: {name}") return "\n".join(line[8:] for line in match[1].splitlines()) @@ -174,7 +176,16 @@ class WorkspaceTests(unittest.TestCase): def test_workflow_stays_shared_and_keeps_platform_gates(self): source = WORKFLOW.read_text() self.assertIn("uses: storytold/craft-common-actions/.github/workflows/gate.yml@main", source) - self.assertIn('os: \'["ubuntu-latest","windows-latest","macos-latest"]\'', source) + self.assertIn('os: \'["ubuntu-latest"]\'', source) + self.assertIn('os: \'["windows-latest","macos-latest"]\'', source) + self.assertIn("if: needs.platforms.outputs.platform == 'true'", source) + # The macOS and Windows legs run the Linux leg's blocks, not copies of them. + self.assertIn(" lint-command: &lint |\n", source) + self.assertIn(" command: &command |\n", source) + self.assertIn(" lint-command: *lint\n", source) + self.assertIn(" command: *command\n", source) + # Only the Linux leg keeps workspace crates; the cache budget has no room for the others. + self.assertEqual(source.count("cache-workspace-crates: true"), 1) self.assertIn(" msrv:", source) self.assertIn(" wasm:", source) self.assertIn("python3 scripts/test-workspace-tests.py", block(source, "lint-command"))