mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
ci(xtask): pack shard archives in parallel with zstd level 1 (#18737)
Co-authored-by: skylar taylor <[email protected]>
This commit is contained in:
1 parent
5cc4259f1e
commit
3439ab7f29
1 file changed
+41
-10
+41
-10
@@ -588,6 +588,17 @@ fn nextest_list(o: &CiOptions, args: &[&str], record: bool) -> Result<serde_json
|
|||||||
serde_json::from_slice(&out).map_err(|e| format!("{what}: bad JSON: {e}"))
|
serde_json::from_slice(&out).map_err(|e| format!("{what}: bad JSON: {e}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Arguments for packing a single shard's nextest archive at fast zstd compression.
|
||||||
|
fn shard_archive_args(o: &CiOptions, shard: &shards::Shard, file: &Path) -> Vec<std::ffi::OsString> {
|
||||||
|
let mut args: Vec<std::ffi::OsString> = ["nextest", "archive", "--profile", "ci", "--zstd-level", "1"].into_iter().map(Into::into).collect();
|
||||||
|
args.extend(test_build_args(&o.exclude, o.corpus).into_iter().map(Into::into));
|
||||||
|
args.push("-E".into());
|
||||||
|
args.push(shard.archive_filter().into());
|
||||||
|
args.push("--archive-file".into());
|
||||||
|
args.push(file.as_os_str().to_owned());
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
/// The gate's build job with per-shard archives: builds the tests, lists them, plans which binaries
|
/// The gate's build job with per-shard archives: builds the tests, lists them, plans which binaries
|
||||||
/// (and which parts of the split ones) each shard runs, writes the plan into the target directory
|
/// (and which parts of the split ones) each shard runs, writes the plan into the target directory
|
||||||
/// (every archive carries it, .config/nextest.toml) and writes each shard's archive.
|
/// (every archive carries it, .config/nextest.toml) and writes each shard's archive.
|
||||||
@@ -616,17 +627,27 @@ fn build_shard_archives(o: &CiOptions, dir: &Path, name: &str, shards: usize, gp
|
|||||||
let plan_path = target.join(shards::PLAN_FILE);
|
let plan_path = target.join(shards::PLAN_FILE);
|
||||||
let json = serde_json::to_string_pretty(&plan).map_err(|e| format!("shard plan: {e}"))?;
|
let json = serde_json::to_string_pretty(&plan).map_err(|e| format!("shard plan: {e}"))?;
|
||||||
std::fs::write(&plan_path, json).map_err(|e| format!("{}: {e}", plan_path.display()))?;
|
std::fs::write(&plan_path, json).map_err(|e| format!("{}: {e}", plan_path.display()))?;
|
||||||
for (k, shard) in plan.shards.iter().enumerate() {
|
for k in 0..plan.shards.len() {
|
||||||
let file = dir.join((k + 1).to_string()).join(name);
|
|
||||||
std::fs::create_dir_all(dir.join((k + 1).to_string())).map_err(|e| format!("{}: {e}", dir.display()))?;
|
std::fs::create_dir_all(dir.join((k + 1).to_string())).map_err(|e| format!("{}: {e}", dir.display()))?;
|
||||||
let mut c = cargo();
|
}
|
||||||
c.args(["nextest", "archive", "--profile", "ci"])
|
let results: Vec<Result<(), String>> = std::thread::scope(|s| {
|
||||||
.args(test_build_args(&o.exclude, o.corpus))
|
let handles: Vec<_> = plan
|
||||||
.arg("-E")
|
.shards
|
||||||
.arg(shard.archive_filter())
|
.iter()
|
||||||
.arg("--archive-file")
|
.enumerate()
|
||||||
.arg(&file);
|
.map(|(k, shard)| {
|
||||||
run(c, &format!("cargo nextest archive (shard {}: {} binaries) --archive-file {}", k + 1, shard.binaries.len(), file.display()))?;
|
let file = dir.join((k + 1).to_string()).join(name);
|
||||||
|
s.spawn(move || {
|
||||||
|
let mut c = cargo();
|
||||||
|
c.args(shard_archive_args(o, shard, &file));
|
||||||
|
run(c, &format!("cargo nextest archive (shard {}: {} binaries) --archive-file {}", k + 1, shard.binaries.len(), file.display()))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
handles.into_iter().map(|h| h.join().unwrap_or_else(|_| Err("cargo nextest archive worker thread panicked".into()))).collect()
|
||||||
|
});
|
||||||
|
for result in results {
|
||||||
|
result?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -920,4 +941,14 @@ mod ci_tests {
|
|||||||
// The workspace's own group exists and parses.
|
// The workspace's own group exists and parses.
|
||||||
assert!(read_gpu_filter().unwrap().contains("package(photocraft-gpu)"));
|
assert!(read_gpu_filter().unwrap().contains("package(photocraft-gpu)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shard_archive_args_use_fast_zstd_and_shard_filter() {
|
||||||
|
let o = ci_from_args(&[], vec!["photocraft-web".into()]).unwrap().1;
|
||||||
|
let shard = shards::Shard { binaries: ["photocraft-geom".into()].into_iter().collect(), parts: Default::default(), seconds: 0.1 };
|
||||||
|
let args: Vec<String> = shard_archive_args(&o, &shard, Path::new("/tmp/1/a.tar.zst")).into_iter().map(|a| a.to_string_lossy().into_owned()).collect();
|
||||||
|
assert!(args.windows(2).any(|w| w == ["--zstd-level", "1"]));
|
||||||
|
assert!(args.windows(2).any(|w| w == ["--archive-file", "/tmp/1/a.tar.zst"]));
|
||||||
|
assert!(args.windows(2).any(|w| w == ["-E", "binary_id(=photocraft-geom)"]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user