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.
This commit is contained in:
dotCooCoo committed 2026-11-30 05:32:36 -08:00
1 parent dcdbd3cc1b
commit 308befa8cf
2 files changed
+40 -1

No files matched your search

+13
View File
@@ -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
+27 -1
View File
@@ -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<String> = 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());
}
}