Skip to content

Commit

Permalink
Exclude pre-release tags from version consideration
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHatch committed Dec 18, 2022
1 parent ba6e71e commit 02763ed
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 10 deletions.
18 changes: 15 additions & 3 deletions 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.

6 changes: 6 additions & 0 deletions lib/formatting/DefaultTagFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ class DefaultTagFormatter {
return [major, minor, patch];
}
;
IsValid(tag) {
if (!!this.namespace) {
return new RegExp(`^${this.tagPrefix}[0-9]+.[0-9]+.[0-9]+${this.namespaceSeperator}${this.namespace}$`).test(tag);
}
return new RegExp(`^${this.tagPrefix}[0-9]+.[0-9]+.[0-9]+$`).test(tag);
}
}
exports.DefaultTagFormatter = DefaultTagFormatter;
12 changes: 9 additions & 3 deletions lib/providers/DefaultLastReleaseResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ 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').reverse().find(t => t !== '' && t !== currentTag) || '';
tag = tag
.split('\n')
.reverse()
.find(t => tagFormatter.IsValid(t) && t !== currentTag) || '';
}
else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = yield (0, CommandRunner_1.cmd)(command);
const command = `git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
let tags = yield (0, CommandRunner_1.cmd)(command);
tag = tags
.split('\n')
.find(t => tagFormatter.IsValid(t)) || '';
}
tag = tag.trim();
}
Expand Down
8 changes: 8 additions & 0 deletions src/formatting/DefaultTagFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ export class DefaultTagFormatter implements TagFormatter {
return [major, minor, patch];
};

public IsValid(tag: string): boolean {
if (!!this.namespace) {
return new RegExp(`^${this.tagPrefix}[0-9]+.[0-9]+.[0-9]+${this.namespaceSeperator}${this.namespace}$`).test(tag);
}

return new RegExp(`^${this.tagPrefix}[0-9]+.[0-9]+.[0-9]+$`).test(tag);
}

}
1 change: 1 addition & 0 deletions src/formatting/TagFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface TagFormatter {
Format(versionInfo: VersionInformation): string;
GetPattern(): string;
Parse(tag: string): [major: number, minor: number, patch: number];
IsValid(tag: string): boolean;
}
25 changes: 25 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,29 @@ test('Correct previous version is returned when directly tagged', async () => {

expect(result.previousVersion).toBe('2.0.1');
expect(result.formattedVersion).toBe('2.0.2+1');
}, 15000);

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

repo.makeCommit('Initial Commit (MAJOR)');
repo.makeCommit(`Second Commit`);
repo.exec('git tag v1.0.0-alpha.1')
repo.makeCommit(`Third Commit`);
const result = await repo.runAction();

expect(result.formattedVersion).toBe('1.0.0+2');
}, 15000);

test('Prerelease suffixes are ignored when namespaces are set', async () => {
const repo = createTestRepo({ namespace: 'test' });

repo.makeCommit('Initial Commit (MAJOR)');
repo.exec('git tag v1.0.0-test')
repo.makeCommit(`Second Commit`);
repo.exec('git tag v1.0.1-test-alpha.1')
repo.makeCommit(`Third Commit`);
const result = await repo.runAction();

expect(result.formattedVersion).toBe('1.0.1+1');
}, 15000);
12 changes: 9 additions & 3 deletions src/providers/DefaultLastReleaseResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ 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').reverse().find(t => t !== '' && t !== currentTag) || '';
tag = tag
.split('\n')
.reverse()
.find(t => tagFormatter.IsValid(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);
const command = `git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
let tags = await cmd(command);
tag = tags
.split('\n')
.find(t => tagFormatter.IsValid(t)) || '';
}

tag = tag.trim();
Expand Down

0 comments on commit 02763ed

Please sign in to comment.