diff --git a/ci/publish.rs b/ci/publish.rs index c27c6c4..1e62df6 100644 --- a/ci/publish.rs +++ b/ci/publish.rs @@ -11,7 +11,7 @@ use std::collections::HashMap; use std::env; use std::fs; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; +use std::process::{Command, Output, Stdio}; use std::thread; use std::time::Duration; @@ -277,19 +277,17 @@ fn publish(krate: &Crate) -> bool { // First make sure the crate isn't already published at this version. This // script may be re-run and there's no need to re-attempt previous work. - let output = Command::new("curl") - .arg(&format!("https://crates.io/api/v1/crates/{}", krate.name)) - .output() - .expect("failed to invoke `curl`"); - if output.status.success() - && String::from_utf8_lossy(&output.stdout) - .contains(&format!("\"newest_version\":\"{}\"", krate.version)) - { - println!( - "skip publish {} because {} is latest version", - krate.name, krate.version, - ); - return true; + match curl(&format!("https://crates.io/api/v1/crates/{}", krate.name)) { + Some(output) => { + if output.contains(&format!("\"newest_version\":\"{}\"", krate.version)) { + println!( + "skip publish {} because {} is latest version", + krate.name, krate.version, + ); + return true; + } + } + None => return false, } let status = Command::new("cargo") @@ -343,6 +341,21 @@ fn publish(krate: &Crate) -> bool { true } +fn curl(url: &str) -> Option { + let output = cmd_output( + Command::new("curl") + .arg("--user-agent") + .arg("bytecodealliance/wasm-component-ld auto-publish script") + .arg(url), + ); + if !output.status.success() { + println!("failed to curl: {}", output.status); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + return None; + } + Some(String::from_utf8_lossy(&output.stdout).into()) +} + // 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 @@ -397,3 +410,11 @@ fn verify(crates: &[Crate]) { .unwrap(); } } + +fn cmd_output(cmd: &mut Command) -> Output { + eprintln!("Running: `{:?}`", cmd); + match cmd.output() { + Ok(o) => o, + Err(e) => panic!("Failed to run `{:?}`: {}", cmd, e), + } +}