Skip to content

Commit

Permalink
fix: replace vergen by directly running git
Browse files Browse the repository at this point in the history
For some reason, `vergen` was unable to find the git binary when
building inside Ansible. Running git directly fixes the problem... and
we also have one dependency less! 🎉
  • Loading branch information
aochagavia committed Dec 12, 2023
1 parent d38c9f4 commit 7582704
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
23 changes: 0 additions & 23 deletions ci-bench-runner/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions ci-bench-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@ uuid = { version = "1.4.1", features = ["v4", "serde"] }
ctor = "0.2.5"
reqwest = { version = "0.11.22", default-features = false, features = ["rustls-tls-webpki-roots"] }
wiremock = "0.5.19"

[build-dependencies]
vergen = { version = "8.2.6", features = ["git", "gitcl"] }
20 changes: 18 additions & 2 deletions ci-bench-runner/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// In some cases if new migrations are added without accompanying Rust src changes
// `cargo build` isn't smart enough to detect the need for recompilation to pick up
// the new embedded migrations. This build script is the recommended workaround.
// See <https://docs.rs/sqlx/latest/sqlx/macro.migrate.html#triggering-recompilation-on-migration-changes>
println!("cargo:rerun-if-changed=migrations");

// Expose git-related information through environment variables at compile-time
vergen::EmitBuilder::builder().all_git().emit()?;
// Trigger recompilation if the repository's head changed, to make sure the commit information
// embedded in the binary is up-to-date
println!("cargo:rerun-if-changed=.git/HEAD");

// Expose git head information through environment variables at compile-time, so it can be
// embedded in the binary through the `env!` macro
let output = Command::new("git").args(["rev-parse", "HEAD"]).output()?;
let git_sha = String::from_utf8(output.stdout)?;
println!("cargo:rustc-env=GIT_HEAD_SHA={}", git_sha);

let output = Command::new("git")
.args(["show-branch", "--no-name", "HEAD"])
.output()?;
let git_commit_message = String::from_utf8(output.stdout)?;
println!("cargo:rustc-env=GIT_HEAD_COMMIT_MESSAGE={git_commit_message}");

Ok(())
}
4 changes: 2 additions & 2 deletions ci-bench-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub async fn server(
/// Returns git commit information about the binary that is currently deployed
async fn get_server_info() -> Json<serde_json::Value> {
Json(json!({
"git_commit_sha": env!("VERGEN_GIT_SHA").to_string(),
"git_commit_message": env!("VERGEN_GIT_COMMIT_MESSAGE").to_string(),
"git_commit_sha": env!("GIT_HEAD_SHA").to_string(),
"git_commit_message": env!("GIT_HEAD_COMMIT_MESSAGE").to_string(),
}))
}

Expand Down

0 comments on commit 7582704

Please sign in to comment.