Skip to content

Commit 597c0c8

Browse files
authored
Make auto-publish script more robust (#11090) (#11108)
* 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 f6cd545 commit 597c0c8

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

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

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

0 commit comments

Comments
 (0)