Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
feat: --version output now includes Git commit
Lars Wirzenius committed 9 months ago
commit 758dde8f5cdd6d622a76eae097710cf4555fd627
parent 1d209f7
2 files changed +28 -1
added build.rs
@@ -0,0 +1,27 @@
+
use std::process::Command;
+

+
fn main() {
+
    // Set a build-time `GIT_HEAD` env var which includes the commit id;
+
    // such that we can tell which code is running.
+
    let hash = Command::new("git")
+
        .arg("rev-parse")
+
        .arg("--short")
+
        .arg("HEAD")
+
        .output()
+
        .ok()
+
        .and_then(|output| {
+
            if output.status.success() {
+
                String::from_utf8(output.stdout).ok()
+
            } else {
+
                None
+
            }
+
        })
+
        .unwrap_or_else(|| String::from("unknown"));
+

+
    println!("cargo:rustc-env=GIT_HEAD={hash}");
+
    println!(
+
        "cargo:rustc-env=VERSION={}@{hash}",
+
        env!("CARGO_PKG_VERSION")
+
    );
+
    println!("cargo:rustc-rerun-if-changed=.git/HEAD");
+
}
modified src/bin/radicle-native-ci.rs
@@ -55,7 +55,7 @@ fn fallible_main() -> Result<bool, EngineError> {
    } else {
        for arg in args.iter() {
            match arg.as_str() {
-
                "--version" => println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
+
                "--version" => println!("{} {}", env!("CARGO_PKG_NAME"), env!("VERSION")),
                "--show-config" => {
                    let engine = Engine::new()?;
                    println!("{}", engine.config().as_json());