Skip to content

Commit c3be373

Browse files
committed
chore: ignore exit code instead of catching errors
1 parent 0a733b8 commit c3be373

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

analyzeCommits.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const analyzeCommits = require('@semantic-release/commit-analyzer')
22
const SemanticReleaseError = require('@semantic-release/error')
33
const execSync = require('child_process').execSync;
4+
const lastTag = require('./lastTag');
45

56
const until = f => array => {
67
const first = array[0];
@@ -13,15 +14,8 @@ const until = f => array => {
1314
};
1415

1516
const lastTaggedRelease = () => {
16-
let sha;
17-
18-
try {
19-
sha = execSync('git rev-list -1 `git describe --tags --abbrev=0 --match "v[0-9]*"`', {
20-
encoding: 'utf8'
21-
}).trim();
22-
} catch(e) {}
23-
24-
return sha;
17+
const tag = lastTag({ branch: '', dev: false });
18+
execSync(`git rev-list -1 ${tag}`, { encoding: 'utf8' }).trim();
2519
};
2620

2721
module.exports = function (pluginConfig, config, cb) {

lastTag.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
const execSync = require('child_process').execSync;
22

3-
const lastTag = () => {
4-
let sha;
5-
6-
try {
7-
sha = execSync(
8-
'git describe --tags --match "v[0-9]*" --exclude="*dev*" --abbrev=0 origin/master',
9-
{ encoding: 'utf8' }
10-
).trim();
11-
} catch(e) {}
12-
13-
return sha;
14-
}
3+
const lastTag = ({ branch = 'origin/master', dev = true } = {}) => {
4+
const exclude = dev ? ' --exclude="*dev*"' : '';
5+
return execSync(`git describe --tags --match "v[0-9]*" ${exclude} --abbrev=0 ${branch} || true`,
6+
{ encoding: 'utf8' }
7+
).trim();
8+
};
159

1610
module.exports = lastTag;

0 commit comments

Comments
 (0)