Skip to content

Commit 8f2f6c9

Browse files
Copilotbcho
andauthored
Include git commit hash in SQL extension version (#8)
* Initial plan * Add git commit hash to SQL extension version Co-authored-by: bcho <1975118+bcho@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
1 parent e5d5ec4 commit 8f2f6c9

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

absurd-sqlite-extension/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::fmt::Write;
33
use std::fs;
44
use std::path::{Path, PathBuf};
5+
use std::process::Command;
56

67
#[derive(Debug)]
78
struct MigrationFile {
@@ -28,6 +29,23 @@ fn main() {
2829
let migrations_dir = manifest_dir.join("migrations");
2930
println!("cargo:rerun-if-changed={}", migrations_dir.display());
3031

32+
// Capture git commit hash
33+
let git_commit = Command::new("git")
34+
.args(["rev-parse", "--short", "HEAD"])
35+
.output()
36+
.ok()
37+
.and_then(|output| {
38+
if output.status.success() {
39+
String::from_utf8(output.stdout).ok()
40+
} else {
41+
None
42+
}
43+
})
44+
.map(|s| s.trim().to_string())
45+
.unwrap_or_else(|| "unknown".to_string());
46+
47+
println!("cargo:rustc-env=GIT_COMMIT={}", git_commit);
48+
3149
let default_version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.0.0".to_string());
3250
let mut migrations: Vec<MigrationFile> = Vec::new();
3351

absurd-sqlite-extension/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ mod validate;
1919

2020
fn absurd_version(context: *mut sqlite3_context, _values: &[*mut sqlite3_value]) -> Result<()> {
2121
let version = env!("CARGO_PKG_VERSION");
22-
sqlite_loadable::api::result_text(context, format!("absurd-sqlite/{}", version))?;
22+
let git_commit = env!("GIT_COMMIT");
23+
sqlite_loadable::api::result_text(
24+
context,
25+
format!("absurd-sqlite/{} ({})", version, git_commit),
26+
)?;
2327
Ok(())
2428
}
2529

@@ -241,10 +245,12 @@ mod tests {
241245
.query_row("select absurd_version()", [], |row| row.get(0))
242246
.unwrap();
243247

244-
assert_eq!(
245-
result,
246-
format!("absurd-sqlite/{}", env!("CARGO_PKG_VERSION"))
248+
let expected = format!(
249+
"absurd-sqlite/{} ({})",
250+
env!("CARGO_PKG_VERSION"),
251+
env!("GIT_COMMIT")
247252
);
253+
assert_eq!(result, expected);
248254
}
249255

250256
#[test]

0 commit comments

Comments
 (0)