From 442ab6e96defaa70a041709185293006d844c605 Mon Sep 17 00:00:00 2001 From: hbc Date: Fri, 10 Jul 2026 15:47:29 -0700 Subject: [PATCH] fix: inject release tag version into binary --- .github/workflows/release.yml | 21 ++++++++++++++++++++- AGENTS.md | 4 ++-- scripts/build-sea.mjs | 3 ++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a67deb..e2985cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,14 +42,33 @@ jobs: - name: Install dependencies run: npm ci + - name: Resolve build version + id: version + shell: bash + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + run: | + set -euo pipefail + if [ "${{ github.event_name }}" = "release" ]; then + case "$RELEASE_TAG" in + v[0-9]*) version="${RELEASE_TAG#v}" ;; + *) echo "Release tag must use the vX.Y.Z format: $RELEASE_TAG" >&2; exit 1 ;; + esac + else + version="$(node -p "require('./package.json').version")" + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: Build SEA binary + env: + B4FUN_AI_VERSION: ${{ steps.version.outputs.version }} run: npm run build:sea - name: Smoke test SEA binary shell: bash run: | set -euo pipefail - expected_version="$(node -p "require('./package.json').version")" + expected_version="${{ steps.version.outputs.version }}" actual_version="$(dist/sea/ai --version)" test "$actual_version" = "$expected_version" dist/sea/ai shell init bash --name ai >/dev/null diff --git a/AGENTS.md b/AGENTS.md index 37ea55d..cb758c3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,7 +11,7 @@ Guidance for future work in this repository. ## Versioning - `package.json` is the source of truth for the project version. - Do not maintain a separate checked-in version file. -- The standalone SEA build injects the package version at build time. +- The standalone SEA build uses `B4FUN_AI_VERSION` when set and otherwise injects the package version. - When bumping a release version, update: - `package.json` - `package-lock.json` @@ -33,7 +33,7 @@ Guidance for future work in this repository. ## Release workflow guardrails - The release workflow should smoke test the SEA binary. -- The smoke test should confirm `dist/sea/ai --version` matches `package.json`. +- The release smoke test should confirm `dist/sea/ai --version` matches the release tag without its leading `v`. - If the release artifact fails, check whether the issue is: - version mismatch - runtime access to repo files that do not exist in SEA diff --git a/scripts/build-sea.mjs b/scripts/build-sea.mjs index 7a26714..14e0aac 100644 --- a/scripts/build-sea.mjs +++ b/scripts/build-sea.mjs @@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url"; const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8")); +const buildVersion = process.env.B4FUN_AI_VERSION || packageJson.version; const distDir = path.join(rootDir, "dist", "sea"); const bundlePath = path.join(distDir, "ai.mjs"); const seaConfigPath = path.join(distDir, "sea-config.json"); @@ -54,7 +55,7 @@ await build({ format: "esm", target: "node25", define: { - "process.env.B4FUN_AI_VERSION": JSON.stringify(packageJson.version), + "process.env.B4FUN_AI_VERSION": JSON.stringify(buildVersion), }, banner: { js: 'import { createRequire as __seaCreateRequire } from "node:module"; const require = globalThis.require ?? __seaCreateRequire(import.meta.url);',