mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-28 15:40:04 +00:00
build: simplify nightly versioning
This commit is contained in:
2
.github/workflows/nightly.yml
vendored
2
.github/workflows/nightly.yml
vendored
@@ -7,7 +7,7 @@ env:
|
|||||||
AWS_REGION: ${{ vars.NIGHTLY_BUILD_AWS_REGION }}
|
AWS_REGION: ${{ vars.NIGHTLY_BUILD_AWS_REGION }}
|
||||||
|
|
||||||
RELEASE: ${{ github.ref_type == 'tag' && github.ref_name || 'nightly' }}
|
RELEASE: ${{ github.ref_type == 'tag' && github.ref_name || 'nightly' }}
|
||||||
VERSION_FLAG: ${{ github.ref_type == 'tag' && format('-Dversion_string={0}', github.ref_name) || format('-Dpre_version={0}', 'nightly') }}
|
VERSION_FLAG: ${{ github.ref_type == 'tag' && format('-Dversion={0}', github.ref_name) || '-Dversion=nightly' }}
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|||||||
50
build.zig
50
build.zig
@@ -719,39 +719,45 @@ fn buildCurl(
|
|||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `MAJOR.MINOR.PATCH-dev` when `git describe` fails.
|
/// Resolves the semantic version of the build.
|
||||||
|
///
|
||||||
|
/// The base version is read from `build.zig.zon`. This can be overridden
|
||||||
|
/// using the `-Dversion` command-line flag:
|
||||||
|
/// - If the flag contains a full semantic version (e.g., `1.2.3`), it replaces
|
||||||
|
/// the base version entirely.
|
||||||
|
/// - If the flag contains a simple string (e.g., `nightly`), it replaces only
|
||||||
|
/// the pre-release tag of the base version (e.g., `1.0.0-dev` -> `1.0.0-nightly`).
|
||||||
|
///
|
||||||
|
/// For versions that have a pre-release tag and no explicit build metadata,
|
||||||
|
/// this function automatically enriches the version with the git commit count
|
||||||
|
/// and short hash (e.g., `1.0.0-dev.5243+dbe45229`).
|
||||||
fn resolveVersion(b: *std.Build) std.SemanticVersion {
|
fn resolveVersion(b: *std.Build) std.SemanticVersion {
|
||||||
const version_string = b.option([]const u8, "version_string", "Override the version of this build");
|
const opt_version = b.option([]const u8, "version", "Override the version of this build");
|
||||||
if (version_string) |semver_string| {
|
|
||||||
return std.SemanticVersion.parse(semver_string) catch |err| {
|
|
||||||
std.debug.panic("Expected -Dversion-string={s} to be a semantic version: {}", .{ semver_string, err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const pre_version = b.option([]const u8, "pre_version", "Override the pre version of this build");
|
const version = if (opt_version) |v|
|
||||||
const pre = blk: {
|
std.SemanticVersion.parse(v) catch blk: {
|
||||||
if (pre_version) |pre| {
|
var fallback = lightpanda_version;
|
||||||
break :blk pre;
|
fallback.pre = v;
|
||||||
|
break :blk fallback;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
lightpanda_version;
|
||||||
|
|
||||||
break :blk lightpanda_version.pre;
|
// Only enrich versions that have a pre-release field and no explicit build metadata.
|
||||||
};
|
if (version.pre == null or version.build != null) return version;
|
||||||
|
|
||||||
// If it's a stable release (no pre or build metadata in build.zig.zon), use it as is
|
|
||||||
if (pre == null and lightpanda_version.build == null) return lightpanda_version;
|
|
||||||
|
|
||||||
// For dev/nightly versions, calculate the commit count and hash
|
// For dev/nightly versions, calculate the commit count and hash
|
||||||
const git_hash_raw = runGit(b, &.{ "rev-parse", "--short", "HEAD" }) catch return lightpanda_version;
|
const git_hash_raw = runGit(b, &.{ "rev-parse", "--short", "HEAD" }) catch return version;
|
||||||
const commit_hash = std.mem.trim(u8, git_hash_raw, " \n\r");
|
const commit_hash = std.mem.trim(u8, git_hash_raw, " \n\r");
|
||||||
|
|
||||||
const git_count_raw = runGit(b, &.{ "rev-list", "--count", "HEAD" }) catch return lightpanda_version;
|
const git_count_raw = runGit(b, &.{ "rev-list", "--count", "HEAD" }) catch return version;
|
||||||
const commit_count = std.mem.trim(u8, git_count_raw, " \n\r");
|
const commit_count = std.mem.trim(u8, git_count_raw, " \n\r");
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.major = lightpanda_version.major,
|
.major = version.major,
|
||||||
.minor = lightpanda_version.minor,
|
.minor = version.minor,
|
||||||
.patch = lightpanda_version.patch,
|
.patch = version.patch,
|
||||||
.pre = b.fmt("{s}.{s}", .{ pre.?, commit_count }),
|
.pre = b.fmt("{s}.{s}", .{ version.pre.?, commit_count }),
|
||||||
.build = commit_hash,
|
.build = commit_hash,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user