MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / verify

Function verify

ci/publish.rs:340–429  ·  view source on GitHub ↗

Verify the current tree is publish-able to crates.io. The intention here is that we'll run `cargo package` on everything which verifies the build as-if it were published to crates.io. This requires using an incrementally-built directory registry generated from `cargo vendor` because the versions referenced from `Cargo.toml` may not exist on crates.io.

(crates: &[Crate])

Source from the content-addressed store, hash-verified

338// directory registry generated from `cargo vendor` because the versions
339// referenced from `Cargo.toml` may not exist on crates.io.
340fn verify(crates: &[Crate]) {
341 drop(fs::remove_dir_all(".cargo"));
342 drop(fs::remove_dir_all("vendor"));
343 let vendor = Command::new("cargo")
344 .arg("vendor")
345 .stderr(Stdio::inherit())
346 .output()
347 .unwrap();
348 assert!(vendor.status.success());
349
350 fs::create_dir_all(".cargo").unwrap();
351 fs::write(".cargo/config.toml", vendor.stdout).unwrap();
352
353 for krate in crates {
354 if !krate.publish {
355 continue;
356 }
357 verify_crates_io(&krate);
358 verify_and_vendor(&krate);
359 }
360
361 fn verify_and_vendor(krate: &Crate) {
362 let mut cmd = Command::new("cargo");
363 cmd.arg("package")
364 .arg("--allow-dirty")
365 .arg("--manifest-path")
366 .arg(&krate.manifest)
367 .env("CARGO_TARGET_DIR", "./target");
368 let status = cmd.status().unwrap();
369 assert!(status.success(), "failed to verify {:?}", &krate.manifest);
370 let tar = Command::new("tar")
371 .arg("xf")
372 .arg(format!(
373 "../target/package/{}-{}.crate",
374 krate.name, krate.version
375 ))
376 .current_dir("./vendor")
377 .status()
378 .unwrap();
379 assert!(tar.success());
380 fs::write(
381 format!(
382 "./vendor/{}-{}/.cargo-checksum.json",
383 krate.name, krate.version
384 ),
385 "{\"files\":{}}",
386 )
387 .unwrap();
388 }
389
390 fn verify_crates_io(krate: &Crate) {
391 let name = &krate.name;
392 let Some(owners) = curl(&format!("https://crates.io/api/v1/crates/{name}/owners")) else {
393 panic!(
394 "
395failed to get owners for {name}
396
397If this crate does not exist on crates.io yet please ping wstd maintainers

Callers 1

mainFunction · 0.85

Calls 2

verify_crates_ioFunction · 0.85
verify_and_vendorFunction · 0.85

Tested by

no test coverage detected