summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-04 12:30:52 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-04 14:57:38 +0300
commitd60b3fbf8d1840e5a1b5b088333e136616068c15 (patch)
tree6f48e856c00748f36f518c9032ddbcdd1fa7a86a
parentcbeff8974a6228a44396cc924acc6fd111a5b681 (diff)
downloadbumper-rs-d60b3fbf8d1840e5a1b5b088333e136616068c15.tar.gz
feat: set version in debian/changelog
-rw-r--r--bumper.md11
-rw-r--r--src/bin/bumper.rs5
-rw-r--r--src/debian.rs46
-rw-r--r--src/errors.rs6
-rw-r--r--src/lib.rs1
-rw-r--r--src/project.rs18
6 files changed, 82 insertions, 5 deletions
diff --git a/bumper.md b/bumper.md
index b4a269f..130e980 100644
--- a/bumper.md
+++ b/bumper.md
@@ -92,11 +92,14 @@ project. We use a Rust project for simplicity.
~~~scenario
given an installed Bumper
given file foo/Cargo.toml from Cargo.toml
+given file foo/debian/changelog from changelog
given all files in foo are committed to git
given the HEAD commit in foo is COMMIT
when I run, in foo, bumper 1.2.0
then in foo, git tag v1.2.0 is a signed tag pointing at <COMMIT>
then file foo/Cargo.toml matches regex /version\s*=\s*"1\.2\.0"/
+then file foo/debian/changelog matches regex / \(0\.1\.0-1\) /
+then file foo/debian/changelog matches regex / \(1\.2\.0-1\) /
~~~
~~~{#Cargo.toml .file .ini}
@@ -109,6 +112,14 @@ edition = "2018"
[dependencies]
~~~
+~~~{#changelog .file}
+dummy (0.1.0-1) unstable; urgency=low
+
+ * This is a debian/changelog file. Syntax is finicky.
+
+ -- Lars Wirzenius <liw@liw.fi> Tue, 30 Mar 2021 08:33:35 +0300
+~~~
+
---
diff --git a/src/bin/bumper.rs b/src/bin/bumper.rs
index 564b589..08242ed 100644
--- a/src/bin/bumper.rs
+++ b/src/bin/bumper.rs
@@ -17,8 +17,9 @@ fn bumper() -> Result<(), BumperError> {
info!("Bumper starts");
let opt = Opt::from_args();
- let mut project = ProjectKind::detect(".")?;
- project.set_version(&opt.version)?;
+ for mut kind in ProjectKind::detect(".")? {
+ kind.set_version(&opt.version)?;
+ }
git::tag(&opt.version)?;
info!("Bumper ends OK");
diff --git a/src/debian.rs b/src/debian.rs
new file mode 100644
index 0000000..d82a14a
--- /dev/null
+++ b/src/debian.rs
@@ -0,0 +1,46 @@
+use crate::errors::BumperError;
+use log::{debug, info};
+use std::path::{Path, PathBuf};
+use std::process::Command;
+
+pub struct Debian {
+ dirname: PathBuf,
+}
+
+impl Debian {
+ pub fn new(dirname: &Path) -> Result<Self, BumperError> {
+ let changelog = dirname.join("debian/changelog");
+ if changelog.exists() {
+ info!("directory {} contains Debian packaging", dirname.display());
+ return Ok(Self {
+ dirname: dirname.to_path_buf(),
+ });
+ }
+ debug!(
+ "directory {} doesn't contains Debian packaging",
+ dirname.display()
+ );
+ Err(BumperError::UnknownProjectKind(dirname.to_path_buf()))
+ }
+
+ pub fn set_version(&mut self, version: &str) -> Result<(), BumperError> {
+ let version = format!("{}-1", version);
+ self.dch(&["-v", &version, ""])?;
+ self.dch(&["-r", ""])?;
+ Ok(())
+ }
+
+ fn dch(&self, args: &[&str]) -> Result<(), BumperError> {
+ let output = Command::new("dch")
+ .args(args)
+ .current_dir(&self.dirname)
+ .output()
+ .map_err(|err| BumperError::DchInvoke(self.dirname.to_path_buf(), err))?;
+ if output.status.success() {
+ Ok(())
+ } else {
+ let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
+ Err(BumperError::Dch(self.dirname.to_path_buf(), stderr))
+ }
+ }
+}
diff --git a/src/errors.rs b/src/errors.rs
index c7febe3..3eb8605 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -37,6 +37,12 @@ pub enum BumperError {
#[error("Command 'git tag' failed: {0}")]
GitTag(String),
+
+ #[error("Failed to run dch in {0}: {1}")]
+ DchInvoke(PathBuf, #[source] std::io::Error),
+
+ #[error("dch failed in {0}: {1}")]
+ Dch(PathBuf, String),
}
impl BumperError {
diff --git a/src/lib.rs b/src/lib.rs
index 06071a6..51ddd5f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,4 @@
+pub mod debian;
pub mod errors;
pub mod git;
pub mod project;
diff --git a/src/project.rs b/src/project.rs
index 7471c66..9f45363 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,25 +1,37 @@
+use crate::debian::Debian;
use crate::errors::BumperError;
use crate::rust::Rust;
use std::path::Path;
pub enum ProjectKind {
Rust(Rust),
+ Debian(Debian),
}
impl ProjectKind {
- pub fn detect<P: AsRef<Path>>(dirname: P) -> Result<ProjectKind, BumperError> {
+ pub fn detect<P: AsRef<Path>>(dirname: P) -> Result<Vec<ProjectKind>, BumperError> {
let dirname = dirname.as_ref();
+ let mut kinds = vec![];
if let Ok(p) = Rust::new(dirname) {
- return Ok(Self::Rust(p));
+ kinds.push(ProjectKind::Rust(p));
}
- Err(BumperError::UnknownProjectKind(dirname.to_path_buf()))
+ if let Ok(p) = Debian::new(dirname) {
+ kinds.push(ProjectKind::Debian(p));
+ }
+
+ if kinds.is_empty() {
+ Err(BumperError::UnknownProjectKind(dirname.to_path_buf()))
+ } else {
+ Ok(kinds)
+ }
}
pub fn set_version(&mut self, version: &str) -> Result<(), BumperError> {
match self {
Self::Rust(ref mut rust) => rust.set_version(version)?,
+ Self::Debian(ref mut debian) => debian.set_version(version)?,
}
Ok(())
}