Fix for pre-release tags on current commit

This commit is contained in:
Paul Hatcherian 2023-01-10 17:11:54 -06:00
parent 346a6f2b12
commit 8b3b8f89c6
5 changed files with 137 additions and 3 deletions

1
dist/index.js vendored
View file

@ -746,6 +746,7 @@ class DefaultLastReleaseResolver {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const releasePattern = tagFormatter.GetPattern(); const releasePattern = tagFormatter.GetPattern();
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim(); let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = ''; let tag = '';
try { try {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -45,6 +45,7 @@ class DefaultLastReleaseResolver {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const releasePattern = tagFormatter.GetPattern(); const releasePattern = tagFormatter.GetPattern();
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim(); let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = ''; let tag = '';
try { try {

View file

@ -708,3 +708,132 @@ test('Namespace can contains a slash', async () => {
expect(result.formattedVersion).toBe('0.0.2+1'); expect(result.formattedVersion).toBe('0.0.2+1');
expect(subprojectResult.formattedVersion).toBe('0.1.1+0'); expect(subprojectResult.formattedVersion).toBe('0.1.1+0');
}, 15000); }, 15000);
test('Namespace can contains a dot', async () => {
const repo = createTestRepo({ tagPrefix: '' });
repo.makeCommit('Initial Commit');
repo.exec('git tag 0.0.1');
repo.makeCommit('Second Commit');
repo.exec('git tag 0.1.0-sub.project');
repo.makeCommit('Third Commit');
repo.exec('git tag 0.2.0-sub/project');
repo.makeCommit('fourth Commit');
const result = await repo.runAction();
const subprojectResult = await repo.runAction({ namespace: "sub.project" });
expect(result.formattedVersion).toBe('0.0.2+2');
expect(subprojectResult.formattedVersion).toBe('0.1.1+1');
}, 15000);
test('Patch increments only once', async () => {
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}" });
repo.makeCommit('Initial Commit');
repo.exec('git tag 0.0.1');
const firstResult = await repo.runAction();
repo.makeCommit('Second Commit');
const secondResult = await repo.runAction();
repo.makeCommit('Third Commit');
const thirdResult = await repo.runAction();
repo.makeCommit('fourth Commit');
const fourthResult = await repo.runAction();
expect(firstResult.formattedVersion).toBe('0.0.1');
expect(secondResult.formattedVersion).toBe('0.0.2');
expect(thirdResult.formattedVersion).toBe('0.0.2');
expect(fourthResult.formattedVersion).toBe('0.0.2');
}, 15000);
test('Patch increments each time when bump each commit is set', async () => {
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}", bumpEachCommit: true });
repo.makeCommit('Initial Commit');
repo.exec('git tag 0.0.1');
const firstResult = await repo.runAction();
repo.makeCommit('Second Commit');
const secondResult = await repo.runAction();
repo.makeCommit('Third Commit');
const thirdResult = await repo.runAction();
repo.makeCommit('fourth Commit');
const fourthResult = await repo.runAction();
expect(firstResult.formattedVersion).toBe('0.0.1');
expect(secondResult.formattedVersion).toBe('0.0.2');
expect(thirdResult.formattedVersion).toBe('0.0.3');
expect(fourthResult.formattedVersion).toBe('0.0.4');
}, 15000);
test('Current commit is provided', async () => {
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}" });
repo.makeCommit('Initial Commit');
repo.makeCommit('Second Commit');
repo.makeCommit('Third Commit');
repo.makeCommit('fourth Commit');
repo.exec('git tag 0.0.1');
const result = await repo.runAction();
expect(result.currentCommit).toBeTruthy();
}, 15000);
test('Prerelease tags are ignored on current commit', async () => {
const repo = createTestRepo({
minorPattern: '/.*/'
});
let i = 0;
const validate = async (version: string, changed: boolean = true) => {
const result = await repo.runAction();
expect(result.formattedVersion).toBe(version);
expect(result.changed).toBe(changed);
}
await validate('0.0.0+0', false);
repo.makeCommit(`Commit ${i++}`);
await validate('0.1.0+0');
repo.exec('git tag v0.0.0');
await validate('0.0.0+0', false);
repo.makeCommit(`Commit ${i++}`);
await validate('0.1.0+0');
repo.exec('git tag v1.0.0-rc1');
await validate('0.1.0+0');
repo.makeCommit(`Commit ${i++}`);
await validate('0.1.0+1');
repo.exec('git tag v1.0.0-rc2');
await validate('0.1.0+1');
repo.makeCommit(`Commit ${i++}`);
await validate('0.1.0+2');
repo.exec('git tag v1.0.0-rc3');
await validate('0.1.0+2');
repo.makeCommit(`Commit ${i++}`);
await validate('0.1.0+3');
repo.exec('git tag v1.0.0');
await validate('1.0.0+0', false);
repo.makeCommit(`Commit ${i++}`);
await validate('1.1.0+0');
repo.exec('git tag v1.1.0-rc2');
await validate('1.1.0+0');
repo.makeCommit(`Commit ${i++}`);
await validate('1.1.0+1');
repo.exec('git tag v1.1.0-rc4');
await validate('1.1.0+1');
repo.makeCommit(`Commit ${i++}`);
await validate('1.1.0+2');
repo.exec('git tag v1.1.0-rc8');
await validate('1.1.0+2');
repo.makeCommit(`Commit ${i++}`);
await validate('1.1.0+3');
repo.exec('git tag v1.1.0-rc9');
await validate('1.1.0+3');
repo.makeCommit(`Commit ${i++}`);
await validate('1.1.0+4');
}, 15000);

View file

@ -21,6 +21,9 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
let currentTag = (await cmd( let currentTag = (await cmd(
`git tag --points-at ${current} ${releasePattern}` `git tag --points-at ${current} ${releasePattern}`
)).trim(); )).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = ''; let tag = '';