Skip to content

Commit bc0a785

Browse files
authored
Update publish script (#2249)
Pull in some changes from Wasmtime * Print curl errors * Use a custom user agent
1 parent 78f9dc8 commit bc0a785

File tree

1 file changed

+49
-29
lines changed

1 file changed

+49
-29
lines changed

ci/publish.rs

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111
use std::env;
1212
use std::fs;
1313
use std::path::{Path, PathBuf};
14-
use std::process::{Command, Stdio};
14+
use std::process::{Command, Output, Stdio};
1515
use std::thread;
1616
use std::time::Duration;
1717

@@ -325,19 +325,17 @@ fn publish(krate: &Crate) -> bool {
325325

326326
// First make sure the crate isn't already published at this version. This
327327
// script may be re-run and there's no need to re-attempt previous work.
328-
let output = Command::new("curl")
329-
.arg(&format!("https://crates.io/api/v1/crates/{}", krate.name))
330-
.output()
331-
.expect("failed to invoke `curl`");
332-
if output.status.success()
333-
&& String::from_utf8_lossy(&output.stdout)
334-
.contains(&format!("\"newest_version\":\"{}\"", krate.version))
335-
{
336-
println!(
337-
"skip publish {} because {} is latest version",
338-
krate.name, krate.version,
339-
);
340-
return true;
328+
match curl(&format!("https://crates.io/api/v1/crates/{}", krate.name)) {
329+
Some(output) => {
330+
if output.contains(&format!("\"newest_version\":\"{}\"", krate.version)) {
331+
println!(
332+
"skip publish {} because {} is latest version",
333+
krate.name, krate.version,
334+
);
335+
return true;
336+
}
337+
}
338+
None => return false,
341339
}
342340

343341
let status = Command::new("cargo")
@@ -354,21 +352,20 @@ fn publish(krate: &Crate) -> bool {
354352
// After we've published then make sure that the `wasmtime-publish` group is
355353
// added to this crate for future publications. If it's already present
356354
// though we can skip the `cargo owner` modification.
357-
let output = Command::new("curl")
358-
.arg(&format!(
359-
"https://crates.io/api/v1/crates/{}/owners",
360-
krate.name
361-
))
362-
.output()
363-
.expect("failed to invoke `curl`");
364-
if output.status.success()
365-
&& String::from_utf8_lossy(&output.stdout).contains("wasmtime-publish")
366-
{
367-
println!(
368-
"wasmtime-publish already listed as an owner of {}",
369-
krate.name
370-
);
371-
return true;
355+
match curl(&format!(
356+
"https://crates.io/api/v1/crates/{}/owners",
357+
krate.name
358+
)) {
359+
Some(output) => {
360+
if output.contains("wasmtime-publish") {
361+
println!(
362+
"wasmtime-publish already listed as an owner of {}",
363+
krate.name
364+
);
365+
return true;
366+
}
367+
}
368+
None => return false,
372369
}
373370

374371
// Note that the status is ignored here. This fails most of the time because
@@ -391,6 +388,21 @@ fn publish(krate: &Crate) -> bool {
391388
true
392389
}
393390

391+
fn curl(url: &str) -> Option<String> {
392+
let output = cmd_output(
393+
Command::new("curl")
394+
.arg("--user-agent")
395+
.arg("bytecodealliance/wasm-tools auto-publish script")
396+
.arg(url),
397+
);
398+
if !output.status.success() {
399+
println!("failed to curl: {}", output.status);
400+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
401+
return None;
402+
}
403+
Some(String::from_utf8_lossy(&output.stdout).into())
404+
}
405+
394406
// Verify the current tree is publish-able to crates.io. The intention here is
395407
// that we'll run `cargo package` on everything which verifies the build as-if
396408
// it were published to crates.io. This requires using an incrementally-built
@@ -445,3 +457,11 @@ fn verify(crates: &[Crate]) {
445457
.unwrap();
446458
}
447459
}
460+
461+
fn cmd_output(cmd: &mut Command) -> Output {
462+
eprintln!("Running: `{:?}`", cmd);
463+
match cmd.output() {
464+
Ok(o) => o,
465+
Err(e) => panic!("Failed to run `{:?}`: {}", cmd, e),
466+
}
467+
}

0 commit comments

Comments
 (0)