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:
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());
|
||||
Reference in New Issue
Block a user