@@ -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
@@ -325,19 +325,17 @@ fn publish(krate: &Crate) -> bool {
325
325
326
326
// First make sure the crate isn't already published at this version. This
327
327
// script may be re-run and there's no need to re-attempt previous work.
328
- let output = Command :: new ( "curl" )
329
- . arg ( & format ! ( "https://crates.io/api/v1/crates/{}" , krate. name) )
330
- . output ( )
331
- . expect ( "failed to invoke `curl`" ) ;
332
- if output. status . success ( )
333
- && String :: from_utf8_lossy ( & output. stdout )
334
- . contains ( & format ! ( "\" newest_version\" :\" {}\" " , krate. version) )
335
- {
336
- println ! (
337
- "skip publish {} because {} is latest version" ,
338
- krate. name, krate. version,
339
- ) ;
340
- return true ;
328
+ match curl ( & format ! ( "https://crates.io/api/v1/crates/{}" , krate. name) ) {
329
+ Some ( output) => {
330
+ if output. contains ( & format ! ( "\" newest_version\" :\" {}\" " , krate. version) ) {
331
+ println ! (
332
+ "skip publish {} because {} is latest version" ,
333
+ krate. name, krate. version,
334
+ ) ;
335
+ return true ;
336
+ }
337
+ }
338
+ None => return false ,
341
339
}
342
340
343
341
let status = Command :: new ( "cargo" )
@@ -354,21 +352,20 @@ fn publish(krate: &Crate) -> bool {
354
352
// After we've published then make sure that the `wasmtime-publish` group is
355
353
// added to this crate for future publications. If it's already present
356
354
// though we can skip the `cargo owner` modification.
357
- let output = Command :: new ( "curl" )
358
- . arg ( & format ! (
359
- "https://crates.io/api/v1/crates/{}/owners" ,
360
- krate. name
361
- ) )
362
- . output ( )
363
- . expect ( "failed to invoke `curl`" ) ;
364
- if output. status . success ( )
365
- && String :: from_utf8_lossy ( & output. stdout ) . contains ( "wasmtime-publish" )
366
- {
367
- println ! (
368
- "wasmtime-publish already listed as an owner of {}" ,
369
- krate. name
370
- ) ;
371
- return true ;
355
+ match curl ( & format ! (
356
+ "https://crates.io/api/v1/crates/{}/owners" ,
357
+ krate. name
358
+ ) ) {
359
+ Some ( output) => {
360
+ if output. contains ( "wasmtime-publish" ) {
361
+ println ! (
362
+ "wasmtime-publish already listed as an owner of {}" ,
363
+ krate. name
364
+ ) ;
365
+ return true ;
366
+ }
367
+ }
368
+ None => return false ,
372
369
}
373
370
374
371
// Note that the status is ignored here. This fails most of the time because
@@ -391,6 +388,21 @@ fn publish(krate: &Crate) -> bool {
391
388
true
392
389
}
393
390
391
+ fn curl ( url : & str ) -> Option < String > {
392
+ let output = cmd_output (
393
+ Command :: new ( "curl" )
394
+ . arg ( "--user-agent" )
395
+ . arg ( "bytecodealliance/wasm-tools auto-publish script" )
396
+ . arg ( url) ,
397
+ ) ;
398
+ if !output. status . success ( ) {
399
+ println ! ( "failed to curl: {}" , output. status) ;
400
+ println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
401
+ return None ;
402
+ }
403
+ Some ( String :: from_utf8_lossy ( & output. stdout ) . into ( ) )
404
+ }
405
+
394
406
// Verify the current tree is publish-able to crates.io. The intention here is
395
407
// that we'll run `cargo package` on everything which verifies the build as-if
396
408
// it were published to crates.io. This requires using an incrementally-built
@@ -445,3 +457,11 @@ fn verify(crates: &[Crate]) {
445
457
. unwrap ( ) ;
446
458
}
447
459
}
460
+
461
+ fn cmd_output ( cmd : & mut Command ) -> Output {
462
+ eprintln ! ( "Running: `{:?}`" , cmd) ;
463
+ match cmd. output ( ) {
464
+ Ok ( o) => o,
465
+ Err ( e) => panic ! ( "Failed to run `{:?}`: {}" , cmd, e) ,
466
+ }
467
+ }
0 commit comments