Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions ci/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -343,6 +341,21 @@ fn publish(krate: &Crate) -> bool {
true
}

fn curl(url: &str) -> Option<String> {
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
Expand Down Expand Up @@ -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),
}
}