diff --git a/analyzeCommits.js b/analyzeCommits.js index 317004d..2303077 100644 --- a/analyzeCommits.js +++ b/analyzeCommits.js @@ -1,6 +1,7 @@ const analyzeCommits = require('@semantic-release/commit-analyzer') const SemanticReleaseError = require('@semantic-release/error') const execSync = require('child_process').execSync; +const lastTag = require('./lastTag'); const until = f => array => { const first = array[0]; @@ -13,15 +14,8 @@ const until = f => array => { }; const lastTaggedRelease = () => { - let sha; - - try { - sha = execSync('git rev-list -1 `git describe --tags --abbrev=0 --match "v[0-9]*"`', { - encoding: 'utf8' - }).trim(); - } catch(e) {} - - return sha; + const tag = lastTag({ branch: '', dev: false }); + execSync(`git rev-list -1 ${tag}`, { encoding: 'utf8' }).trim(); }; module.exports = function (pluginConfig, config, cb) { diff --git a/lastTag.js b/lastTag.js index 17aa4ce..4370245 100644 --- a/lastTag.js +++ b/lastTag.js @@ -1,16 +1,10 @@ const execSync = require('child_process').execSync; -const lastTag = () => { - let sha; - - try { - sha = execSync( - 'git describe --tags --match "v[0-9]*" --exclude="*dev*" --abbrev=0 origin/master', - { encoding: 'utf8' } - ).trim(); - } catch(e) {} - - return sha; -} +const lastTag = ({ branch = 'origin/master', dev = true } = {}) => { + const exclude = dev ? ' --exclude="*dev*"' : ''; + return execSync(`git describe --tags --match "v[0-9]*" ${exclude} --abbrev=0 ${branch} || true`, + { encoding: 'utf8' } + ).trim(); +}; module.exports = lastTag;