@@ -11,7 +11,7 @@ use std::collections::HashMap;
11
11
use std:: env;
12
12
use std:: fs;
13
13
use std:: path:: { Path , PathBuf } ;
14
- use std:: process:: { Command , Stdio } ;
14
+ use std:: process:: { Command , Output , Stdio } ;
15
15
use std:: thread;
16
16
use std:: time:: Duration ;
17
17
@@ -277,19 +277,17 @@ fn publish(krate: &Crate) -> bool {
277
277
278
278
// First make sure the crate isn't already published at this version. This
279
279
// 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 ,
293
291
}
294
292
295
293
let status = Command :: new ( "cargo" )
@@ -343,6 +341,21 @@ fn publish(krate: &Crate) -> bool {
343
341
true
344
342
}
345
343
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
+
346
359
// Verify the current tree is publish-able to crates.io. The intention here is
347
360
// that we'll run `cargo package` on everything which verifies the build as-if
348
361
// it were published to crates.io. This requires using an incrementally-built
@@ -397,3 +410,11 @@ fn verify(crates: &[Crate]) {
397
410
. unwrap ( ) ;
398
411
}
399
412
}
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