worklyn / zukapublic
Agent-first git hosting. One Rust binary: git over HTTP and SSH, a REST API, MCP, CI, and multi-tenant isolation.
Get a copy:
git clone https://zuka.worklyn.com/worklyn/zuka.git
| 1 | // Embeds the commit this binary was built from. |
| 2 | // |
| 3 | // The semantic version is bumped by CI and is the number for humans. The build |
| 4 | // identity is version plus commit, and that is what upgrade detection compares — |
| 5 | // because a forgotten version bump would make an old tenant look current, and the |
| 6 | // failure mode of that is a security patch silently not landing. |
| 7 | |
| 8 | use std::process::Command; |
| 9 | |
| 10 | fn main() { |
| 11 | // CI checks a commit out into a bare work tree with no `.git` directory, so |
| 12 | // asking git here finds nothing. The runner already knows the commit and puts it |
| 13 | // in the environment, so prefer that: without it every binary CI produces would |
| 14 | // report `unknown`, they would all compare equal, and no upgrade would ever be |
| 15 | // detected — which is precisely the thing this file exists to prevent. |
| 16 | let commit = std::env::var("ZUKA_SHA") |
| 17 | .ok() |
| 18 | .filter(|s| !s.is_empty()) |
| 19 | .map(|s| s.chars().take(12).collect::<String>()) |
| 20 | .or_else(git_commit) |
| 21 | // A source tarball with neither git history nor a build environment still has |
| 22 | // to compile. Two such builds compare equal, which is the honest answer when |
| 23 | // there is nothing to tell them apart. |
| 24 | .unwrap_or_else(|| "unknown".to_string()); |
| 25 | |
| 26 | let dirty = Command::new("git") |
| 27 | .args(["status", "--porcelain"]) |
| 28 | .output() |
| 29 | .ok() |
| 30 | .filter(|o| o.status.success()) |
| 31 | .map(|o| !o.stdout.is_empty()) |
| 32 | .unwrap_or(false); |
| 33 | |
| 34 | println!( |
| 35 | "cargo:rustc-env=ZUKA_BUILD_COMMIT={commit}{}", |
| 36 | if dirty { "-dirty" } else { "" } |
| 37 | ); |
| 38 | |
| 39 | // The build number: the position of this CI run in the repository's history. |
| 40 | // |
| 41 | // Cargo.toml carries major and minor, which are deliberate and set by a person. |
| 42 | // The third component grows on its own, because the alternative — a human |
| 43 | // remembering to bump a file — is a number that stays 0.1.0 for a year, and a |
| 44 | // version that never changes is one that cannot answer "is this host current?". |
| 45 | // |
| 46 | // Absent outside CI, where the version stays whatever Cargo.toml says. |
| 47 | let version = match std::env::var("ZUKA_RUN_NUMBER").ok().filter(|n| n != "0") { |
| 48 | Some(build) => { |
| 49 | let declared = std::env::var("CARGO_PKG_VERSION").unwrap_or_default(); |
| 50 | let mut parts = declared.split('.'); |
| 51 | let major = parts.next().unwrap_or("0"); |
| 52 | let minor = parts.next().unwrap_or("0"); |
| 53 | format!("{major}.{minor}.{build}") |
| 54 | } |
| 55 | None => std::env::var("CARGO_PKG_VERSION").unwrap_or_default(), |
| 56 | }; |
| 57 | println!("cargo:rustc-env=ZUKA_BUILD_VERSION={version}"); |
| 58 | |
| 59 | println!("cargo:rerun-if-env-changed=ZUKA_SHA"); |
| 60 | println!("cargo:rerun-if-env-changed=ZUKA_RUN_NUMBER"); |
| 61 | // Rebuild when HEAD moves, so the embedded commit cannot go stale. |
| 62 | println!("cargo:rerun-if-changed=.git/HEAD"); |
| 63 | println!("cargo:rerun-if-changed=.git/refs"); |
| 64 | } |
| 65 | |
| 66 | fn git_commit() -> Option<String> { |
| 67 | Command::new("git") |
| 68 | .args(["rev-parse", "--short=12", "HEAD"]) |
| 69 | .output() |
| 70 | .ok() |
| 71 | .filter(|o| o.status.success()) |
| 72 | .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) |
| 73 | .filter(|s| !s.is_empty()) |
| 74 | } |