Fix to provide correct previous version when the current commit is tagged.

This commit is contained in:
Paul Hatcherian 2022-12-17 19:00:10 -06:00
parent 92bc0a8ba4
commit ba6e71e658
5 changed files with 32 additions and 4 deletions

2
dist/index.js vendored
View file

@ -745,7 +745,7 @@ class DefaultLastReleaseResolver {
// so that we will have an accurate increment (assuming the new tag is the expected one)
const command = `git for-each-ref --count=2 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = yield (0, CommandRunner_1.cmd)(command);
tag = tag.split('\n').at(-1) || '';
tag = tag.split('\n').reverse().find(t => t !== '' && t !== currentTag) || '';
}
else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -54,7 +54,7 @@ class DefaultLastReleaseResolver {
// so that we will have an accurate increment (assuming the new tag is the expected one)
const command = `git for-each-ref --count=2 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = yield (0, CommandRunner_1.cmd)(command);
tag = tag.split('\n').at(-1) || '';
tag = tag.split('\n').reverse().find(t => t !== '' && t !== currentTag) || '';
}
else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;

View file

@ -97,6 +97,19 @@ test('Tagging does not break version', async () => {
expect(result.formattedVersion).toBe('0.0.1+2');
}, 15000);
test('Tagging does not break version from previous tag', async () => {
const repo = createTestRepo(); // 0.0.0+0
repo.makeCommit('Initial Commit'); // 0.0.1+0
repo.exec('git tag v0.0.1')
repo.makeCommit(`Second Commit`); // 0.0.2+0
repo.makeCommit(`Third Commit`); // 0.0.2+1
repo.exec('git tag v0.0.2')
const result = await repo.runAction();
expect(result.formattedVersion).toBe('0.0.2+1');
}, 15000);
test('Minor update bumps minor version and resets increment', async () => {
const repo = createTestRepo(); // 0.0.0+0
@ -640,3 +653,17 @@ test('Correct previous version is returned when using branches', async () => {
expect(result.previousVersion).toBe('2.0.1');
expect(result.formattedVersion).toBe('2.0.2+0');
}, 15000);
test('Correct previous version is returned when directly tagged', async () => {
const repo = createTestRepo();
repo.makeCommit('Initial Commit');
repo.exec('git tag v2.0.1')
repo.makeCommit(`Second Commit`);
repo.makeCommit(`Third Commit`);
repo.exec('git tag v2.0.2')
const result = await repo.runAction();
expect(result.previousVersion).toBe('2.0.1');
expect(result.formattedVersion).toBe('2.0.2+1');
}, 15000);

View file

@ -31,7 +31,8 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
// so that we will have an accurate increment (assuming the new tag is the expected one)
const command = `git for-each-ref --count=2 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = await cmd(command);
tag = tag.split('\n').at(-1) || '';
tag = tag.split('\n').reverse().find(t => t !== '' && t !== currentTag) || '';
} else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = await cmd(command);