Skip to content

Commit

Permalink
Merge pull request #87 from PaulHatch/pre-release-tagged-commits-fix
Browse files Browse the repository at this point in the history
Fix for pre-release tags on current commit
  • Loading branch information
PaulHatch authored Jan 10, 2023
2 parents 346a6f2 + 8b3b8f8 commit 61243c9
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 3 deletions.
1 change: 1 addition & 0 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.

1 change: 1 addition & 0 deletions lib/providers/DefaultLastReleaseResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DefaultLastReleaseResolver {
return __awaiter(this, void 0, void 0, function* () {
const releasePattern = tagFormatter.GetPattern();
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];
let tag = '';
try {
Expand Down
133 changes: 131 additions & 2 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ test('Current tag is used', async () => {
}, 15000);

test('Bump each commit works', async () => {

const repo = createTestRepo({ tagPrefix: '', bumpEachCommit: true }); // 0.0.0

expect((await repo.runAction()).formattedVersion).toBe('0.0.0+0');
Expand Down Expand Up @@ -651,7 +651,7 @@ test('Correct previous version is returned when using branches', async () => {
const result = await repo.runAction();

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

test('Correct previous version is returned when directly tagged', async () => {
Expand Down Expand Up @@ -707,4 +707,133 @@ test('Namespace can contains a slash', async () => {

expect(result.formattedVersion).toBe('0.0.2+1');
expect(subprojectResult.formattedVersion).toBe('0.1.1+0');
}, 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);
3 changes: 3 additions & 0 deletions src/providers/DefaultLastReleaseResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
let currentTag = (await cmd(
`git tag --points-at ${current} ${releasePattern}`
)).trim();

currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';

const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];

let tag = '';
Expand Down

0 comments on commit 61243c9

Please sign in to comment.