mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-08-31 22:50:43 +00:00
better git version info
My previous patch to embed git version info in nodeinfo had some issues, like it produced `2024.4.4-249-g04d45859e6` when building on current `develop`, which is arguably correct but not helpful (it should really say `2025.5.2-dev` somewhere!) * if we're on a tag, trust `package.json` * if we're not, *append* the current commit hash so for example, building on `stable` right now gets you `2025.4.4`, and building on the parent of this commit gets you `2025.5.2-dev+g04d45859e6` the `+` is correct according to https://semver.org/
This commit is contained in:
parent
04d45859e6
commit
1b213dece8
1 changed files with 24 additions and 9 deletions
|
@ -7,20 +7,35 @@ const fs = require('fs');
|
||||||
const packageJsonPath = __dirname + '/../package.json'
|
const packageJsonPath = __dirname + '/../package.json'
|
||||||
const { execFileSync } = require('node:child_process');
|
const { execFileSync } = require('node:child_process');
|
||||||
|
|
||||||
function build() {
|
function callGit(args) {
|
||||||
let gitVersion;
|
return execFileSync('git', args, {
|
||||||
try {
|
encoding: 'utf-8',
|
||||||
gitVersion = execFileSync('git', ['describe', '--tags'], {
|
}).trim();
|
||||||
encoding: 'utf-8',
|
}
|
||||||
});
|
|
||||||
gitVersion = gitVersion.trim();
|
function getGitVersion(versionFromPackageJson) {
|
||||||
} catch (e) {
|
const thisTag = callGit(['tag', '--points-at', 'HEAD']);
|
||||||
console.warn("couldn't get git commit details, ignoring",e);
|
if (thisTag) {
|
||||||
|
// we're building from a tag, we don't care about extra details
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commitId = callGit(['rev-parse', '--short', 'HEAD']);
|
||||||
|
return `${versionFromPackageJson}+g${commitId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function build() {
|
||||||
try {
|
try {
|
||||||
const json = fs.readFileSync(packageJsonPath, 'utf-8')
|
const json = fs.readFileSync(packageJsonPath, 'utf-8')
|
||||||
const meta = JSON.parse(json);
|
const meta = JSON.parse(json);
|
||||||
|
|
||||||
|
let gitVersion;
|
||||||
|
try {
|
||||||
|
gitVersion = getGitVersion(meta.version);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("couldn't get git commit details, ignoring",e);
|
||||||
|
}
|
||||||
|
|
||||||
fs.mkdirSync(__dirname + '/../built', { recursive: true });
|
fs.mkdirSync(__dirname + '/../built', { recursive: true });
|
||||||
fs.writeFileSync(__dirname + '/../built/meta.json', JSON.stringify({ version: meta.version, gitVersion }), 'utf-8');
|
fs.writeFileSync(__dirname + '/../built/meta.json', JSON.stringify({ version: meta.version, gitVersion }), 'utf-8');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue