Skip to content

Commit e7198a3

Browse files
authored
Make auto-publish script more robust (#11090) (#11111)
* Make auto-publish script more robust * Add a helper to run `curl` and get the output * Print an error if `curl` fails to help diagnose what went wrong in the future * Pass a custom `--user-agent` which is requested by crates.io's [data access policy](https://crates.io/data-access). * Don't continue publishing if `curl` fails
1 parent 3349bbe commit e7198a3

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

scripts/publish.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,13 @@ fn publish(krate: &Crate) -> bool {
426426

427427
// First make sure the crate isn't already published at this version. This
428428
// script may be re-run and there's no need to re-attempt previous work.
429-
let output = cmd_output(Command::new("curl").arg(&format!(
429+
let Some(output) = curl(&format!(
430430
"https://crates.io/api/v1/crates/{}/versions",
431431
krate.name
432-
)));
433-
if output.status.success()
434-
&& String::from_utf8_lossy(&output.stdout)
435-
.contains(&format!("\"num\":\"{}\"", krate.version))
436-
{
432+
)) else {
433+
return false;
434+
};
435+
if output.contains(&format!("\"num\":\"{}\"", krate.version)) {
437436
println!(
438437
"skip publish {} because {} is already published",
439438
krate.name, krate.version,
@@ -455,13 +454,13 @@ fn publish(krate: &Crate) -> bool {
455454
// After we've published then make sure that the `wasmtime-publish` group is
456455
// added to this crate for future publications. If it's already present
457456
// though we can skip the `cargo owner` modification.
458-
let output = cmd_output(Command::new("curl").arg(&format!(
457+
let Some(output) = curl(&format!(
459458
"https://crates.io/api/v1/crates/{}/owners",
460459
krate.name
461-
)));
462-
if output.status.success()
463-
&& String::from_utf8_lossy(&output.stdout).contains("wasmtime-publish")
464-
{
460+
)) else {
461+
return false;
462+
};
463+
if output.contains("wasmtime-publish") {
465464
println!(
466465
"wasmtime-publish already listed as an owner of {}",
467466
krate.name
@@ -483,6 +482,21 @@ fn publish(krate: &Crate) -> bool {
483482
true
484483
}
485484

485+
fn curl(url: &str) -> Option<String> {
486+
let output = cmd_output(
487+
Command::new("curl")
488+
.arg("--user-agent")
489+
.arg("bytecodealliance/wasmtime auto-publish script")
490+
.arg(url),
491+
);
492+
if !output.status.success() {
493+
println!("failed to curl: {}", output.status);
494+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
495+
return None;
496+
}
497+
Some(String::from_utf8_lossy(&output.stdout).into())
498+
}
499+
486500
// Verify the current tree is publish-able to crates.io. The intention here is
487501
// that we'll run `cargo package` on everything which verifies the build as-if
488502
// it were published to crates.io. This requires using an incrementally-built

0 commit comments

Comments
 (0)