mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add (short) commit hash and build time to version hash
This commit is contained in:
parent
59b5e3d239
commit
b1182d4f7b
4 changed files with 62 additions and 13 deletions
33
crunchy-cli-core/build.rs
Normal file
33
crunchy-cli-core/build.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
fn main() -> std::io::Result<()> {
|
||||
println!(
|
||||
"cargo:rustc-env=GIT_HASH={}",
|
||||
get_short_commit_hash()?.unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=BUILD_DATE={}",
|
||||
chrono::Utc::now().format("%F")
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_short_commit_hash() -> std::io::Result<Option<String>> {
|
||||
let git = std::process::Command::new("git")
|
||||
.arg("rev-parse")
|
||||
.arg("--short")
|
||||
.arg("HEAD")
|
||||
.output();
|
||||
|
||||
match git {
|
||||
Ok(cmd) => Ok(Some(
|
||||
String::from_utf8_lossy(cmd.stdout.as_slice()).to_string(),
|
||||
)),
|
||||
Err(e) => {
|
||||
if e.kind() != std::io::ErrorKind::NotFound {
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue