Skip to content

Commit

Permalink
Preserve increment value on already tagged commits
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHatch committed Jan 16, 2021
1 parent fada5c1 commit 9e192e1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
21 changes: 14 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -1214,6 +1210,7 @@ async function run() {
patch += 1;
}
});

setOutput(major, minor, patch, increment, changed, branch, namespace);
return;
}
Expand All @@ -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) {
Expand Down
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -193,6 +189,7 @@ async function run() {
patch += 1;
}
});

setOutput(major, minor, patch, increment, changed, branch, namespace);
return;
}
Expand All @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});

0 comments on commit 9e192e1

Please sign in to comment.