feat: unify release steps

This commit is contained in:
eric
2026-03-04 07:25:54 +01:00
parent 9f2e1b512b
commit 40d0464f61
3 changed files with 341 additions and 351 deletions

View File

@@ -122,8 +122,7 @@
${pre-commit-check.shellHook} ${pre-commit-check.shellHook}
if [ -t 1 ]; then if [ -t 1 ]; then
: command -v tput >/dev/null 2>&1 && tput clear || printf '\033c'
# command -v tput >/dev/null 2>&1 && tput clear || printf '\033c'
fi fi
GREEN='\033[1;32m' GREEN='\033[1;32m'
@@ -151,27 +150,13 @@
# line 2: CHANNEL (stable|alpha|beta|rc|internal|...) # line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
# line 3: N (prerelease number, 0 for stable) # line 3: N (prerelease number, 0 for stable)
postVersion ? "", postVersion ? "",
# Shell string — runs after VERSION + versionFiles are written, before git add. # Shell string — runs after VERSION + release steps are written/run, before git add.
# Same env vars available. # Same env vars available.
versionFiles ? [ ], release ? [ ],
# List of { path, template } attrsets. # Unified list processed in declaration order:
# template is a Nix function: version -> string # { file = "path/to/file"; content = ''...$FULL_VERSION...''; } # write file
# The content is fully rendered by Nix at eval time — no shell interpolation needed. # { run = ''...shell snippet...''; } # run script
# Example: # Runtime env includes: BASE_VERSION, CHANNEL, PRERELEASE_NUM, FULL_VERSION, FULL_TAG.
# versionFiles = [
# {
# path = "src/version.ts";
# template = version: ''export const APP_VERSION = "${version}" as const;'';
# }
# {
# path = "internal/version/version.go";
# template = version: ''
# package version
#
# const Version = "${version}"
# '';
# }
# ];
channels ? [ channels ? [
"alpha" "alpha"
"beta" "beta"
@@ -186,35 +171,34 @@
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
channelList = pkgs.lib.concatStringsSep " " channels; channelList = pkgs.lib.concatStringsSep " " channels;
# Version files are fully rendered by Nix at eval time. releaseStepsScript = pkgs.lib.concatMapStrings (
# The shell only writes the pre-computed strings — no shell interpolation in templates. entry:
versionFilesScript = pkgs.lib.concatMapStrings ( if entry ? file then
f:
let
# We can't call f.template here since FULL_VERSION is a runtime value.
# Instead we pass the path and use a shell heredoc with the template
# rendered at runtime via the VERSION env vars.
renderedContent = f.template "$FULL_VERSION";
in
'' ''
mkdir -p "$(dirname "${f.path}")" mkdir -p "$(dirname "${entry.file}")"
cat > "${f.path}" << 'NIXEOF' cat > "${entry.file}" << NIXEOF
${renderedContent} ${entry.content}
NIXEOF NIXEOF
log "Generated version file: ${f.path}" log "Generated version file: ${entry.file}"
'' ''
) versionFiles; else if entry ? run then
''
${entry.run}
''
else
builtins.throw "release entry must have either 'file' or 'run'"
) release;
script = script =
builtins.replaceStrings builtins.replaceStrings
[ [
"__CHANNEL_LIST__" "__CHANNEL_LIST__"
"__VERSION_FILES__" "__RELEASE_STEPS__"
"__POST_VERSION__" "__POST_VERSION__"
] ]
[ [
channelList channelList
versionFilesScript releaseStepsScript
postVersion postVersion
] ]
(builtins.readFile ./packages/release/release.sh); (builtins.readFile ./packages/release/release.sh);
@@ -237,18 +221,20 @@
}; };
# ── packages ──────────────────────────────────────────────────────────── # ── packages ────────────────────────────────────────────────────────────
packages = forAllSystems ( packages = forAllSystems (system: {
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
# 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;
}; release = [
{
run = ''
sed -E -i "s#^([[:space:]]*devshell-lib\\.url = \")git\\+https://git\\.dgren\\.dev/eric/nix-flake-lib[^"]*(\";)#\\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\\2#" "$ROOT_DIR/template/flake.nix"
log "Updated template/flake.nix devshell-lib ref to $FULL_TAG"
'';
} }
); ];
};
});
# ── devShells ─────────────────────────────────────────────────────────── # ── devShells ───────────────────────────────────────────────────────────
devShells = forAllSystems ( devShells = forAllSystems (

View File

@@ -1,13 +1,11 @@
# release.nix # release.nix
{ {
pkgs, pkgs,
# 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 ? "", postVersion ? "",
versionFiles ? [ ], release ? [ ],
# Unified list, processed in declaration order:
# { file = "path/to/file"; content = "..."; } — write file
# { run = "shell snippet..."; } — run script
channels ? [ channels ? [
"alpha" "alpha"
"beta" "beta"
@@ -19,24 +17,28 @@
let let
channelList = pkgs.lib.concatStringsSep " " channels; channelList = pkgs.lib.concatStringsSep " " channels;
versionFilesScript = pkgs.lib.concatMapStrings (f: '' releaseScript = pkgs.lib.concatMapStrings (
mkdir -p "$(dirname "${f.path}")" entry:
${f.content} > "${f.path}" if entry ? file then
log "Generated version file: ${f.path}" ''
'') versionFiles; mkdir -p "$(dirname "${entry.file}")"
cat > "${entry.file}" << NIXEOF
${entry.content}
NIXEOF
log "Generated version file: ${entry.file}"
''
else if entry ? run then
''
${entry.run}
''
else
builtins.throw "release entry must have either 'file' or 'run'"
) release;
script = script =
builtins.replaceStrings builtins.replaceStrings
[ [ "__CHANNEL_LIST__" "__RELEASE_STEPS__" "__POST_VERSION__" ]
"__CHANNEL_LIST__" [ channelList releaseScript postVersion ]
"__VERSION_FILES__"
"__POST_VERSION__"
]
[
channelList
versionFilesScript
postVersion
]
(builtins.readFile ./release.sh); (builtins.readFile ./release.sh);
in in
pkgs.writeShellApplication { pkgs.writeShellApplication {

View File

@@ -159,7 +159,8 @@ compute_full_version() {
else else
FULL_VERSION="${BASE_VERSION}-${CHANNEL}.${PRERELEASE_NUM:-1}" FULL_VERSION="${BASE_VERSION}-${CHANNEL}.${PRERELEASE_NUM:-1}"
fi fi
export BASE_VERSION CHANNEL PRERELEASE_NUM FULL_VERSION FULL_TAG="v$FULL_VERSION"
export BASE_VERSION CHANNEL PRERELEASE_NUM FULL_VERSION FULL_TAG
} }
# ── gitlint ──────────────────────────────────────────────────────────────── # ── gitlint ────────────────────────────────────────────────────────────────
@@ -187,9 +188,9 @@ validate_commit_message() {
# ── version file generation ──────────────────────────────────────────────── # ── version file generation ────────────────────────────────────────────────
generate_version_files() { run_release_steps() {
: :
__VERSION_FILES__ __RELEASE_STEPS__
} }
# ── version source (built-in) ────────────────────────────────────────────── # ── version source (built-in) ──────────────────────────────────────────────
@@ -364,7 +365,8 @@ main() {
do_write_version do_write_version
log "Updated version source" log "Updated version source"
generate_version_files run_release_steps
log "Release steps done"
do_post_version do_post_version
log "Post-version hook done" log "Post-version hook done"
@@ -378,13 +380,13 @@ main() {
git commit -m "$commit_msg" git commit -m "$commit_msg"
log "Created commit" log "Created commit"
git tag "v$FULL_VERSION" git tag "$FULL_TAG"
CREATED_TAG="v$FULL_VERSION" CREATED_TAG="$FULL_TAG"
log "Tagged v$FULL_VERSION" log "Tagged $FULL_TAG"
git push git push
git push --tags git push --tags
log "Done — released v$FULL_VERSION" log "Done — released $FULL_TAG"
trap - ERR trap - ERR
} }