~whynothugo/shotman

c266fc5dcd75d2fc3a5a06abd4435a336fd74bfb — Hugo Osvaldo Barrera 7 months ago fb76f8e git-attribute-version
Use git-attributes to write version into releases
2 files changed, 15 insertions(+), 14 deletions(-)

A .gitattributes
M build.rs
A .gitattributes => .gitattributes +1 -0
@@ 0,0 1,1 @@
build.rs export-subst

M build.rs => build.rs +14 -14
@@ 1,18 1,18 @@
use std::process::Command;
fn main() {
    if std::env::var("SHOTMAN_VERSION").is_err() {
        let version = Command::new("git")
            .args(["describe", "--tags"])
            .output()
            .map(|o| {
                if o.status.success() {
                    String::from_utf8_lossy(&o.stdout).trim().to_owned()
                } else {
                    String::from("unversioned") // git exited non-zero
                }
            })
            .unwrap_or(String::from("unknown")); // failed to run git
    let version = Command::new("git")
        .args(["describe", "--tags"])
        .output()
        .map(|o| {
            if o.status.success() {
                Some(String::from_utf8_lossy(&o.stdout).trim().to_owned())
            } else {
                None
            }
        })
        .ok()
        .flatten()
        .unwrap_or(String::from("$Format:%(describe:tags)$"));

        println!("cargo:rustc-env=SHOTMAN_VERSION={version}");
    }
    println!("cargo:rustc-env=SHOTMAN_VERSION={version}");
}