Files
DanConwayDev 57bc76ea69 fix(build): publish the deployed source revision
Production ngit_build_info reports commit="unknown", forcing every stabilisation cycle to reconstruct the running revision from the deployment pin, store path, and activation time. The metrics reader also expected GIT_HASH while build.rs emitted GIT_COMMIT_SHORT.

Use one full GIT_COMMIT compile-time value for metrics and retain its eight-character form for NIP-11 and the landing page. Nix package and module outputs inject the locked flake revision because filtered Nix sources do not contain .git; ordinary Cargo builds continue to derive HEAD from Git.

Correctness assumes production consumes ngit-grasp through its exported flake module, which captures self.rev. Direct module imports remain supported but deliberately report unknown when no revision is supplied. Runtime configuration and deployment policy are unchanged.

Validated with the 21 metrics-related library tests, nix flake check --no-build, and evaluation of the dirty-tree revision injection. A clean Nix package build and production endpoint verification follow on this committed revision.
2026-08-07 12:05:40 +00:00

34 lines
1.2 KiB
Rust

use std::{env, process::Command};
fn main() {
if let Some(commit) = build_revision() {
let short: String = commit.chars().take(8).collect();
println!("cargo:rustc-env=GIT_COMMIT={commit}");
println!("cargo:rustc-env=GIT_COMMIT_SHORT={short}");
}
// Nix builds inject the locked flake revision because their source archive
// intentionally excludes .git. Development builds fall back to Git.
println!("cargo:rerun-if-env-changed=NGIT_BUILD_REVISION");
// Re-run if HEAD changes (new commits)
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/heads/");
}
fn build_revision() -> Option<String> {
env::var("NGIT_BUILD_REVISION")
.ok()
.filter(|revision| !revision.is_empty() && revision != "unknown")
.or_else(|| {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.ok()?;
output
.status
.success()
.then(|| String::from_utf8_lossy(&output.stdout).trim().to_owned())
.filter(|revision| !revision.is_empty())
})
}