sforkowany z mirror/soapbox
Try to get version from GitLab CI first
rodzic
5040bca304
commit
284aacccf0
|
@ -3,20 +3,32 @@ const pkg = require('../../../package.json');
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
const shortRepoName = url => new URL(url).pathname.substring(1);
|
const shortRepoName = url => new URL(url).pathname.substring(1);
|
||||||
|
const trimHash = hash => hash.substring(0, 7);
|
||||||
|
|
||||||
const version = pkg => {
|
const version = pkg => {
|
||||||
|
// Try to discern from GitLab CI first
|
||||||
|
const { CI_COMMIT_TAG, CI_COMMIT_REF_NAME, CI_COMMIT_SHA } = process.env;
|
||||||
|
|
||||||
|
if (CI_COMMIT_TAG === `v${pkg.version}` || CI_COMMIT_REF_NAME === 'stable') {
|
||||||
|
return pkg.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof CI_COMMIT_SHA === 'string') {
|
||||||
|
return `${pkg.version}-${trimHash(CI_COMMIT_SHA)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to git directly
|
||||||
try {
|
try {
|
||||||
const head = String(execSync('git rev-parse HEAD'));
|
const head = String(execSync('git rev-parse HEAD'));
|
||||||
const tag = String(execSync(`git rev-parse v${pkg.version}`));
|
const tag = String(execSync(`git rev-parse v${pkg.version}`));
|
||||||
|
|
||||||
if (head !== tag) {
|
if (head !== tag) return `${pkg.version}-${trimHash(head)}`;
|
||||||
return `${pkg.version}-${head.substring(0, 7)}`;
|
|
||||||
} else {
|
|
||||||
return pkg.version;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return pkg.version;
|
// Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fall back to version in package.json
|
||||||
|
return pkg.version;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Ładowanie…
Reference in New Issue