Merge branch 'commithash' into 'develop'
Fix commit hash not appearing See merge request soapbox-pub/soapbox-fe!1290
This commit is contained in:
@ -125,7 +125,7 @@ const Dashboard: React.FC = () => {
|
||||
<h4><FormattedMessage id='admin.dashwidgets.software_header' defaultMessage='Software' /></h4>
|
||||
<ul>
|
||||
<li>{sourceCode.displayName} <span className='pull-right'>{sourceCode.version}</span></li>
|
||||
<li>{v.software} <span className='pull-right'>{v.version}</span></li>
|
||||
<li>{v.software + (v.build ? `+${v.build}` : '')} <span className='pull-right'>{v.version}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
{features.emailList && account.admin && (
|
||||
|
||||
@ -6,6 +6,14 @@ const pkg = require('../../../package.json');
|
||||
const shortRepoName = url => new URL(url).pathname.substring(1);
|
||||
const trimHash = hash => hash.substring(0, 7);
|
||||
|
||||
const tryGit = cmd => {
|
||||
try {
|
||||
return String(execSync(cmd));
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const version = pkg => {
|
||||
// Try to discern from GitLab CI first
|
||||
const { CI_COMMIT_TAG, CI_COMMIT_REF_NAME, CI_COMMIT_SHA } = process.env;
|
||||
@ -19,14 +27,10 @@ const version = pkg => {
|
||||
}
|
||||
|
||||
// Fall back to git directly
|
||||
try {
|
||||
const head = String(execSync('git rev-parse HEAD'));
|
||||
const tag = String(execSync(`git rev-parse v${pkg.version}`));
|
||||
const head = tryGit('git rev-parse HEAD');
|
||||
const tag = tryGit(`git rev-parse v${pkg.version}`);
|
||||
|
||||
if (head !== tag) return `${pkg.version}-${trimHash(head)}`;
|
||||
} catch (e) {
|
||||
// Continue
|
||||
}
|
||||
if (head && head !== tag) return `${pkg.version}-${trimHash(head)}`;
|
||||
|
||||
// Fall back to version in package.json
|
||||
return pkg.version;
|
||||
|
||||
Reference in New Issue
Block a user