Skip to content

Commit

Permalink
New verbump (#935)
Browse files Browse the repository at this point in the history
implement a new version bumping process, simpler, multi-crate workspace aware `xtask bump`
  • Loading branch information
jondot authored Oct 30, 2024
1 parent 322b86a commit 2b4272e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
17 changes: 14 additions & 3 deletions xtask/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum Commands {
quick: bool,
},
/// Bump loco version in all dependencies places
BumpVersion {
DeprecatedBumpVersion {
#[arg(name = "VERSION")]
new_version: Version,
#[arg(short, long, action = SetFalse)]
Expand All @@ -51,7 +51,7 @@ fn main() -> eyre::Result<()> {
println!("{}", xtask::out::print_ci_results(&res));
xtask::CmdExit::ok()
}
Commands::BumpVersion {
Commands::DeprecatedBumpVersion {
new_version,
exclude_starters,
} => {
Expand All @@ -75,7 +75,18 @@ fn main() -> eyre::Result<()> {
xtask::CmdExit::ok()
}
Commands::Bump { new_version } => {
versions::bump_version(&new_version.to_string());
let meta = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.current_dir(&project_dir)
.exec()
.unwrap();
let root: &Package = meta.root_package().unwrap();
if xtask::prompt::confirmation(&format!(
"upgrading loco version from {} to {}",
root.version, new_version,
))? {
versions::bump_version(&new_version.to_string())?;
}
xtask::CmdExit::ok()
}
};
Expand Down
39 changes: 33 additions & 6 deletions xtask/src/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use std::path::Path;

use regex::Regex;

use crate::{
ci,
errors::{Error, Result},
out,
};

fn bump_version_in_file(
file_path: &str,
version_regex: &str,
Expand Down Expand Up @@ -31,21 +37,41 @@ fn bump_version_in_file(
}
}

pub fn bump_version(version: &str) {
for cargo in [
pub fn bump_version(version: &str) -> Result<()> {
let starters = [
"starters/saas/Cargo.toml",
"starters/saas/migration/Cargo.toml",
] {
// turn starters to local
"starters/rest-api/Cargo.toml",
"starters/lightweight-service/Cargo.toml",
];

// turn starters to local "../../" version for testing
for cargo in starters {
bump_version_in_file(
cargo,
// loco-rs = { version =".."
r#"loco-rs\s*=\s*\{\s*version\s*=\s*"[^"]+""#,
r#"loco-rs = { path="../../""#,
false,
);
}

println!("Testing starters CI");
let starter_projects: Vec<ci::RunResults> = ci::run_all_in_folder(Path::new("starters"))?;

println!("Starters CI results:");
println!("{}", out::print_ci_results(&starter_projects));
for starter in &starter_projects {
if !starter.is_valid() {
return Err(Error::Message(format!(
"starter {} ins not passing the CI",
starter.path.display()
)));
}
}

// turn starters from local to version
// all oK
// turn starters from local to version
for cargo in starters {
bump_version_in_file(
cargo,
// loco-rs = { path =".."
Expand All @@ -69,4 +95,5 @@ pub fn bump_version(version: &str) {
// sync new version to subcrates in main Cargo.toml
let loco_gen_dep = format!(r#"loco-gen = {{ version = "{version}","#);
bump_version_in_file("Cargo.toml", r"(?m)^loco-gen [^,]*,", &loco_gen_dep, false);
Ok(())
}

0 comments on commit 2b4272e

Please sign in to comment.