Skip to content

Commit

Permalink
Merge pull request #104 from PaulHatch/101-previous_version-output-re…
Browse files Browse the repository at this point in the history
…sults-in-first-versiontag-and-not-previous-versiontag-when-commit-is-already-tagged

Fix for previous tag logic
  • Loading branch information
PaulHatch committed Apr 8, 2023
2 parents f9d3daa + 9a5d07b commit d3ce4be
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
1 change: 0 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/providers/DefaultLastReleaseResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class DefaultLastReleaseResolver {
tag = yield (0, CommandRunner_1.cmd)(command);
tag = tag
.split('\n')
.reverse()
.find(t => tagFormatter.IsValid(t) && t !== currentTag) || '';
}
else {
Expand Down
55 changes: 54 additions & 1 deletion src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ test('Correct previous version is returned', async () => {
const repo = createTestRepo();

repo.makeCommit('Initial Commit');
repo.exec('git tag v2.0.1')
repo.exec('git tag v2.0.1');
repo.makeCommit(`Second Commit`);
repo.makeCommit(`Third Commit`);
const result = await repo.runAction();
Expand All @@ -644,6 +644,22 @@ test('Correct previous version is returned', async () => {
expect(result.previousVersion).toBe('2.0.1');
}, timeout);

test('Correct previous version is returned when multiple tags are present', async () => {
const repo = createTestRepo();

repo.makeCommit('Initial Commit');
repo.exec('git tag v1.0.1');
repo.makeCommit(`Second Commit`);
repo.exec('git tag v2.0.1');
repo.makeCommit(`Third Commit`);
repo.exec('git tag v3.0.1');
repo.makeCommit(`Fourth Commit`);
const result = await repo.runAction();

expect(result.formattedVersion).toBe('3.0.2+0');
expect(result.previousVersion).toBe('3.0.1');
}, timeout);

test('Correct previous version is returned when using branches', async () => {
const repo = createTestRepo({ tagPrefix: 'release/', useBranches: true });

Expand Down Expand Up @@ -673,6 +689,21 @@ test('Correct previous version is returned when directly tagged', async () => {
expect(result.formattedVersion).toBe('2.0.2+1');
}, timeout);

test('Correct previous version is returned when directly tagged with multiple previous tags', async () => {
const repo = createTestRepo();

repo.makeCommit('Initial Commit');
repo.exec('git tag v2.0.1')
repo.makeCommit(`Second Commit`);
repo.exec('git tag v2.0.2')
repo.makeCommit(`Third Commit`);
repo.exec('git tag v2.0.3')
const result = await repo.runAction();

expect(result.previousVersion).toBe('2.0.2');
expect(result.formattedVersion).toBe('2.0.3+0');
}, timeout);

test('Prerelease suffixes are ignored', async () => {
const repo = createTestRepo();

Expand Down Expand Up @@ -897,4 +928,26 @@ test('Tagged commit is flagged as release', async () => {
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.1.0-prerelease.1');
expect(result.isTagged).toBe(true);
}, timeout);


test('Highest tag is chosen when multiple tags are present', async () => {
const repo = createTestRepo();

repo.makeCommit('Initial Commit');
repo.exec('git tag v2.0.0');
repo.exec('git tag v1.0.0');
repo.exec('git tag v1.5.0');
var result = await repo.runAction();
expect(result.formattedVersion).toBe('2.0.0+0');

repo.exec('git tag v3.0.0');
repo.exec('git tag v2.1.0');
result = await repo.runAction();
expect(result.formattedVersion).toBe('3.0.0+0');

repo.makeCommit('Additional Commit');
result = await repo.runAction();
expect(result.formattedVersion).toBe('3.0.1+0');

}, timeout);
1 change: 0 additions & 1 deletion src/providers/DefaultLastReleaseResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
tag = await cmd(command);
tag = tag
.split('\n')
.reverse()
.find(t => tagFormatter.IsValid(t) && t !== currentTag) || '';

} else {
Expand Down

0 comments on commit d3ce4be

Please sign in to comment.