From 4c5d42cb138466f92fd59329ee717c632a945b0b Mon Sep 17 00:00:00 2001 From: gitlawr Date: Thu, 4 Jun 2026 16:50:38 +0800 Subject: [PATCH] feat(version): respect GPUSTACK_UI_* env overrides in build info Allow a wrapping build that checks this source tree out as a sub-package to stamp its own release tag and commit id onto the UI (otherwise the version panel reports the host tree's git HEAD, which the wrapper doesn't control). GPUSTACK_UI_VERSION overrides the release tag and GPUSTACK_UI_COMMIT_ID overrides the short commit id; both fall back to the git tag / commit at HEAD when unset, preserving existing behavior. Names are namespaced to avoid colliding with the many tools and CI runners that already set a generic VERSION. --- config/utils.ts | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/config/utils.ts b/config/utils.ts index 7ddc687c..f2ac5de6 100644 --- a/config/utils.ts +++ b/config/utils.ts @@ -1,13 +1,27 @@ -const child_process = require('child_process'); +import { execSync } from 'child_process'; export const getBranchInfo = () => { - const latestCommit = child_process - .execSync('git rev-parse HEAD') - .toString() - .trim(); - const versionTag = child_process - .execSync(`git tag --contains ${latestCommit}`) - .toString() - .trim(); - return { version: versionTag || '', commitId: latestCommit.slice(0, 7) }; + // git may be absent (source archive, bare container) or this tree may + // not be a git checkout. Swallow the failure and fall back to the env + // overrides below — losing build info shouldn't fail the build. + let latestCommit = ''; + let versionTag = ''; + try { + latestCommit = execSync('git rev-parse HEAD').toString().trim(); + versionTag = execSync(`git tag --contains ${latestCommit}`) + .toString() + .trim(); + } catch { + // Not a git checkout / git unavailable; rely on env overrides. + } + // Respect explicit GPUSTACK_UI_* overrides so a wrapping build that + // checks this source tree out as a sub-package can stamp its own + // release tag and commit id onto the UI (otherwise the panel reports + // the host tree's git HEAD, which the wrapper doesn't control). + const overrideVersion = process.env.GPUSTACK_UI_VERSION?.trim(); + const overrideCommitId = process.env.GPUSTACK_UI_COMMIT_ID?.trim(); + return { + version: overrideVersion || versionTag || '', + commitId: overrideCommitId || latestCommit.slice(0, 7) + }; };