diff --git a/dist/index.js b/dist/index.js index 936dc57..23c0ac1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1141,12 +1141,6 @@ async function run() { `git tag --points-at ${branch} ${releasePattern}` )).trim(); - if (currentTag) { - [major, minor, patch] = parseVersion(currentTag); - setOutput(major, minor, patch, 0, false, branch, namespace); - return; - } - let tag = ''; try { tag = (await cmd( @@ -1203,7 +1197,9 @@ async function run() { if (bumpEachCommit) { core.info(history) history.forEach(line => { - if (line.includes(majorPattern)) { + if (currentTag) { + [major, minor, patch] = parseVersion(currentTag); + } else if (line.includes(majorPattern)) { major += 1; minor = 0; patch = 0; @@ -1214,6 +1210,7 @@ async function run() { patch += 1; } }); + setOutput(major, minor, patch, increment, changed, branch, namespace); return; } @@ -1238,6 +1235,16 @@ async function run() { patch++; } + if (currentTag) { + let tagVersion = parseVersion(currentTag); + if (tagVersion[0] !== major && + tagVersion[1] !== minor && + tagVersion[2] !== patch) { + [major, minor, patch] = tagVersion; + increment = 0; + } + } + setOutput(major, minor, patch, increment, changed, branch, namespace); } catch (error) { diff --git a/index.js b/index.js index 1a20da4..252f0ec 100644 --- a/index.js +++ b/index.js @@ -120,12 +120,6 @@ async function run() { `git tag --points-at ${branch} ${releasePattern}` )).trim(); - if (currentTag) { - [major, minor, patch] = parseVersion(currentTag); - setOutput(major, minor, patch, 0, false, branch, namespace); - return; - } - let tag = ''; try { tag = (await cmd( @@ -182,7 +176,9 @@ async function run() { if (bumpEachCommit) { core.info(history) history.forEach(line => { - if (line.includes(majorPattern)) { + if (currentTag) { + [major, minor, patch] = parseVersion(currentTag); + } else if (line.includes(majorPattern)) { major += 1; minor = 0; patch = 0; @@ -193,6 +189,7 @@ async function run() { patch += 1; } }); + setOutput(major, minor, patch, increment, changed, branch, namespace); return; } @@ -217,6 +214,16 @@ async function run() { patch++; } + if (currentTag) { + let tagVersion = parseVersion(currentTag); + if (tagVersion[0] !== major && + tagVersion[1] !== minor && + tagVersion[2] !== patch) { + [major, minor, patch] = tagVersion; + increment = 0; + } + } + setOutput(major, minor, patch, increment, changed, branch, namespace); } catch (error) { diff --git a/index.test.js b/index.test.js index da7161f..4ad0519 100644 --- a/index.test.js +++ b/index.test.js @@ -90,10 +90,11 @@ test('Tagging does not break version', () => { repo.makeCommit('Initial Commit'); // 0.0.1+0 repo.makeCommit(`Second Commit`); // 0.0.1+1 + repo.makeCommit(`Third Commit`); // 0.0.1+2 repo.exec('git tag v0.0.1') const result = repo.runAction(); - expect(result).toMatch('Version is 0.0.1+0'); + expect(result).toMatch('Version is 0.0.1+2'); repo.clean(); }); @@ -501,5 +502,16 @@ test('Bump each commit picks up tags', () => { repo.makeCommit('Fourth Commit'); expect(repo.runAction()).toMatch('Version is 3.0.1+0'); + repo.clean(); +}); + +test('Increment not affected by matching tag', () => { + const repo = createTestRepo({ tag_prefix: '' }); // 0.0.1 + + repo.makeCommit('Initial Commit'); // 0.0.1+0 + repo.makeCommit('Second Commit'); // 0.0.1+1 + repo.exec('git tag 1.0.0'); + expect(repo.runAction()).toMatch('Version is 0.0.1+1'); + repo.clean(); }); \ No newline at end of file