Skip to content

Commit

Permalink
feat: Update version to 0.1.71
Browse files Browse the repository at this point in the history
This commit updates the version of the `aicommit` package to 0.1.71 in `Cargo.toml`, `package.json`, and the `version`
  • Loading branch information
suenot committed Jan 31, 2025
1 parent 8a2eb92 commit 6267f61
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aicommit"
version = "0.1.70"
version = "0.1.71"
edition = "2021"
authors = ["Eugen Soloviov <suenot@gmail.com>"]
description = "A CLI tool that generates concise and descriptive git commit messages using LLMs"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
69 changes: 61 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<String>>()
.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::<Vec<String>>()
.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(())
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.70
0.1.71

0 comments on commit 6267f61

Please sign in to comment.