Exclude pre-release tags from version consideration

This commit is contained in:
Paul Hatcherian 2022-12-17 19:56:43 -06:00
parent ba6e71e658
commit 02763ed6d3
8 changed files with 74 additions and 10 deletions

18
dist/index.js vendored
View file

@ -286,6 +286,12 @@ class DefaultTagFormatter {
return [major, minor, patch]; 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; exports.DefaultTagFormatter = DefaultTagFormatter;
@ -745,11 +751,17 @@ class DefaultLastReleaseResolver {
// so that we will have an accurate increment (assuming the new tag is the expected one) // 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}`; 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 = 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 { else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`; const command = `git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = yield (0, CommandRunner_1.cmd)(command); let tags = yield (0, CommandRunner_1.cmd)(command);
tag = tags
.split('\n')
.find(t => tagFormatter.IsValid(t)) || '';
} }
tag = tag.trim(); tag = tag.trim();
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -42,5 +42,11 @@ class DefaultTagFormatter {
return [major, minor, patch]; 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; exports.DefaultTagFormatter = DefaultTagFormatter;

View file

@ -54,11 +54,17 @@ class DefaultLastReleaseResolver {
// so that we will have an accurate increment (assuming the new tag is the expected one) // 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}`; 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 = 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 { else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`; const command = `git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = yield (0, CommandRunner_1.cmd)(command); let tags = yield (0, CommandRunner_1.cmd)(command);
tag = tags
.split('\n')
.find(t => tagFormatter.IsValid(t)) || '';
} }
tag = tag.trim(); tag = tag.trim();
} }

View file

@ -61,4 +61,12 @@ export class DefaultTagFormatter implements TagFormatter {
return [major, minor, patch]; 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);
}
} }

View file

@ -4,4 +4,5 @@ export interface TagFormatter {
Format(versionInfo: VersionInformation): string; Format(versionInfo: VersionInformation): string;
GetPattern(): string; GetPattern(): string;
Parse(tag: string): [major: number, minor: number, patch: number]; Parse(tag: string): [major: number, minor: number, patch: number];
IsValid(tag: string): boolean;
} }

View file

@ -666,4 +666,29 @@ test('Correct previous version is returned when directly tagged', async () => {
expect(result.previousVersion).toBe('2.0.1'); expect(result.previousVersion).toBe('2.0.1');
expect(result.formattedVersion).toBe('2.0.2+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); }, 15000);

View file

@ -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) // 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}`; const command = `git for-each-ref --count=2 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = await cmd(command); 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 { } else {
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`; const command = `git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}`;
tag = await cmd(command); let tags = await cmd(command);
tag = tags
.split('\n')
.find(t => tagFormatter.IsValid(t)) || '';
} }
tag = tag.trim(); tag = tag.trim();