Skip to content

Commit 5466a8d

Browse files
committed
Wrap CLI commands with 'exec' helper
1 parent 11a6b08 commit 5466a8d

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

crates/xtask/src/publish.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::util::{get_crates, path_to_crates, Crate};
2-
use anyhow::{anyhow, Context, Result};
1+
use crate::util::{exec, get_crates, path_to_crates, Crate};
2+
use anyhow::{anyhow, Result};
33
use std::{process::Command, thread::sleep, time::Duration};
44
use structopt::StructOpt;
55

66
#[derive(Debug, StructOpt)]
77
#[structopt(name = "bump")]
88
pub struct PublishCommand {
99
/// Tag the current commit and push the tags to the default upstream; equivalent to `git tag
10-
/// v[version]` and `git push v[version]`.
10+
/// v[version] && git push origin v[version]`.
1111
#[structopt(long)]
1212
git: bool,
1313
/// Do not publish any crates; instead, simply print the actions that would have been taken.
@@ -43,13 +43,19 @@ impl PublishCommand {
4343
for krate in PUBLICATION_ORDER {
4444
println!("> publish {}", krate);
4545
if !self.dry_run {
46-
assert!(Command::new("cargo")
47-
.arg("publish")
48-
.current_dir(crates_dir.clone().join(krate))
49-
.arg("--no-verify")
50-
.status()
51-
.with_context(|| format!("failed to run cargo publish on '{}' crate", krate))?
52-
.success());
46+
let crate_dir = crates_dir.clone().join(krate);
47+
let exec_result = exec(
48+
Command::new("cargo")
49+
.arg("publish")
50+
.arg("--no-verify")
51+
.current_dir(&crate_dir),
52+
);
53+
54+
// We want to continue even if a crate does not publish: this allows us to re-run
55+
// the `publish` command if uploading one or more crates fails.
56+
if let Err(e) = exec_result {
57+
println!("Failed to publish crate {}, continuing:\n {}", krate, e);
58+
}
5359

5460
// Hopefully this gives crates.io enough time for subsequent publications to work.
5561
sleep(Duration::from_secs(20));
@@ -61,18 +67,8 @@ impl PublishCommand {
6167
if self.git {
6268
println!("> push Git tag: {}", tag);
6369
if !self.dry_run {
64-
assert!(Command::new("git")
65-
.arg("tag")
66-
.arg(&tag)
67-
.status()
68-
.with_context(|| format!("failed to run `git tag {}` command", &tag))?
69-
.success());
70-
assert!(Command::new("git")
71-
.arg("push")
72-
.arg(&tag)
73-
.status()
74-
.with_context(|| format!("failed to run `git push {}` command", &tag))?
75-
.success());
70+
exec(Command::new("git").arg("tag").arg(&tag))?;
71+
exec(Command::new("git").arg("push").arg("origin").arg(&tag))?;
7672
}
7773
}
7874

crates/xtask/src/util.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
use anyhow::{Context, Result};
1+
use anyhow::{anyhow, Context, Result};
22
use semver::Version;
3-
use std::fs;
43
use std::path::PathBuf;
4+
use std::{fs, process::Command};
55
use toml::Value;
66

7+
/// Convenience wrapper for executing commands.
8+
pub fn exec(command: &mut Command) -> Result<()> {
9+
let status = command.status()?;
10+
if status.success() {
11+
Ok(())
12+
} else {
13+
Err(anyhow!("failed to execute: {:?}", &command))
14+
}
15+
}
16+
717
/// Determine the path to the `crates` directory`.
818
pub fn path_to_crates() -> Result<PathBuf> {
919
Ok(PathBuf::from(file!())

0 commit comments

Comments
 (0)