fix: getGitVersion incorrectly stating dirty builds in production
All checks were successful
Deploy Brew Application / deploy (push) Successful in 11s

This commit is contained in:
2026-06-06 18:06:50 +05:30
parent 4a9f6b6266
commit e808aa8a37
3 changed files with 56 additions and 4 deletions

View File

@@ -6,12 +6,33 @@ import { execSync } from 'child_process'
// Derive version from git tags; fall back to commit hash
function getGitVersion() {
try {
// If there's a tag pointing at HEAD, use it exactly (e.g. "v1.2.0")
// Otherwise use "v0.0.0-<hash>[-dirty]"
const raw = execSync('git describe --tags --always --dirty', { stdio: ['pipe', 'pipe', 'ignore'] })
// Attempt to fetch tags in case of a shallow clone (e.g. CI/CD)
try {
execSync('git fetch --tags', { stdio: 'ignore' });
} catch (e) {
// Ignore if fetch fails
}
// Only include --dirty locally (development), omit in production to prevent false "dirty" flags
const isProd = process.env.NODE_ENV === 'production' || process.env.CI;
const describeCmd = isProd ? 'git describe --tags --always' : 'git describe --tags --always --dirty';
const raw = execSync(describeCmd, { stdio: ['pipe', 'pipe', 'ignore'] })
.toString()
.trim();
// If it looks like a pure tag (no dashes after the tag part) return as-is
// If it's just a commit hash (no tags found)
if (/^[0-9a-f]{7,}$/.test(raw)) {
return `v0.0.0-${raw}`;
}
// If it's a tag + commits + hash (e.g., v0.1.1-5-g4a9f6b6)
// Format it cleanly to v0.1.1-4a9f6b6
const match = raw.match(/^(.*)-\d+-g([0-9a-f]+)$/);
if (match) {
return `${match[1]}-${match[2]}`;
}
// Exact tag (e.g., v1.2.0)
return raw;
} catch {
return 'dev';