Skip to content

Commit 721fa95

Browse files
authored
Make auto-publish script more robust (#11090) (#11110)
* 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 57c9948 commit 721fa95

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
@@ -437,14 +437,13 @@ fn publish(krate: &Crate) -> bool {
437437

438438
// First make sure the crate isn't already published at this version. This
439439
// script may be re-run and there's no need to re-attempt previous work.
440-
let output = cmd_output(Command::new("curl").arg(&format!(
440+
let Some(output) = curl(&format!(
441441
"https://crates.io/api/v1/crates/{}/versions",
442442
krate.name
443-
)));
444-
if output.status.success()
445-
&& String::from_utf8_lossy(&output.stdout)
446-
.contains(&format!("\"num\":\"{}\"", krate.version))
447-
{
443+
)) else {
444+
return false;
445+
};
446+
if output.contains(&format!("\"num\":\"{}\"", krate.version)) {
448447
println!(
449448
"skip publish {} because {} is already published",
450449
krate.name, krate.version,
@@ -466,13 +465,13 @@ fn publish(krate: &Crate) -> bool {
466465
// After we've published then make sure that the `wasmtime-publish` group is
467466
// added to this crate for future publications. If it's already present
468467
// though we can skip the `cargo owner` modification.
469-
let output = cmd_output(Command::new("curl").arg(&format!(
468+
let Some(output) = curl(&format!(
470469
"https://crates.io/api/v1/crates/{}/owners",
471470
krate.name
472-
)));
473-
if output.status.success()
474-
&& String::from_utf8_lossy(&output.stdout).contains("wasmtime-publish")
475-
{
471+
)) else {
472+
return false;
473+
};
474+
if output.contains("wasmtime-publish") {
476475
println!(
477476
"wasmtime-publish already listed as an owner of {}",
478477
krate.name
@@ -494,6 +493,21 @@ fn publish(krate: &Crate) -> bool {
494493
true
495494
}
496495

496+
fn curl(url: &str) -> Option<String> {
497+
let output = cmd_output(
498+
Command::new("curl")
499+
.arg("--user-agent")
500+
.arg("bytecodealliance/wasmtime auto-publish script")
501+
.arg(url),
502+
);
503+
if !output.status.success() {
504+
println!("failed to curl: {}", output.status);
505+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
506+
return None;
507+
}
508+
Some(String::from_utf8_lossy(&output.stdout).into())
509+
}
510+
497511
// Verify the current tree is publish-able to crates.io. The intention here is
498512
// that we'll run `cargo package` on everything which verifies the build as-if
499513
// it were published to crates.io. This requires using an incrementally-built

0 commit comments

Comments
 (0)