Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtask: new bump versions #893

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bg_redis = ["dep:rusty-sidekiq", "dep:bb8"]
bg_pg = ["dep:sqlx", "dep:ulid"]

[dependencies]
loco-gen = { path = "./loco-gen" }
loco-gen = { version = "0.11.1", path = "./loco-gen" }
backtrace_printer = { version = "1.3.0" }

# cli
Expand Down
2 changes: 1 addition & 1 deletion loco-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "loco-gen"
version = "0.11.0"
version = "0.11.1"
description = "Loco generators"
license.workspace = true
edition.workspace = true
Expand Down
9 changes: 9 additions & 0 deletions xtask/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::{
ArgAction::{SetFalse, SetTrue},
Parser, Subcommand,
};
use xtask::versions;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -29,6 +30,10 @@ enum Commands {
#[arg(short, long, action = SetFalse)]
exclude_starters: bool,
},
Bump {
#[arg(name = "VERSION")]
new_version: Version,
},
}

fn main() -> eyre::Result<()> {
Expand Down Expand Up @@ -69,6 +74,10 @@ fn main() -> eyre::Result<()> {
}
xtask::CmdExit::ok()
}
Commands::Bump { new_version } => {
versions::bump_version(&new_version.to_string());
xtask::CmdExit::ok()
}
};

res.exit();
Expand Down
1 change: 1 addition & 0 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod errors;
pub mod out;
pub mod prompt;
pub mod utils;
pub mod versions;

#[derive(Debug)]
pub struct CmdExit {
Expand Down
72 changes: 72 additions & 0 deletions xtask/src/versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::path::Path;

use regex::Regex;

fn bump_version_in_file(
file_path: &str,
version_regex: &str,
replacement_version: &str,
once: bool,
) {
let path = Path::new(file_path);

// Read the content of the file
if path.exists() {
println!("bumping in {file_path}");
let file_content = std::fs::read_to_string(file_path).expect("read file");

// Apply regex replacement
let re = Regex::new(version_regex).expect("Invalid regex");
if !re.is_match(&file_content) {
println!("cannot match on {file_path}");
return;
}
let new_content = if once {
re.replace(&file_content, replacement_version)
} else {
re.replace_all(&file_content, replacement_version)
};

std::fs::write(path, new_content.to_string()).expect("write file");
}
}

pub fn bump_version(version: &str) {
for cargo in [
"starters/saas/Cargo.toml",
"starters/saas/migration/Cargo.toml",
] {
// turn starters to local
bump_version_in_file(
cargo,
// loco-rs = { version =".."
r#"loco-rs\s*=\s*\{\s*version\s*=\s*"[^"]+""#,
r#"loco-rs = { path="../../""#,
false,
);

// turn starters from local to version
bump_version_in_file(
cargo,
// loco-rs = { path =".."
r#"loco-rs\s*=\s*\{\s*path\s*=\s*"[^"]+?""#,
&format!(r#"loco-rs = {{ version = "{version}""#),
false,
);
}

// replace main versions
let version_replacement = format!(r#"version = "{version}""#);
bump_version_in_file("Cargo.toml", r"(?m)^version.*$", &version_replacement, true);

bump_version_in_file(
"loco-gen/Cargo.toml",
r"(?m)^version.*$",
&version_replacement,
true,
);

// 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);
}
Loading