From 6267f6121f7823befa4cea0eed987dbd09c7de03 Mon Sep 17 00:00:00 2001 From: Eugen Soloviov Date: Fri, 31 Jan 2025 14:56:40 +0300 Subject: [PATCH] feat: Update version to 0.1.71 This commit updates the version of the `aicommit` package to 0.1.71 in `Cargo.toml`, `package.json`, and the `version` --- Cargo.toml | 2 +- package.json | 2 +- src/main.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++------ version | 2 +- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f6dbf68..863b2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aicommit" -version = "0.1.70" +version = "0.1.71" edition = "2021" authors = ["Eugen Soloviov "] description = "A CLI tool that generates concise and descriptive git commit messages using LLMs" diff --git a/package.json b/package.json index 0b53017..456acee 100644 --- a/package.json +++ b/package.json @@ -36,5 +36,5 @@ "postinstall": "node -e \"process.exit(0)\"", "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.1.70" + "version": "0.1.71" } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bc7e9af..af52936 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,19 +162,72 @@ async fn update_version_file(file_path: &str) -> Result<(), String> { /// Update version in Cargo.toml async fn update_cargo_version(version: &str) -> Result<(), String> { - let cargo_path = "Cargo.toml"; - let content = tokio::fs::read_to_string(cargo_path) + // Update version in Cargo.toml + let cargo_toml_path = "Cargo.toml"; + let content = tokio::fs::read_to_string(cargo_toml_path) .await - .map_err(|e| format!("Failed to read Cargo.toml: {}", e))?; + .map_err(|e| format!("Failed to read {}: {}", cargo_toml_path, e))?; + + let updated_content = content + .lines() + .map(|line| { + if line.starts_with("version = ") { + format!("version = \"{}\"", version) + } else { + line.to_string() + } + }) + .collect::>() + .join("\n"); - let re = regex::Regex::new(r#"(?m)^version = "(.*?)"$"#) - .map_err(|e| format!("Failed to create regex: {}", e))?; + tokio::fs::write(cargo_toml_path, updated_content) + .await + .map_err(|e| format!("Failed to write {}: {}", cargo_toml_path, e))?; - let new_content = re.replace(&content, format!(r#"version = "{}""#, version).as_str()); + // Update version in Cargo.lock + let cargo_lock_path = "Cargo.lock"; + let lock_content = tokio::fs::read_to_string(cargo_lock_path) + .await + .map_err(|e| format!("Failed to read {}: {}", cargo_lock_path, e))?; + + let mut in_aicommit_package = false; + let updated_lock_content = lock_content + .lines() + .map(|line| { + if line.starts_with("name = \"aicommit\"") { + in_aicommit_package = true; + line.to_string() + } else if in_aicommit_package && line.starts_with("version = ") { + in_aicommit_package = false; + format!("version = \"{}\"", version) + } else if line.trim().is_empty() { + in_aicommit_package = false; + line.to_string() + } else { + line.to_string() + } + }) + .collect::>() + .join("\n"); - tokio::fs::write(cargo_path, new_content.as_bytes()) + tokio::fs::write(cargo_lock_path, updated_lock_content) .await - .map_err(|e| format!("Failed to write Cargo.toml: {}", e))?; + .map_err(|e| format!("Failed to write {}: {}", cargo_lock_path, e))?; + + // Run cargo update to ensure Cargo.lock is in sync + let update_output = std::process::Command::new("cargo") + .arg("update") + .arg("--package") + .arg("aicommit") + .output() + .map_err(|e| format!("Failed to execute cargo update: {}", e))?; + + if !update_output.status.success() { + return Err(format!( + "Failed to update Cargo.lock: {}", + String::from_utf8_lossy(&update_output.stderr) + )); + } Ok(()) } diff --git a/version b/version index 62b2f42..8e9f64c 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.70 \ No newline at end of file +0.1.71 \ No newline at end of file