Skip to content

Commit 8bfe042

Browse files
committed
fix(build): detect exact tags before branch logic for clean versions
When checking out a tag in CI (detached HEAD state), the version resolution was incorrectly adding dev suffixes. Now checks if we're on an exact tag first, returning clean versions for releases.
1 parent c12aabb commit 8bfe042

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

build.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ fn resolveVersion(b: *std.Build) std.SemanticVersion {
241241

242242
var code: u8 = undefined;
243243

244+
// Check if we're on an exact tag by running git describe early
245+
const git_describe_check = b.runAllowFail(&.{ "git", "describe", "--tags" }, &code, .Ignore) catch "";
246+
if (git_describe_check.len > 0) {
247+
const describe_output = std.mem.trim(u8, git_describe_check, " \n\r");
248+
// If git describe returns just a tag (no dashes), we're on an exact tag
249+
if (std.mem.count(u8, describe_output, "-") == 0) {
250+
// If tag matches version, return clean version
251+
if (std.mem.eql(u8, describe_output, b.fmt("{f}", .{zignal_version}))) {
252+
return zignal_version;
253+
}
254+
}
255+
}
256+
244257
// Get current branch name
245258
const git_branch_raw = b.runAllowFail(&.{ "git", "branch", "--show-current" }, &code, .Ignore) catch "";
246259
const git_branch = std.mem.trim(u8, git_branch_raw, " \n\r");

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .zignal,
3-
.version = "0.3.0-dev",
3+
.version = "0.2.0",
44
.fingerprint = 0x5303c43db377b63a,
55
.minimum_zig_version = "0.15.0-dev.1034+bd97b6618",
66
.dependencies = .{},

0 commit comments

Comments
 (0)