@@ -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
@@ -310,19 +310,17 @@ fn publish(krate: &Crate) -> bool {
310
310
311
311
// First make sure the crate isn't already published at this version. This
312
312
// script may be re-run and there's no need to re-attempt previous work.
313
- let output = Command :: new ( "curl" )
314
- . arg ( & format ! ( "https://crates.io/api/v1/crates/{}" , krate. name) )
315
- . output ( )
316
- . expect ( "failed to invoke `curl`" ) ;
317
- if output. status . success ( )
318
- && String :: from_utf8_lossy ( & output. stdout )
319
- . contains ( & format ! ( "\" newest_version\" :\" {}\" " , krate. version) )
320
- {
321
- println ! (
322
- "skip publish {} because {} is latest version" ,
323
- krate. name, krate. version,
324
- ) ;
325
- return true ;
313
+ match curl ( & format ! ( "https://crates.io/api/v1/crates/{}" , krate. name) ) {
314
+ Some ( output) => {
315
+ if output. contains ( & format ! ( "\" newest_version\" :\" {}\" " , krate. version) ) {
316
+ println ! (
317
+ "skip publish {} because {} is latest version" ,
318
+ krate. name, krate. version,
319
+ ) ;
320
+ return true ;
321
+ }
322
+ }
323
+ None => return false ,
326
324
}
327
325
328
326
let status = Command :: new ( "cargo" )
@@ -339,21 +337,20 @@ fn publish(krate: &Crate) -> bool {
339
337
// After we've published then make sure that the `wasmtime-publish` group is
340
338
// added to this crate for future publications. If it's already present
341
339
// though we can skip the `cargo owner` modification.
342
- let output = Command :: new ( "curl" )
343
- . arg ( & format ! (
344
- "https://crates.io/api/v1/crates/{}/owners" ,
345
- krate. name
346
- ) )
347
- . output ( )
348
- . expect ( "failed to invoke `curl`" ) ;
349
- if output. status . success ( )
350
- && String :: from_utf8_lossy ( & output. stdout ) . contains ( "wasmtime-publish" )
351
- {
352
- println ! (
353
- "wasmtime-publish already listed as an owner of {}" ,
354
- krate. name
355
- ) ;
356
- return true ;
340
+ match curl ( & format ! (
341
+ "https://crates.io/api/v1/crates/{}/owners" ,
342
+ krate. name
343
+ ) ) {
344
+ Some ( output) => {
345
+ if output. contains ( "wasmtime-publish" ) {
346
+ println ! (
347
+ "wasmtime-publish already listed as an owner of {}" ,
348
+ krate. name
349
+ ) ;
350
+ return true ;
351
+ }
352
+ }
353
+ None => return false ,
357
354
}
358
355
359
356
// Note that the status is ignored here. This fails most of the time because
@@ -376,6 +373,21 @@ fn publish(krate: &Crate) -> bool {
376
373
true
377
374
}
378
375
376
+ fn curl ( url : & str ) -> Option < String > {
377
+ let output = cmd_output (
378
+ Command :: new ( "curl" )
379
+ . arg ( "--user-agent" )
380
+ . arg ( "bytecodealliance/wit-bindgen auto-publish script" )
381
+ . arg ( url) ,
382
+ ) ;
383
+ if !output. status . success ( ) {
384
+ println ! ( "failed to curl: {}" , output. status) ;
385
+ println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
386
+ return None ;
387
+ }
388
+ Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
389
+ }
390
+
379
391
// Verify the current tree is publish-able to crates.io. The intention here is
380
392
// that we'll run `cargo package` on everything which verifies the build as-if
381
393
// it were published to crates.io. This requires using an incrementally-built
@@ -430,3 +442,11 @@ fn verify(crates: &[Crate]) {
430
442
. unwrap ( ) ;
431
443
}
432
444
}
445
+
446
+ fn cmd_output ( cmd : & mut Command ) -> Output {
447
+ eprintln ! ( "Running: `{:?}`" , cmd) ;
448
+ match cmd. output ( ) {
449
+ Ok ( o) => o,
450
+ Err ( e) => panic ! ( "Failed to run `{:?}`: {}" , cmd, e) ,
451
+ }
452
+ }
0 commit comments