3 Commits

Author SHA1 Message Date
eric
8ee5367310 feat: auto-init VERSION file 2026-03-04 06:10:29 +01:00
eric
d4a7acefd6 feat: better version management 2026-03-04 06:00:43 +01:00
eric
16f403ef4b fix: add result to gitignore 2026-03-04 05:48:40 +01:00
5 changed files with 65 additions and 28 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.pre-commit-config.yaml
.direnv
result

View File

@@ -144,16 +144,13 @@
mkRelease =
{
system,
readVersion,
# Shell string — must print current version to stdout: "x.y.z" or "x.y.z-channel.N"
# Example:
# readVersion = ''cat "$ROOT_DIR/VERSION"'';
writeVersion,
# Shell string — env vars available: BASE_VERSION, CHANNEL, PRERELEASE_NUM, FULL_VERSION
# Example:
# writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
# 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 ? "",
# 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.
versionFiles ? [ ],
# List of { path, template } attrsets.
@@ -212,15 +209,11 @@
[
"__CHANNEL_LIST__"
"__VERSION_FILES__"
"__READ_VERSION__"
"__WRITE_VERSION__"
"__POST_VERSION__"
]
[
channelList
versionFilesScript
readVersion
writeVersion
postVersion
]
(builtins.readFile ./packages/release/release.sh);
@@ -252,8 +245,6 @@
# Expose a no-op release package for the lib repo itself (dogfood)
release = self.lib.mkRelease {
inherit system;
readVersion = ''cat "$ROOT_DIR/VERSION"'';
writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
};
}
);

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 ? [
@@ -27,15 +30,11 @@ let
[
"__CHANNEL_LIST__"
"__VERSION_FILES__"
"__READ_VERSION__"
"__WRITE_VERSION__"
"__POST_VERSION__"
]
[
channelList
versionFilesScript
readVersion
writeVersion
postVersion
]
(builtins.readFile ./release.sh);

View File

@@ -192,18 +192,65 @@ generate_version_files() {
__VERSION_FILES__
}
# ── user-provided hooks ────────────────────────────────────────────────────
# ── version source (built-in) ──────────────────────────────────────────────
do_read_version() {
:
__READ_VERSION__
if [[ ! -f "$ROOT_DIR/VERSION" ]]; then
local highest_tag=""
while IFS= read -r raw_tag; do
local tag="${raw_tag#v}"
[[ $tag =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+\.[0-9]+)?$ ]] || continue
if [[ -z $highest_tag ]]; then
highest_tag="$tag"
continue
fi
local cmp_status=0
version_cmp "$tag" "$highest_tag" || cmp_status=$?
[[ $cmp_status -eq 1 ]] && highest_tag="$tag"
done < <(git tag --list)
[[ -z $highest_tag ]] && highest_tag="0.0.1"
parse_full_version "$highest_tag"
local channel_to_write="$CHANNEL"
local 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"
log "Initialized $ROOT_DIR/VERSION from highest tag: v$highest_tag"
fi
local base_line channel_line n_line
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')"
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
}
do_write_version() {
:
__WRITE_VERSION__
local channel_to_write="$CHANNEL"
local 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"
}
# ── user-provided hook ─────────────────────────────────────────────────────
do_post_version() {
:
__POST_VERSION__

1
result
View File

@@ -1 +0,0 @@
/nix/store/acl2f263ncy3zfy38cipk2idmqnnvp9x-release