change some version stuff

This commit is contained in:
galister
2024-08-20 16:40:08 +09:00
parent 1a87823847
commit 0a2be76150

View File

@@ -2,22 +2,39 @@ use regex::Regex;
use std::process::Command; use std::process::Command;
fn main() { fn main() {
let mut wlx_build = get_version().unwrap_or(format!("{} (Cargo)", env!("CARGO_PKG_VERSION"))); let mut wlx_build = get_version().unwrap_or(format!("{}-unknown", env!("CARGO_PKG_VERSION")));
if std::env::var("GITHUB_ACTIONS").is_ok() { match std::env::var("GITHUB_JOB").as_deref() {
wlx_build = format!("{} (AppImage)", &wlx_build) Ok("make_release") => {
wlx_build = format!("{} (Release)", &wlx_build);
}
Ok("build_appimage") => {
wlx_build = format!("{} (AppImage)", &wlx_build);
}
_ => {}
} }
println!("cargo:rustc-env=WLX_BUILD={}", &wlx_build); println!("cargo:rustc-env=WLX_BUILD={}", &wlx_build);
} }
fn get_version() -> Result<String, Box<dyn std::error::Error>> { fn get_version() -> Result<String, Box<dyn std::error::Error>> {
let re = Regex::new(r"v([0-9.]+)-([0-9]+)-g([a-f0-9]+)").unwrap(); // safe let re = Regex::new(r"v([0-9.]+)-([0-9]+)-g([a-f0-9]+)").unwrap(); // safe
let output = Command::new("git") let output = Command::new("git")
.args(["describe", "--tags", "--abbrev=7", "--dirty", "--always"]) .args(["describe", "--tags", "--abbrev=7", "--dirty"])
.output()?; .output()?;
let output_str = String::from_utf8(output.stdout)?; let mut output_str = String::from_utf8(output.stdout)?;
if output_str.is_empty() {
let output = Command::new("git")
.args(["describe", "--tags", "--abbrev=7", "--dirty", "--always"])
.output()?;
output_str = format!(
"{}-{}",
env!("CARGO_PKG_VERSION"),
String::from_utf8(output.stdout)?
);
}
Ok(re.replace_all(&output_str, "${1}.r${2}.${3}").into_owned()) Ok(re.replace_all(&output_str, "${1}.r${2}.${3}").into_owned())
} }