Skip to content

Commit

Permalink
fix: better conditional for git commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aulneau committed May 11, 2021
1 parent 7e78bde commit 354077c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,28 @@ const getSegmentKey = () => {
};

const getBranch = () => {
const branch = execSync(`git rev-parse --abbrev-ref HEAD`, { encoding: 'utf8' }).trim();
return branch;
try {
return execSync(`git rev-parse --abbrev-ref HEAD`, { encoding: 'utf8' }).trim();
} catch (e) {
console.warn(e);
return null;
}
};

const getCommit = () => {
const commit = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
return commit;
try {
return execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
} catch (e) {
console.warn(e);
return null;
}
};

/**
* For CI builds, we add a random number after the patch version.
*/
const getVersion = () => {
const branch = getBranch();
if (branch === 'main') return _version;
if (branch === 'main' || !branch) return _version;
return `${_version}.${Math.floor(Math.floor(Math.random() * 1000))}`;
};

Expand Down

0 comments on commit 354077c

Please sign in to comment.