fix: getGitVersion incorrectly stating dirty builds in production
All checks were successful
Deploy Brew Application / deploy (push) Successful in 11s
All checks were successful
Deploy Brew Application / deploy (push) Successful in 11s
This commit is contained in:
@@ -14,6 +14,8 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build Frontend
|
||||
env:
|
||||
CI: "true"
|
||||
run: |
|
||||
npm install
|
||||
rm -rf dist/
|
||||
|
||||
29
test_version.js
Normal file
29
test_version.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { execSync } = require('child_process');
|
||||
function getGitVersion() {
|
||||
try {
|
||||
try {
|
||||
execSync('git fetch --tags', { stdio: 'ignore' });
|
||||
} catch (e) {}
|
||||
|
||||
const raw = execSync('git describe --tags --always', { stdio: ['pipe', 'pipe', 'ignore'] })
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
// Check if it's just a commit hash (no dashes, just hex)
|
||||
if (/^[0-9a-f]{7,}$/.test(raw)) {
|
||||
return `v0.0.0-${raw}`;
|
||||
}
|
||||
|
||||
// It might be tag-commits-hash, e.g., v0.1.1-5-g4a9f6b6
|
||||
// Let's shorten it to v0.1.1-4a9f6b6 for a cleaner look, or just return as-is
|
||||
const match = raw.match(/^(.*)-\d+-g([0-9a-f]+)$/);
|
||||
if (match) {
|
||||
return `${match[1]}-${match[2]}`;
|
||||
}
|
||||
|
||||
return raw;
|
||||
} catch (e) {
|
||||
return 'dev';
|
||||
}
|
||||
}
|
||||
console.log(getGitVersion());
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user