From efd6e9d4f6579499e1f32f3a2fc462e3b749778a Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 8 Jul 2023 14:28:36 -0500 Subject: build: fix and simplify release --- xtask/src/release.rs | 65 +++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) (limited to 'xtask') diff --git a/xtask/src/release.rs b/xtask/src/release.rs index 274df12..3e8f02e 100644 --- a/xtask/src/release.rs +++ b/xtask/src/release.rs @@ -10,65 +10,44 @@ use self::bump::{Bump, Level}; mod bump; -#[derive(Debug, Clone, Args)] -pub struct Release { - #[command(subcommand)] - step: Option, - - /// Level of version bump version. - #[arg(global = true, required = false)] - level: bump::Level, - - /// Options passed to git commit. - #[arg(global = true, last = true)] - git_commit_args: Vec, -} - -impl Release { - pub fn run(self) -> Result<()> { - match self.step { - Some(step) => step.run(), - None => { - let bump = Step::bump(self.level)?; - - println!("Bumped version: {bump}"); - - Ok(()) - } - } - } -} - #[derive(Debug, Clone, Subcommand)] pub enum Step { /// Bump version in package files and commit changes. Bump { - #[arg(from_global)] + /// Level of version bump version. + #[arg(required = false)] level: bump::Level, }, /// Make a release commit. Commit { - #[arg(from_global)] + /// Options passed to git commit. + #[arg(last = true)] git_commit_args: Vec, }, /// Create git tag for release. - Tag { - #[arg(from_global)] - level: bump::Level, - }, + Tag, +} + +#[derive(Debug, Clone, Args)] +pub struct Release { + #[command(subcommand)] + step: Step, } -impl Step { +impl Release { pub fn run(self) -> Result<()> { - match self { + match self.step { Step::Bump { level } => { let bump = Self::bump(level)?; println!("Bumped version: {bump}"); } - Step::Commit { git_commit_args } => Self::commit(git_commit_args)?, - Step::Tag { level } => { + Step::Commit { git_commit_args } => { + let version = PKG_VER.parse()?; + Self::commit(version, git_commit_args)? + } + Step::Tag => { let stdout = Command::new("git") .arg("describe") .arg("--abbrev=0") @@ -76,9 +55,11 @@ impl Step { .stdout; let prev = std::str::from_utf8(&stdout)? + .trim() .trim_start_matches('v') .parse()?; - let next = level.bump(&prev); + + let next = PKG_VER.parse()?; Self::tag(prev, next)?; } }; @@ -114,9 +95,11 @@ impl Step { Ok(bump) } - pub fn commit(git_commit_args: Vec) -> Result<()> { + pub fn commit(version: Version, git_commit_args: Vec) -> Result<()> { let git_commit = Command::new("git") .arg("commit") + .arg("-em") + .arg(format!("chore: release projectr version {version}")) .args(git_commit_args) .status()?; -- cgit v1.2.3-70-g09d2