Rust implementation of OCI Distribution Spec with granular access control
1use std::process::Command;
2
3fn main() {
4 // Re-run if git HEAD changes (new commit)
5 println!("cargo:rerun-if-changed=.git/HEAD");
6 println!("cargo:rerun-if-changed=.git/refs/heads/");
7
8 let version = env!("CARGO_PKG_VERSION");
9
10 let short_sha = Command::new("git")
11 .args(["rev-parse", "--short", "HEAD"])
12 .output()
13 .ok()
14 .filter(|o| o.status.success())
15 .and_then(|o| String::from_utf8(o.stdout).ok())
16 .map(|s| s.trim().to_string());
17
18 let full_version = match short_sha {
19 Some(sha) => format!("{}-{}", version, sha),
20 None => version.to_string(),
21 };
22
23 println!("cargo:rustc-env=GRAIN_VERSION={}", full_version);
24}