Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
ci: Make sure to fetch git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Mar 26, 2024
1 parent aaea06d commit 76d917c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
32 changes: 21 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,32 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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("--candidates=1") // Only one result
.arg("--abbrev=0") // Don't add the commit short-hash to the tag name
.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)
);
let tags = Command::new("git")
.arg("tag")
.arg("--list") // Match tags starting with `v`
.output()?;
println!(
"cargo::warning=tags: {:?}",
String::from_utf8_lossy(&output.stdout)
);
None
}
}
// If there are no tags found, we'll just call this a pre-release.
.unwrap_or(String::from("pre-release"));
Expand Down

0 comments on commit 76d917c

Please sign in to comment.