mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Preserve increment value on already tagged commits
This commit is contained in:
parent
fada5c116a
commit
9e192e115f
3 changed files with 41 additions and 15 deletions
21
dist/index.js
vendored
21
dist/index.js
vendored
|
|
@ -1141,12 +1141,6 @@ async function run() {
|
||||||
`git tag --points-at ${branch} ${releasePattern}`
|
`git tag --points-at ${branch} ${releasePattern}`
|
||||||
)).trim();
|
)).trim();
|
||||||
|
|
||||||
if (currentTag) {
|
|
||||||
[major, minor, patch] = parseVersion(currentTag);
|
|
||||||
setOutput(major, minor, patch, 0, false, branch, namespace);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let tag = '';
|
let tag = '';
|
||||||
try {
|
try {
|
||||||
tag = (await cmd(
|
tag = (await cmd(
|
||||||
|
|
@ -1203,7 +1197,9 @@ async function run() {
|
||||||
if (bumpEachCommit) {
|
if (bumpEachCommit) {
|
||||||
core.info(history)
|
core.info(history)
|
||||||
history.forEach(line => {
|
history.forEach(line => {
|
||||||
if (line.includes(majorPattern)) {
|
if (currentTag) {
|
||||||
|
[major, minor, patch] = parseVersion(currentTag);
|
||||||
|
} else if (line.includes(majorPattern)) {
|
||||||
major += 1;
|
major += 1;
|
||||||
minor = 0;
|
minor = 0;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
|
|
@ -1214,6 +1210,7 @@ async function run() {
|
||||||
patch += 1;
|
patch += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1238,6 +1235,16 @@ async function run() {
|
||||||
patch++;
|
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);
|
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
21
index.js
21
index.js
|
|
@ -120,12 +120,6 @@ async function run() {
|
||||||
`git tag --points-at ${branch} ${releasePattern}`
|
`git tag --points-at ${branch} ${releasePattern}`
|
||||||
)).trim();
|
)).trim();
|
||||||
|
|
||||||
if (currentTag) {
|
|
||||||
[major, minor, patch] = parseVersion(currentTag);
|
|
||||||
setOutput(major, minor, patch, 0, false, branch, namespace);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let tag = '';
|
let tag = '';
|
||||||
try {
|
try {
|
||||||
tag = (await cmd(
|
tag = (await cmd(
|
||||||
|
|
@ -182,7 +176,9 @@ async function run() {
|
||||||
if (bumpEachCommit) {
|
if (bumpEachCommit) {
|
||||||
core.info(history)
|
core.info(history)
|
||||||
history.forEach(line => {
|
history.forEach(line => {
|
||||||
if (line.includes(majorPattern)) {
|
if (currentTag) {
|
||||||
|
[major, minor, patch] = parseVersion(currentTag);
|
||||||
|
} else if (line.includes(majorPattern)) {
|
||||||
major += 1;
|
major += 1;
|
||||||
minor = 0;
|
minor = 0;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
|
|
@ -193,6 +189,7 @@ async function run() {
|
||||||
patch += 1;
|
patch += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -217,6 +214,16 @@ async function run() {
|
||||||
patch++;
|
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);
|
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,11 @@ test('Tagging does not break version', () => {
|
||||||
|
|
||||||
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||||
repo.makeCommit(`Second Commit`); // 0.0.1+1
|
repo.makeCommit(`Second Commit`); // 0.0.1+1
|
||||||
|
repo.makeCommit(`Third Commit`); // 0.0.1+2
|
||||||
repo.exec('git tag v0.0.1')
|
repo.exec('git tag v0.0.1')
|
||||||
const result = repo.runAction();
|
const result = repo.runAction();
|
||||||
|
|
||||||
expect(result).toMatch('Version is 0.0.1+0');
|
expect(result).toMatch('Version is 0.0.1+2');
|
||||||
|
|
||||||
repo.clean();
|
repo.clean();
|
||||||
});
|
});
|
||||||
|
|
@ -501,5 +502,16 @@ test('Bump each commit picks up tags', () => {
|
||||||
repo.makeCommit('Fourth Commit');
|
repo.makeCommit('Fourth Commit');
|
||||||
expect(repo.runAction()).toMatch('Version is 3.0.1+0');
|
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();
|
repo.clean();
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue