diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-07 17:14:25 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-07 17:14:25 +0000 |
| commit | 9fa03035b9f21352c1c8b93681cc1bc1ce4cf6ff (patch) | |
| tree | a59357b60f6fb3bd9ae20e1f7bf4d8c06ce8abae /src | |
| parent | 18d18b1c125c06dd67dcf54ccbd89eb128643737 (diff) | |
| download | genenetwork4-9fa03035b9f21352c1c8b93681cc1bc1ce4cf6ff.tar.gz | |
version: stamp the commit the binary was built from, and prove it
/version reported 4831e5a while HEAD had moved on to 18d18b1: the stamp is written at build time and build.rs only declared .git/HEAD, which keeps saying "ref: refs/heads/main" across commits, so a rebuild after a commit reused the old hash. It now declares the ref file and the index as well, which is what actually makes a rebuild re-stamp. Three additions make the stamp trustworthy rather than merely newer: - `-dirty` when the working tree had uncommitted changes at build time, so a binary built pre-commit can never claim to be that commit; - `source_digest`, a hash over the compiled source files, which tells apart two builds of the same commit -- or of the same dirty tree -- where a commit hash cannot; - `branch`, so a detached HEAD is visible. * build.rs: watch .git/HEAD, the ref it points at, and .git/index; stamp dirty, digest and branch as well as the hash and commit date. * src/lib.rs (VersionInfo): the three new fields, plus a note saying a stamp is never advanced by committing without rebuilding.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs index 3c027bd..42bc748 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,22 +132,48 @@ struct VersionInfo { short_name: &'static str, version: f64, release: u32, + /// The HEAD commit's date (`YYYYMMDD`), not the build time. date: &'static str, + /// The commit this binary was built from, e.g. "18d18b1", or + /// "18d18b1-dirty" when the working tree had uncommitted changes at + /// build time. Compare the part before "-dirty" with a clone's + /// `git log -1 --format=%h`. git: &'static str, + /// Whether that build was from a dirty tree. When true, `git` names + /// the commit whose *neighbourhood* the binary was built from, and + /// `source_digest` is what identifies the code. + dirty: bool, + /// A digest of the compiled source files: two builds of the same + /// commit (or of the same dirty tree) can be told apart by this, + /// which a bare commit hash cannot do. + source_digest: &'static str, + /// The branch the build's HEAD was on, or "HEAD" when detached. + branch: &'static str, } -#[utoipa::path(get, path = "/version", summary = "Build information: version, git commit, commit date", responses( +#[utoipa::path(get, path = "/version", summary = "Build information: the git commit the binary was built from, and a source digest", responses( (status = 200, description = "Build information", body = Envelope<VersionInfo>), (status = 500, description = "Internal error", body = ApiError) ), security())] #[gnauth(disabled)] async fn version(ctx: Ctx) -> Json<Envelope<VersionInfo>> { - Json(ctx.envelope(VersionInfo { - name: "GeneNetwork4", - short_name: "GN4AI", - version: 4.0, - release: 1, - date: env!("GN4_COMMIT_DATE"), - git: env!("GN4_GIT_HASH"), - })) + let git = env!("GN4_GIT_HASH"); + Json( + ctx.envelope(VersionInfo { + name: "GeneNetwork4", + short_name: "GN4AI", + version: 4.0, + release: 1, + date: env!("GN4_COMMIT_DATE"), + git, + dirty: git.ends_with("-dirty"), + source_digest: env!("GN4_SOURCE_DIGEST"), + branch: env!("GN4_GIT_BRANCH"), + }) + .with_note( + "`git` is stamped when this binary was built; `-dirty` means the build had \ + uncommitted changes, and `source_digest` identifies the compiled sources even then. \ + A stamp is never advanced by committing without rebuilding.", + ), + ) } |
