Skip to content

Commit

Permalink
feat: log build commit
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpdev committed Sep 7, 2024
1 parent deee2db commit 5419443
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::process::Command;

// https://stackoverflow.com/a/44407625/19020549

#[allow(clippy::unnecessary_wraps)]
fn try_main() -> Result<(), Box<dyn std::error::Error>> {
let Ok(output) = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
else {
return Err("Failed to get current Git commit using command".into());
};

let Ok(git_hash) = String::from_utf8(output.stdout) else {
return Err("Failed to convert Git output to UTF-8 string".into());
};

println!("cargo:rustc-env=GIT_HASH={git_hash}");

Ok(())
}

fn main() {
if let Err(e) = try_main() {
eprintln!("Error: {e:#?}");
std::process::exit(1)
}
}
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ async fn main() -> Result<()> {
.init();
}
tracing::info!("Logging to {log_path:?}");
tracing::debug!(
"Running {} built from Git commit {}",
env!("CARGO_CRATE_NAME"),
env!("GIT_HASH")
);

tracing::info!("Creating TLS config");
let cert_dirs_to_search = get_cert_dirs_to_search(&exe_path);
Expand Down

0 comments on commit 5419443

Please sign in to comment.