From 308befa8cfdbbddde8400cb3840f19a8a1fca811 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 05:32:36 -0800 Subject: [PATCH] CI: run only the test shards a pull request's changes reach The gate call sets select-tests and shard-members, so a pull request runs the test shards whose crates its changes reach (the crates that own or declare a read of a changed file, and every crate that depends on them) and always runs shard 6, the checks. Pushes to main, the nightly run and the full-ci label run all six shards. xtask's test ci_names_the_crates_of_every_shard_for_test_selection fails when the shard-members lines in ci.yml differ from GROUPS in xtask/src/shards.rs. --- .github/workflows/ci.yml | 13 +++++++++++++ xtask/src/shards.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0954b5c35c..4acf23c676 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,19 @@ jobs: test-shards: 6 shard-command: cargo xtask ci shard warm-command: cargo xtask ci warm + # A pull request runs only the test shards whose crates its changes reach: the crates that + # own a changed file or declare a read of it (`[package.metadata.craft] reads`), and every + # crate that depends on them. Shard 6 runs on every event. The `select legs` log lists the + # shards left out and why; pushes to main, the nightly run and the `full-ci` label run all + # six. `shard-members` names each shard's crates, as xtask/src/shards.rs › GROUPS does. + select-tests: true + shard-members: | + vectorcraft-ui-egui + vectorcraft-ui-egui + vectorcraft-engine + vectorcraft vectorcraft-web vectorcraft-cli vectorcraft-mcp xtask + (rest) + (always) # The dependency cache also keeps the compiled workspace crates and test executables, so a # pull request's shards rebuild only the crates its changes reach. Each main run's `cache # warm` leg saves a rolling entry of its own, every leg restores the newest one, and diff --git a/xtask/src/shards.rs b/xtask/src/shards.rs index 2a4ae4d927..261a27191e 100644 --- a/xtask/src/shards.rs +++ b/xtask/src/shards.rs @@ -70,7 +70,8 @@ pub static UI_EGUI: Split = Split { ], }; -/// The shards in order; `test-shards` in `.github/workflows/ci.yml` is its length. +/// The shards in order; `test-shards` in `.github/workflows/ci.yml` is its length, and its +/// `shard-members` names each shard's crates. pub const GROUPS: &[Group] = &[ Group::Part(&UI_EGUI, 1), Group::Part(&UI_EGUI, 2), @@ -586,4 +587,29 @@ geom v0.1.0 (/w/geom)| ["lib: features absent in shard 4, [default,synth] with the whole workspace"] ); } + + /// The lines of the `shard-members: |` block in `workflow`, trimmed. + fn shard_members(workflow: &str) -> Vec<&str> { + let mut lines = workflow.lines().skip_while(|l| l.trim() != "shard-members: |"); + let Some(key) = lines.next() else { return Vec::new() }; + let indent = |l: &str| l.len() - l.trim_start().len(); + lines.take_while(|l| !l.trim().is_empty() && indent(l) > indent(key)).map(str::trim).collect() + } + + #[test] + fn ci_names_the_crates_of_every_shard_for_test_selection() { + // The shared gate runs only the shards that test a crate a pull request reaches, by these lines. + let expected: Vec = GROUPS + .iter() + .map(|g| match g { + Group::Crates(crates) => crates.join(" "), + Group::Part(split, _) => split.crates.join(" "), + Group::Rest => "(rest)".to_owned(), + Group::Checks => "(always)".to_owned(), + }) + .collect(); + assert_eq!(shard_members(include_str!("../../.github/workflows/ci.yml")), expected, "shard-members in .github/workflows/ci.yml"); + assert_eq!(shard_members(" shard-members: |\n a b\n (rest)\n next: 1\n"), ["a b", "(rest)"]); + assert!(shard_members("test-shards: 6\n").is_empty()); + } }