| 435 | } |
| 436 | |
| 437 | fn publish(krate: &Crate) -> bool { |
| 438 | if !krate.publish { |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | // First make sure the crate isn't already published at this version. This |
| 443 | // script may be re-run and there's no need to re-attempt previous work. |
| 444 | let Some(output) = curl(&format!( |
| 445 | "https://crates.io/api/v1/crates/{}/versions", |
| 446 | krate.name |
| 447 | )) else { |
| 448 | return false; |
| 449 | }; |
| 450 | if output.contains(&format!("\"num\":\"{}\"", krate.version)) { |
| 451 | println!( |
| 452 | "skip publish {} because {} is already published", |
| 453 | krate.name, krate.version, |
| 454 | ); |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | let status = cmd_status( |
| 459 | Command::new("cargo") |
| 460 | .arg("publish") |
| 461 | .current_dir(krate.manifest.parent().unwrap()) |
| 462 | .arg("--no-verify"), |
| 463 | ); |
| 464 | if !status.success() { |
| 465 | println!("FAIL: failed to publish `{}`: {}", krate.name, status); |
| 466 | return false; |
| 467 | } |
| 468 | |
| 469 | true |
| 470 | } |
| 471 | |
| 472 | fn curl(url: &str) -> Option<String> { |
| 473 | let output = cmd_output( |