Skip to content

Commit 8f513c8

Browse files
authored
Improve publish script (#67)
* Improve publish script Pulling in some Wasmtime changes * Update user agent
1 parent 527aa22 commit 8f513c8

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

ci/publish.rs

Lines changed: 35 additions & 14 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

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

278278
// First make sure the crate isn't already published at this version. This
279279
// script may be re-run and there's no need to re-attempt previous work.
280-
let output = Command::new("curl")
281-
.arg(&format!("https://crates.io/api/v1/crates/{}", krate.name))
282-
.output()
283-
.expect("failed to invoke `curl`");
284-
if output.status.success()
285-
&& String::from_utf8_lossy(&output.stdout)
286-
.contains(&format!("\"newest_version\":\"{}\"", krate.version))
287-
{
288-
println!(
289-
"skip publish {} because {} is latest version",
290-
krate.name, krate.version,
291-
);
292-
return true;
280+
match curl(&format!("https://crates.io/api/v1/crates/{}", krate.name)) {
281+
Some(output) => {
282+
if output.contains(&format!("\"newest_version\":\"{}\"", krate.version)) {
283+
println!(
284+
"skip publish {} because {} is latest version",
285+
krate.name, krate.version,
286+
);
287+
return true;
288+
}
289+
}
290+
None => return false,
293291
}
294292

295293
let status = Command::new("cargo")
@@ -343,6 +341,21 @@ fn publish(krate: &Crate) -> bool {
343341
true
344342
}
345343

344+
fn curl(url: &str) -> Option<String> {
345+
let output = cmd_output(
346+
Command::new("curl")
347+
.arg("--user-agent")
348+
.arg("bytecodealliance/wasm-component-ld auto-publish script")
349+
.arg(url),
350+
);
351+
if !output.status.success() {
352+
println!("failed to curl: {}", output.status);
353+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
354+
return None;
355+
}
356+
Some(String::from_utf8_lossy(&output.stdout).into())
357+
}
358+
346359
// Verify the current tree is publish-able to crates.io. The intention here is
347360
// that we'll run `cargo package` on everything which verifies the build as-if
348361
// it were published to crates.io. This requires using an incrementally-built
@@ -397,3 +410,11 @@ fn verify(crates: &[Crate]) {
397410
.unwrap();
398411
}
399412
}
413+
414+
fn cmd_output(cmd: &mut Command) -> Output {
415+
eprintln!("Running: `{:?}`", cmd);
416+
match cmd.output() {
417+
Ok(o) => o,
418+
Err(e) => panic!("Failed to run `{:?}`: {}", cmd, e),
419+
}
420+
}

0 commit comments

Comments
 (0)