merge: better git version info (!1203)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1203 Approved-by: Marie <github@yuugi.dev> Approved-by: Hazelnoot <acomputerdog@gmail.com>
This commit is contained in:
commit
69f88d2184
1 changed files with 24 additions and 9 deletions
|
|
@ -7,20 +7,35 @@ const fs = require('fs');
|
|||
const packageJsonPath = __dirname + '/../package.json'
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
function build() {
|
||||
let gitVersion;
|
||||
try {
|
||||
gitVersion = execFileSync('git', ['describe', '--tags'], {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
gitVersion = gitVersion.trim();
|
||||
} catch (e) {
|
||||
console.warn("couldn't get git commit details, ignoring",e);
|
||||
function callGit(args) {
|
||||
return execFileSync('git', args, {
|
||||
encoding: 'utf-8',
|
||||
}).trim();
|
||||
}
|
||||
|
||||
function getGitVersion(versionFromPackageJson) {
|
||||
const thisTag = callGit(['tag', '--points-at', 'HEAD']);
|
||||
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 {
|
||||
const json = fs.readFileSync(packageJsonPath, 'utf-8')
|
||||
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.writeFileSync(__dirname + '/../built/meta.json', JSON.stringify({ version: meta.version, gitVersion }), 'utf-8');
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue