From 52b0740b1343af32b77dc7044457a379fcaaad7e Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 26 Mar 2024 15:35:37 +0100 Subject: [PATCH] ci: Make sure to fetch git tags --- .github/workflows/release.yml | 4 ++++ build.rs | 39 ++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 141e94972..94a24dff1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,6 +23,8 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v4 + - name: Get tags + run: git fetch --tags origin - name: Configure build cache uses: actions/cache@v4 with: @@ -59,6 +61,8 @@ jobs: - x86_64-apple-darwin steps: - uses: actions/checkout@v4 + - name: Get tags + run: git fetch --tags origin - name: Configure build cache uses: actions/cache@v4 with: diff --git a/build.rs b/build.rs index 620232c60..fbaab3535 100644 --- a/build.rs +++ b/build.rs @@ -50,22 +50,37 @@ fn main() -> Result<(), Box> { // If `HEAD` doesn't have a tag pointing to it, this is a development version, // so find the closest tag starting with `v` and append `-dev` to the version. // Eg. "1.0.43-dev". - Command::new("git") + let output = Command::new("git") .arg("describe") - .arg("--match=v*") // Match tags starting with `v` + // .arg("--match=v*") // Match tags starting with `v` .arg("--candidates=1") // Only one result .arg("--abbrev=0") // Don't add the commit short-hash to the tag name + .arg("--debug") .arg("HEAD") - .output() - .ok() - .and_then(|output| { - if output.status.success() { - String::from_utf8(output.stdout).ok() - } else { - None - } - }) - .map(|last| format!("{}-dev", last.trim())) + .output()?; + if output.status.success() { + String::from_utf8(output.stdout) + .ok() + .map(|last| format!("{}-dev", last.trim())) + } else { + println!( + "cargo::warning=error: {:?}", + String::from_utf8_lossy(&output.stderr) + ); + println!( + "cargo::warning=error: {:?}", + String::from_utf8_lossy(&output.stdout) + ); + let tags = Command::new("git") + .arg("tag") + .arg("--list") // Match tags starting with `v` + .output()?; + println!( + "cargo::warning=tags: {:?}", + String::from_utf8_lossy(&tags.stdout) + ); + None + } } // If there are no tags found, we'll just call this a pre-release. .unwrap_or(String::from("pre-release"));