feat: better version management

This commit is contained in:
eric
2026-03-04 06:00:43 +01:00
parent 16f403ef4b
commit d4a7acefd6
2 changed files with 67 additions and 17 deletions

View File

@@ -1,8 +1,11 @@
# release.nix
{
pkgs,
readVersion,
writeVersion,
# Source of truth is always $ROOT_DIR/VERSION.
# Format:
# line 1: X.Y.Z
# line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
# line 3: N (prerelease number, 0 for stable)
postVersion ? "",
versionFiles ? [ ],
channels ? [
@@ -34,8 +37,34 @@ let
[
channelList
versionFilesScript
readVersion
writeVersion
''
if [[ ! -f "$ROOT_DIR/VERSION" ]]; then
echo "Error: missing $ROOT_DIR/VERSION" >&2
exit 1
fi
base_line="$(sed -n '1p' "$ROOT_DIR/VERSION" | tr -d '\r')"
channel_line="$(sed -n '2p' "$ROOT_DIR/VERSION" | tr -d '\r')"
n_line="$(sed -n '3p' "$ROOT_DIR/VERSION" | tr -d '\r')"
# Backward compatibility: old single-line format.
if [[ -z "$channel_line" ]]; then
printf '%s\n' "$base_line"
elif [[ "$channel_line" == "stable" ]]; then
printf '%s\n' "$base_line"
else
printf '%s-%s.%s\n' "$base_line" "$channel_line" "$n_line"
fi
''
''
channel_to_write="$CHANNEL"
n_to_write="''${PRERELEASE_NUM:-1}"
if [[ "$channel_to_write" == "stable" || -z "$channel_to_write" ]]; then
channel_to_write="stable"
n_to_write="0"
fi
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write" > "$ROOT_DIR/VERSION"
''
postVersion
]
(builtins.readFile ./release.sh);