ci: build the tests once per OS, keep compiled workspace crates, balance the shards

- Both gate calls build the tests once into a nextest archive (cargo xtask ci archive); the
  shards run it, and the build job runs the doctests after the upload.
- The Linux gate keeps the compiled workspace crates in a rolling cache entry
  (cache-workspace-crates). A nightly cold build is its safety net; gate-cache-prune keeps the
  newest entry. test (without heif) restores that entry.
- The shards split the tests with nextest's slice partition, which spreads the slow modules:
  on one main run's times the non-GPU shards go from 728/493/523 s (hash) to about 602/506/625 s.

Fixes #15702
This commit is contained in:
aiongg committed 2026-11-19 08:06:05 +00:00
1 parent c353bd0274
commit c9746558d7
5 files changed
+96 -46

No files matched your search

+78 -33
View File
@@ -2,10 +2,14 @@ name: CI
# Quality gates for every push to main and every pull request. The Linux and Windows tests run
# through the suite's shared gate workflow in craft-common-actions (`cargo xtask ci`, split over the
# gate's jobs); the test variant and the corpus, web and fuzz jobs are PhotoCraft's own.
# gate's jobs); the test variant and the corpus, web and fuzz jobs are PhotoCraft's own. Every night
# the Linux gate alone runs a cold build: the safety net for the workspace crates it keeps between
# runs (`cache-workspace-crates`), and a fresh start for that cache entry.
on:
push:
branches: [main]
schedule:
- cron: "11 3 * * *"
pull_request:
# `labeled` so that adding `full-ci` to an open PR starts a run with Windows in it.
types: [opened, synchronize, reopened, labeled]
@@ -70,7 +74,7 @@ concurrency:
jobs:
# Git dependencies come from github.com/storytold, and Cargo.lock is complete and up to date.
git-sources:
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
uses: storytold/craft-common-actions/.github/workflows/git-sources.yml@main
@@ -86,7 +90,7 @@ jobs:
# `windows_skip`: the platform-neutral packages whose Windows tests a pull request skips because nothing it
# changes reaches them (same script); empty on main and `full-ci`.
platforms:
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
timeout-minutes: 10
name: select platforms
runs-on: ubuntu-latest
@@ -145,17 +149,20 @@ jobs:
fi
# The Linux gate (craft-common-actions gate.yml). Its `lint` leg runs the checks that need no test
# build; four test shards each build the tests from the restored cache and run their share
# (scripts/ci-test-shard.sh). Shard 1 runs nextest's `gpu` group alone, on lavapipe, and fails on
# a skipped GPU comparison (scripts/ci-gpu-lavapipe.py); shards 2-4 split the other tests, and
# shard 2 runs the doctests. The `gpu` group is ~2400 test-seconds on 4 slots (~12 min with its
# slowest test, ~8 once the five slow UI tests are fixed); the other ~5900 test-seconds over 3
# shards are ~8 min each, so a fifth shard would not shorten the gate. Its rust-cache entry is
# the one `test (without heif)` restores.
# build. The `build` job builds the tests once into a nextest archive (`cargo xtask ci archive`),
# uploads it and then runs the doctests; four test shards download the archive and run their
# share (scripts/ci-test-shard.sh). Shard 1 runs nextest's `gpu` group alone, on lavapipe, and
# fails on a skipped GPU comparison (scripts/ci-gpu-lavapipe.py); shards 2-4 split the other
# tests. The `gpu` group is ~840 test-seconds on 4 slots (~3.5 min); the other ~6900
# test-seconds over 3 shards are ~8.5-10.5 min each.
# The build keeps the compiled workspace crates between runs (`cache-workspace-crates`), so a
# pull request rebuilds only the crates its changes reach. Each main run's build job saves a
# rolling entry of its own, which `test (without heif)` restores too; `gate-cache-prune` keeps
# the newest one.
gate:
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
uses: aiongg/craft-common-actions/.github/workflows/gate.yml@trial-build-once
uses: aiongg/craft-common-actions/.github/workflows/gate.yml@ci-build-once-test
with:
# egui/winit/rfd.
packages: >-
@@ -175,34 +182,32 @@ jobs:
LPDEST=photocraft-no-such-printer
CARGO_PROFILE_TEST_STRIP=symbols
timeout-minutes: 100
# On main, a `cache warm` leg builds xtask and the tests, as each shard does, and saves the
# dependency cache as soon as the build succeeds; the shards then only restore, so a failing
# test cannot keep the entry from being saved (craft-common-actions#270). The lint leg keeps
# its own entry.
warm-command: cargo xtask ci build
cache-workspace-crates: true
cold-build: ${{ github.event_name == 'schedule' }}
# fmt, egui-fork, clippy, layers, panel-commands, scorecard, the wasm32 check and the
# missing-translations report (`cargo xtask ci lint`, xtask/src/main.rs), and the CI scripts'
# own tests.
lint-command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && cargo xtask ci lint
archive-command: cargo xtask ci archive
after-archive-command: cargo xtask ci doctest
test-shards: 4
# The tests and panic_hunt with `--locked --features heif` (TEST_TARGETS in xtask/src/main.rs).
shard-command: bash scripts/ci-test-shard.sh --gpu-shard
# The Windows tests and Clippy on the same gate, when `platforms` says the run needs them: a
# `lint` leg runs Clippy, and six shards each build the tests and run their hash partition;
# shard 1 also runs the doctests. Windows runs the tests ~1.75x slower than Linux: ~55 min on
# one runner, ~9 min per shard. A seventh shard would not shorten the slowest one while its
# slowest test alone takes ~9.6 min (the shortcut-dispatch UI test). The browser apps are wasm
# targets, so their native tests are left out;
# pull requests also leave out photocraft-gpu and the platform-neutral packages nothing they change
# reaches (`windows_gpu`, `windows_skip`). The `cache warm` leg (main only) builds what main's
# build job builds.
# `lint` leg runs Clippy, the `build` job builds the tests once into a nextest archive and then
# runs the doctests, and six shards run their slice of the tests from the archive. Windows runs
# the tests ~1.75x slower than Linux: ~55 min on one runner, ~9 min per shard. A seventh shard
# would not shorten the slowest one while its slowest test alone takes ~9.6 min (the
# shortcut-dispatch UI test). The browser apps are wasm targets, so their native tests are left
# out; pull requests also leave out photocraft-gpu and the platform-neutral packages nothing they
# change reaches (`windows_gpu`, `windows_skip`). Windows keeps a dependency-only cache entry:
# its workspace crates would not fit the repository's cache budget beside Linux's.
windows:
needs: platforms
if: needs.platforms.outputs.windows == 'true'
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
uses: aiongg/craft-common-actions/.github/workflows/gate.yml@trial-build-once
uses: aiongg/craft-common-actions/.github/workflows/gate.yml@ci-build-once-test
with:
os: '["windows-latest"]'
# The all-language UI tests shape real Japanese, Chinese, Korean and Devanagari labels with
@@ -230,18 +235,57 @@ jobs:
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS=-Clink-arg=/OPT:NOICF -Clink-arg=/DEBUG:NONE
PHOTOCRAFT_CI_EXCLUDE=photocraft-web photocraft-web-boot ${{ needs.platforms.outputs.windows_gpu == 'false' && 'photocraft-gpu' || '' }} ${{ needs.platforms.outputs.windows_skip }}
timeout-minutes: 100
warm-command: cargo xtask ci build
lint-command: cargo xtask ci clippy
archive-command: cargo xtask ci archive
after-archive-command: cargo xtask ci doctest
test-shards: 6
shard-command: bash scripts/ci-test-shard.sh
# The Linux gate's build job saves a rolling cache entry of its own on every main and nightly run
# (`cache-workspace-crates`), about 3.8 GB, and every run restores only the newest. This deletes
# the older ones at once instead of leaving them to the 10 GB budget's eviction, which would
# evict other entries too.
gate-cache-prune:
needs: gate
if: ${{ !cancelled() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
timeout-minutes: 5
runs-on: ubuntu-24.04
permissions:
actions: write
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # 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
# `<version>-rust-<profile>-<job>-crates-<os>-<arch>-<run>-<attempt>-...`, newest first.
gh cache list --repo "$REPO" --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"
# The same codecs without the optional decoder: HEIC must stay a clear "not in this build" error
# for distributors who leave it out. Runs beside the gate and restores the gate's dependency
# cache without saving one: the dependencies are the same, and the 10 GB cache budget is tight
# (#2688).
# for distributors who leave it out. Runs beside the gate and restores the gate's newest rolling
# cache entry without saving one: the dependencies are the same, and the 10 GB cache budget is
# tight (#2688). Its sources keep their checkout mtimes, so the workspace crates it builds are
# rebuilt.
test-without-heif:
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
timeout-minutes: 60
name: test (without heif)
# The gate's runner: its cache entry is keyed on the OS.
@@ -279,11 +323,12 @@ jobs:
# The gate's own key (the shared action computes it), restore only. The toolchain action
# exports CARGO_HOME, which the gate's legs do not have; align-environment leaves it out of
# the key.
- uses: storytold/craft-common-actions/actions/rust-cache@main
# the cache paths.
- uses: aiongg/craft-common-actions/actions/rust-cache@ci-build-once-test
with:
cache-version: v2
job: gate
cache-workspace-crates: "true"
align-environment: "true"
- uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
@@ -294,7 +339,7 @@ jobs:
run: cargo nextest run -p photocraft-io --locked --profile ci
corpus:
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
if: github.event_name != 'schedule' && (github.event.action != 'labeled' || github.event.label.name == 'full-ci')
timeout-minutes: 30
# Real-file corpus tests (cargo feature `corpus`), on every PR and on main. The corpora are
# pinned in xtask/src/corpus_pins.rs and sha256-verified (xtask/*.sha256) after both a cache
+1 -1
View File
@@ -114,7 +114,7 @@ the opted-in test; an unset variable leaves the ordinary behavior tests availabl
After review, remove only the two generated PNGs and their owned temporary directory. The same
Rust test and variable work on Windows with the native shell's environment-variable syntax.
**GPU tests without a GPU.** Linux CI uses the shared `craft-common-actions` gate with Mesa's Vulkan driver installed. The gate builds the tests once into a nextest archive (`cargo xtask ci archive`) and runs them in shards from it (`cargo xtask ci tests`). One shard runs the configured `gpu` group alone, through `python3 scripts/ci-gpu-lavapipe.py`, with `WGPU_BACKEND=vulkan` and the lavapipe ICD explicitly selected; the other shards split the remaining tests. The script requires Vulkan parity evidence in that shard's output and rejects authored skips, except the documented software-adapter timing exceptions. xtask reads the group's filter from `.config/nextest.toml`, so no second filter needs maintaining. To run locally on Linux, install `mesa-vulkan-drivers libvulkan1`, build an archive and run `python3 scripts/ci-gpu-lavapipe.py <extracted>/target/debug/xtask ci tests --from <extracted> --gpu` as the gate's shard command in `.github/workflows/ci.yml` does. Windows uses WARP; this check does not certify Windows skip coverage.
**GPU tests without a GPU.** Linux CI uses the shared `craft-common-actions` gate with Mesa's Vulkan driver installed. The gate builds the tests once into a nextest archive (`cargo xtask ci archive`) and runs them in shards from it (`cargo xtask ci tests`). One shard runs the configured `gpu` group alone, through `python3 scripts/ci-gpu-lavapipe.py`, with `WGPU_BACKEND=vulkan` and the lavapipe ICD explicitly selected; the other shards split the remaining tests. The script requires Vulkan parity evidence in that shard's output and rejects authored skips, except the documented software-adapter timing exceptions. xtask reads the group's filter from `.config/nextest.toml`, so no second filter needs maintaining. To run locally on Linux, install `mesa-vulkan-drivers libvulkan1`, build an archive and run `python3 scripts/ci-gpu-lavapipe.py <extracted>/target/debug/xtask ci tests --from <extracted> --gpu` as `scripts/ci-test-shard.sh` does. Windows uses WARP; this check does not certify Windows skip coverage.
## Fonts (craft-fonts)
+1 -1
View File
@@ -2,7 +2,7 @@
"""Run a command with wgpu on lavapipe, and fail if a GPU comparison in its output was skipped.
The Linux gate runs nextest's `gpu` test group in a shard of its own through this script
(`ci-gpu-lavapipe.py <xtask> ci tests --from <dir> --gpu`, .github/workflows/ci.yml): every wgpu
(`ci-gpu-lavapipe.py <xtask> ci tests --from <dir> --gpu`, scripts/ci-test-shard.sh): every wgpu
device in the run is Vulkan on Mesa's CPU rasterizer, each test's output is shown, and the output
is checked here for authored skips and for the parity tests' Vulkan backend line.
+10 -5
View File
@@ -2,10 +2,15 @@
# One shard of the gate's tests: the gate's `shard-command` (.github/workflows/ci.yml). The gate's
# build job wrote a nextest archive of the tests with `cargo xtask ci archive`, and the archive
# carries that xtask binary (.config/nextest.toml), so the shard extracts it and runs the test steps
# with `xtask ci tests` without building anything. The gate sets NEXTEST_ARCHIVE_FILE, GATE_SHARD,
# GATE_SHARDS and NEXTEST_PARTITION.
# with `xtask ci tests` without building anything. The gate sets NEXTEST_ARCHIVE_FILE, GATE_SHARD
# and GATE_SHARDS.
#
# ci-test-shard.sh the shard runs its hash partition of every test
# The shards split the tests with nextest's `slice` partition (round-robin over every test of every
# binary). Test times are heavy-tailed and cluster in a few modules: on the times of a main run
# (#15702), a three-way `hash` split of the non-GPU tests ran 728, 493 and 523 s, and `slice`
# would run them in about 602, 506 and 625 s.
#
# ci-test-shard.sh the shard runs its slice of every test
# ci-test-shard.sh --gpu-shard shard 1 runs nextest's `gpu` group alone on lavapipe, checked by
# scripts/ci-gpu-lavapipe.py; the other shards split the other tests
set -euo pipefail
@@ -17,7 +22,7 @@ xtask=("$archive/target/debug/xtask" ci tests --from "$archive")
case "$(uname -s)" in MINGW* | MSYS* | CYGWIN*) xtask=("$archive/target/debug/xtask.exe" ci tests --from "$archive") ;; esac
case "${1:-}" in
"") exec "${xtask[@]}" ;;
"") NEXTEST_PARTITION="slice:$GATE_SHARD/$GATE_SHARDS" exec "${xtask[@]}" ;;
--gpu-shard)
if [ "$GATE_SHARDS" -lt 2 ]; then
echo "::error::--gpu-shard needs at least two shards, got $GATE_SHARDS"
@@ -26,7 +31,7 @@ case "${1:-}" in
if [ "$GATE_SHARD" = 1 ]; then
exec python3 scripts/ci-gpu-lavapipe.py "${xtask[@]}" --gpu
fi
NEXTEST_PARTITION="hash:$((GATE_SHARD - 1))/$((GATE_SHARDS - 1))" exec "${xtask[@]}" --no-gpu
NEXTEST_PARTITION="slice:$((GATE_SHARD - 1))/$((GATE_SHARDS - 1))" exec "${xtask[@]}" --no-gpu
;;
*)
echo "usage: $0 [--gpu-shard]" >&2
+6 -6
View File
@@ -40,12 +40,12 @@ commands:
tests (nextest --profile ci), panic_hunt, doctests, wasm and the i18n-report, with --locked
--features heif (stops at first failure). The gate splits it over its jobs: `lint` runs the
steps that need no test build; `archive` builds the tests into the nextest archive at
$NEXTEST_ARCHIVE_FILE and runs the doctests; `tests --from <dir>` runs the tests from that archive
$NEXTEST_ARCHIVE_FILE (the gate's build job, which then runs `doctest`); `tests --from <dir>` runs the tests from that archive
extracted to <dir> (without --from it builds them); `tests` runs the tests and panic_hunt on the partition in
$NEXTEST_PARTITION (`--gpu`: all of nextest's gpu test group, whatever the partition, each
test's output shown;
`--no-gpu`: every other test); `doctest` runs the doctests; `build` only builds what `tests`
builds (the cache warm-up). $PHOTOCRAFT_CI_EXCLUDE (packages separated by spaces) leaves
builds. $PHOTOCRAFT_CI_EXCLUDE (packages separated by spaces) leaves
packages out of the test build and the doctests
corpus [--all | --pngsuite | --psd | --psd-tools | --pixls | --atn | --photoshop | --gimp] [--local] [--update-manifest]
show where test corpora live and their pins (xtask/src/corpus_pins.rs), or fetch
@@ -265,7 +265,7 @@ enum Part {
Lint,
/// The tests, which the gate splits over its shards (`ci tests`).
Test,
/// The doctests, which the gate runs in one shard (`ci doctest`).
/// The doctests, which the gate's build job runs once the archive is uploaded (`ci doctest`).
Doc,
}
@@ -518,13 +518,13 @@ fn ci_from_args(args: &[&str], exclude: Vec<String>) -> Result<(CiPlan, CiOption
options.build_only = true;
&[Part::Test]
}
// The gate's build job: the tests into the archive at $NEXTEST_ARCHIVE_FILE (which also
// carries this xtask, .config/nextest.toml), and the doctests, which need the rlibs.
// The gate's build job: the tests into the archive at $NEXTEST_ARCHIVE_FILE, which also
// carries this xtask (.config/nextest.toml).
Some("archive") => {
let file = std::env::var_os("NEXTEST_ARCHIVE_FILE").ok_or("ci archive: set NEXTEST_ARCHIVE_FILE to the archive to write")?;
options.archive = Some(file.into());
options.build_only = true;
&[Part::Test, Part::Doc]
&[Part::Test]
}
Some("tests") => {
options.partition = tests_partition(options.selection, std::env::var("NEXTEST_PARTITION").ok());