summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-05 11:47:03 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-05 11:47:03 +0300
commit19cb8fcd22e9d2bc240cbd2b23efa2e19cf7ea52 (patch)
tree9b3e746ba6d523c080f0f40b5c0798f7e9326da5 /src
parent62e5bf8eca44deec7f45bb697ee98298b8abd219 (diff)
downloadbumper-rs-19cb8fcd22e9d2bc240cbd2b23efa2e19cf7ea52.tar.gz
feat: update Cargo.lock int Rust projects
If we update Cargo.toml, but not Cargo.lock, and Cargo.lock is in git, when cargo publish will refuse to publish, because the files are out of sync.
Diffstat (limited to 'src')
-rw-r--r--src/errors.rs6
-rw-r--r--src/rust.rs17
2 files changed, 23 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 6ea498d..bd09eba 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -43,4 +43,10 @@ pub enum BumperError {
#[error("dch failed in {0}: {1}")]
Dch(PathBuf, String),
+
+ #[error("Failed to run cargo in {0}: {1}")]
+ CargoInvoke(PathBuf, #[source] std::io::Error),
+
+ #[error("cargo failed in {0}: {1}")]
+ Cargo(PathBuf, String),
}
diff --git a/src/rust.rs b/src/rust.rs
index 56778b1..10dc1a1 100644
--- a/src/rust.rs
+++ b/src/rust.rs
@@ -2,6 +2,7 @@ use crate::errors::BumperError;
use cargo_edit::Manifest;
use log::{debug, info};
use std::path::{Path, PathBuf};
+use std::process::Command;
use toml_edit::{Item, Value};
pub struct Rust {
@@ -26,6 +27,7 @@ impl Rust {
// debug!("Cargo.toml:\n{:#?}", self.cargo_toml);
self.cargo_toml.set_version(version)?;
self.cargo_toml.write()?;
+ self.update_cargo_lock()?;
let dirname = self
.dirname
@@ -40,6 +42,21 @@ impl Rust {
);
Ok(())
}
+
+ fn update_cargo_lock(&self) -> Result<(), BumperError> {
+ info!("running cargo update in {}", self.dirname.display());
+ let output = Command::new("cargo")
+ .arg("update")
+ .current_dir(&self.dirname)
+ .output()
+ .map_err(|err| BumperError::CargoInvoke(self.dirname.to_path_buf(), err))?;
+ debug!("git exit code was {:?}", output.status.code());
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
+ return Err(BumperError::Cargo(self.dirname.to_path_buf(), stderr));
+ }
+ Ok(())
+ }
}
#[derive(Debug)]