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

@@ -144,16 +144,13 @@
mkRelease = mkRelease =
{ {
system, system,
readVersion, # Source of truth is always $ROOT_DIR/VERSION.
# Shell string — must print current version to stdout: "x.y.z" or "x.y.z-channel.N" # Format:
# Example: # line 1: X.Y.Z
# readVersion = ''cat "$ROOT_DIR/VERSION"''; # line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
writeVersion, # line 3: N (prerelease number, 0 for stable)
# Shell string — env vars available: BASE_VERSION, CHANNEL, PRERELEASE_NUM, FULL_VERSION
# Example:
# writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
postVersion ? "", postVersion ? "",
# Shell string — runs after writeVersion and versionFiles, before git add. # Shell string — runs after VERSION + versionFiles are written, before git add.
# Same env vars available. # Same env vars available.
versionFiles ? [ ], versionFiles ? [ ],
# List of { path, template } attrsets. # List of { path, template } attrsets.
@@ -219,8 +216,34 @@
[ [
channelList channelList
versionFilesScript 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 postVersion
] ]
(builtins.readFile ./packages/release/release.sh); (builtins.readFile ./packages/release/release.sh);
@@ -252,8 +275,6 @@
# Expose a no-op release package for the lib repo itself (dogfood) # Expose a no-op release package for the lib repo itself (dogfood)
release = self.lib.mkRelease { release = self.lib.mkRelease {
inherit system; inherit system;
readVersion = ''cat "$ROOT_DIR/VERSION"'';
writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
}; };
} }
); );

View File

@@ -1,8 +1,11 @@
# release.nix # release.nix
{ {
pkgs, pkgs,
readVersion, # Source of truth is always $ROOT_DIR/VERSION.
writeVersion, # Format:
# line 1: X.Y.Z
# line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
# line 3: N (prerelease number, 0 for stable)
postVersion ? "", postVersion ? "",
versionFiles ? [ ], versionFiles ? [ ],
channels ? [ channels ? [
@@ -34,8 +37,34 @@ let
[ [
channelList channelList
versionFilesScript 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 postVersion
] ]
(builtins.readFile ./release.sh); (builtins.readFile ./release.sh);