mirror of
https://github.com/TECHNOFAB11/bump2version.git
synced 2025-12-12 16:10:07 +01:00
Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f6a50bbda0 | |||
| 2136a99b31 | |||
| a576cb735f | |||
| 053b7cb94b | |||
| 5d2e86e6f1 | |||
| 1a7c22bdbf |
8 changed files with 53 additions and 42 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
current_version = "1.0.0"
|
current_version = "1.1.1"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
message = "chore: bump {current_version} → {new_version}"
|
message = "chore: bump {current_version} → {new_version}"
|
||||||
|
|
@ -11,8 +11,8 @@ type = "string"
|
||||||
values = ["alpha", "beta", "stable"]
|
values = ["alpha", "beta", "stable"]
|
||||||
|
|
||||||
[file."Cargo.toml"]
|
[file."Cargo.toml"]
|
||||||
format = 'version = "{version}"'
|
formats = ['version = "{version}"']
|
||||||
|
|
||||||
[file."Cargo.lock"]
|
[file."Cargo.lock"]
|
||||||
format = """name = "bump2version"
|
formats = ["""name = "bump2version"
|
||||||
version = "{version}""""
|
version = "{version}""""]
|
||||||
|
|
|
||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -61,7 +61,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bump2version"
|
name = "bump2version"
|
||||||
version = "1.0.0"
|
version = "1.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bump2version"
|
name = "bump2version"
|
||||||
version = "1.0.0"
|
version = "1.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "⬆️ Easily manage version numbers in your projects."
|
description = "⬆️ Easily manage version numbers in your projects."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
@ -13,10 +13,6 @@ authors = [
|
||||||
"TECHNOFAB <admin@technofab.de>",
|
"TECHNOFAB <admin@technofab.de>",
|
||||||
]
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.1", features = ["derive"] }
|
clap = { version = "4.5.1", features = ["derive"] }
|
||||||
regex = "1.10.3"
|
regex = "1.10.3"
|
||||||
|
|
|
||||||
4
src/cli.rs
Executable file → Normal file
4
src/cli.rs
Executable file → Normal file
|
|
@ -24,6 +24,10 @@ pub(crate) struct Cli {
|
||||||
#[arg(short = 'n', long = "dry-run", default_value_t = false)]
|
#[arg(short = 'n', long = "dry-run", default_value_t = false)]
|
||||||
pub(crate) dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
|
|
||||||
|
/// Current version
|
||||||
|
#[arg(long = "current-version", value_name = "VERSION")]
|
||||||
|
pub(crate) current_version: Option<String>,
|
||||||
|
|
||||||
/// New version that should be in the files.
|
/// New version that should be in the files.
|
||||||
#[arg(long = "new-version", value_name = "VERSION")]
|
#[arg(long = "new-version", value_name = "VERSION")]
|
||||||
pub(crate) new_version: Option<String>,
|
pub(crate) new_version: Option<String>,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use serde_derive::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub(crate) struct Config {
|
pub(crate) struct Config {
|
||||||
pub(crate) current_version: String,
|
pub(crate) current_version: Option<String>,
|
||||||
pub(crate) message: Option<String>,
|
pub(crate) message: Option<String>,
|
||||||
pub(crate) commit: bool,
|
pub(crate) commit: bool,
|
||||||
pub(crate) tag: bool,
|
pub(crate) tag: bool,
|
||||||
|
|
@ -13,8 +13,8 @@ pub(crate) struct Config {
|
||||||
#[serde(default = "default_serialize")]
|
#[serde(default = "default_serialize")]
|
||||||
pub(crate) serialize: String,
|
pub(crate) serialize: String,
|
||||||
|
|
||||||
pub(crate) part: HashMap<String, Part>,
|
pub(crate) part: Option<HashMap<String, Part>>,
|
||||||
pub(crate) file: HashMap<String, File>,
|
pub(crate) file: Option<HashMap<String, File>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
|
@ -35,8 +35,8 @@ pub(crate) struct Part {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub(crate) struct File {
|
pub(crate) struct File {
|
||||||
/// Format to replace, eg. `current_version = "{version}"`
|
/// Formats to replace, eg. `current_version = "{version}"`
|
||||||
pub(crate) format: String,
|
pub(crate) formats: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_parse() -> String {
|
fn default_parse() -> String {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
||||||
#![doc = include_str!("../README.md")]
|
|
||||||
|
|
||||||
pub(crate) mod cli;
|
|
||||||
pub(crate) mod config;
|
|
||||||
pub(crate) mod utils;
|
|
||||||
34
src/main.rs
34
src/main.rs
|
|
@ -38,12 +38,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let current_version = config.current_version.clone();
|
let current_version = args
|
||||||
|
.current_version
|
||||||
let attempted_new_version = args
|
|
||||||
.new_version
|
|
||||||
.clone()
|
.clone()
|
||||||
.or(attempt_version_bump(args.clone(), config.clone()));
|
.or(config.current_version.clone());
|
||||||
|
|
||||||
|
if current_version.is_none() {
|
||||||
|
error!("No current version could be determined, either set in config or pass as arg");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_version = current_version.unwrap();
|
||||||
|
|
||||||
|
let attempted_new_version = args.new_version.clone().or(attempt_version_bump(
|
||||||
|
args.clone(),
|
||||||
|
config.clone(),
|
||||||
|
current_version.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
if attempted_new_version.is_some() {
|
if attempted_new_version.is_some() {
|
||||||
let new_version = attempted_new_version.clone().unwrap();
|
let new_version = attempted_new_version.clone().unwrap();
|
||||||
|
|
@ -57,7 +68,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.or(config.message)
|
.or(config.message)
|
||||||
.unwrap_or("Bump version: {current_version} → {new_version}".to_string());
|
.unwrap_or("Bump version: {current_version} → {new_version}".to_string());
|
||||||
|
|
||||||
let files: Vec<&String> = config.file.keys().collect();
|
let config_files = config.file.unwrap_or_default();
|
||||||
|
let files: Vec<&String> = config_files.keys().collect();
|
||||||
|
|
||||||
// Check if Git working directory is clean
|
// Check if Git working directory is clean
|
||||||
if fs::metadata(".git").is_ok() {
|
if fs::metadata(".git").is_ok() {
|
||||||
|
|
@ -83,9 +95,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Update version in specified files
|
// Update version in specified files
|
||||||
info!(amount = &files.len(), "Updating version in files");
|
info!(amount = &files.len(), "Updating version in files");
|
||||||
for path in files.clone() {
|
for path in files.clone() {
|
||||||
let content = fs::read_to_string(path)?;
|
let mut content = fs::read_to_string(path)?;
|
||||||
let format = &config.file.get(path).unwrap().format;
|
let formats = &config_files.get(path).unwrap().formats.clone();
|
||||||
|
|
||||||
|
for format in formats {
|
||||||
let old_line = format.replace("{version}", ¤t_version);
|
let old_line = format.replace("{version}", ¤t_version);
|
||||||
if !content.contains(&old_line) {
|
if !content.contains(&old_line) {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
@ -95,10 +108,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_line = format.replace("{version}", &new_version);
|
let new_line = format.replace("{version}", &new_version);
|
||||||
let updated_content = content.replace(&old_line, &new_line);
|
content = content.replace(&old_line, &new_line);
|
||||||
|
}
|
||||||
|
|
||||||
if !dry_run {
|
if !dry_run {
|
||||||
fs::write(path, updated_content)?;
|
fs::write(path, content)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@ use std::collections::HashMap;
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
use tracing::{error, trace};
|
use tracing::{error, trace};
|
||||||
|
|
||||||
pub fn attempt_version_bump(args: Cli, config: Config) -> Option<String> {
|
pub(crate) fn attempt_version_bump(
|
||||||
|
args: Cli,
|
||||||
|
config: Config,
|
||||||
|
current_version: String,
|
||||||
|
) -> Option<String> {
|
||||||
let parse_regex = config.parse;
|
let parse_regex = config.parse;
|
||||||
let regex = match Regex::new(&parse_regex) {
|
let regex = match Regex::new(&parse_regex) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
|
|
@ -16,7 +20,6 @@ pub fn attempt_version_bump(args: Cli, config: Config) -> Option<String> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let current_version = config.current_version;
|
|
||||||
let mut parsed: HashMap<String, String> = HashMap::new();
|
let mut parsed: HashMap<String, String> = HashMap::new();
|
||||||
|
|
||||||
if let Some(captures) = regex.captures(¤t_version) {
|
if let Some(captures) = regex.captures(¤t_version) {
|
||||||
|
|
@ -41,7 +44,7 @@ pub fn attempt_version_bump(args: Cli, config: Config) -> Option<String> {
|
||||||
|
|
||||||
for label in order.clone() {
|
for label in order.clone() {
|
||||||
if let Some(part) = parsed.get_mut(label) {
|
if let Some(part) = parsed.get_mut(label) {
|
||||||
let part_cfg = part_configs.get(label);
|
let part_cfg = part_configs.as_ref().and_then(|c| c.get(label));
|
||||||
|
|
||||||
if label == args.bump {
|
if label == args.bump {
|
||||||
match part_cfg
|
match part_cfg
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue