mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Update tag resolver to use tag order instead of author date
This commit is contained in:
parent
0e3d4652d7
commit
cd16d71443
6 changed files with 126 additions and 13 deletions
13
dist/index.js
vendored
13
dist/index.js
vendored
|
|
@ -868,7 +868,18 @@ class TagLastReleaseResolver {
|
|||
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (yield (0, CommandRunner_1.cmd)('git', `describe`, `--tags`, `--abbrev=0`, `--match=${releasePattern}`, `${current}~1`)).trim();
|
||||
if (!!currentTag) {
|
||||
// If we already have the current branch tagged, we are checking for the previous 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} refs/tags/${releasePattern}`;
|
||||
tag = yield (0, CommandRunner_1.cmd)(command);
|
||||
tag = tag.split('\n').at(-1) || '';
|
||||
}
|
||||
else {
|
||||
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} refs/tags/${releasePattern}`;
|
||||
tag = yield (0, CommandRunner_1.cmd)(command);
|
||||
}
|
||||
tag = tag.trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -47,7 +47,18 @@ class TagLastReleaseResolver {
|
|||
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (yield (0, CommandRunner_1.cmd)('git', `describe`, `--tags`, `--abbrev=0`, `--match=${releasePattern}`, `${current}~1`)).trim();
|
||||
if (!!currentTag) {
|
||||
// If we already have the current branch tagged, we are checking for the previous 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} refs/tags/${releasePattern}`;
|
||||
tag = yield (0, CommandRunner_1.cmd)(command);
|
||||
tag = tag.split('\n').at(-1) || '';
|
||||
}
|
||||
else {
|
||||
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} refs/tags/${releasePattern}`;
|
||||
tag = yield (0, CommandRunner_1.cmd)(command);
|
||||
}
|
||||
tag = tag.trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||

|
||||
|
||||
> *Version 5-alpha now available!*
|
||||
> Version 5 adds support for several new features and allows easier extension/customization. See the [release notes](https://github.com/PaulHatch/semantic-version/releases/tag/v5.0.0-alpha) for more information.
|
||||
> Version 5 adds support for several new features and allows easier extension/customization.
|
||||
> ##### Breaking Changes
|
||||
> - Versions now use the version number (`--sort=-v:*refname`) rather than date to determine which tag is the latest.
|
||||
> - "Short tag" support removed
|
||||
>
|
||||
> See the [release notes](https://github.com/PaulHatch/semantic-version/releases/tag/v5.0.0-alpha) for more information.
|
||||
|
||||
# Git-Based Semantic Versioning
|
||||
|
||||
|
|
|
|||
|
|
@ -337,6 +337,7 @@ test('Changes to multiple monitored path is false when change is not in path', a
|
|||
expect(result.changed).toBe(false);
|
||||
}, 15000);
|
||||
|
||||
|
||||
test('Namespace is tracked separately', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: '' }); // 0.0.0
|
||||
|
||||
|
|
@ -464,3 +465,85 @@ test('Tag prefix can include forward slash', async () => {
|
|||
|
||||
expect(result.formattedVersion).toBe('1.2.3+0');
|
||||
}, 15000);
|
||||
|
||||
test('Tags immediately before merge are detected', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'v' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Commit 1');
|
||||
repo.exec('git tag v1.0.0');
|
||||
repo.makeCommit('Commit 2');
|
||||
repo.exec('git checkout -b feature/branch');
|
||||
repo.makeCommit('Commit 3');
|
||||
repo.makeCommit('Commit 4');
|
||||
repo.exec('git tag v2.0.0');
|
||||
repo.exec('git checkout master');
|
||||
repo.makeCommit('Commit 5');
|
||||
repo.exec('git merge feature/branch');
|
||||
const result = await repo.runAction();
|
||||
|
||||
expect(result.versionTag).toBe('v2.0.1');
|
||||
}, 15000);
|
||||
|
||||
test('Correct tag is detected on merged branches', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'v' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Commit 1');
|
||||
repo.exec('git tag v1.0.0');
|
||||
repo.makeCommit('Commit 2');
|
||||
repo.exec('git checkout -b feature/branch');
|
||||
repo.makeCommit('Commit 3');
|
||||
repo.exec('git tag v2.0.0');
|
||||
repo.makeCommit('Commit 4');
|
||||
repo.exec('git checkout master');
|
||||
repo.makeCommit('Commit 5');
|
||||
repo.exec('git merge feature/branch');
|
||||
const result = await repo.runAction();
|
||||
|
||||
expect(result.versionTag).toBe('v2.0.1');
|
||||
}, 15000);
|
||||
|
||||
test('Correct tag is detected on multiple branches', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'v' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Commit 1');
|
||||
repo.exec('git checkout -b feature/branch1');
|
||||
repo.exec('git tag v1.0.0');
|
||||
repo.makeCommit('Commit 2');
|
||||
repo.exec('git checkout master');
|
||||
repo.exec('git merge feature/branch1');
|
||||
repo.exec('git checkout -b feature/branch2');
|
||||
repo.makeCommit('Commit 3');
|
||||
repo.exec('git tag v2.0.0');
|
||||
repo.makeCommit('Commit 4');
|
||||
repo.exec('git checkout master');
|
||||
repo.makeCommit('Commit 5');
|
||||
repo.exec('git merge feature/branch2');
|
||||
const result = await repo.runAction();
|
||||
|
||||
expect(result.versionTag).toBe('v2.0.1');
|
||||
}, 15000);
|
||||
|
||||
test('Correct tag is detected when versions pass 10s place', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'v' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Commit 1');
|
||||
repo.exec('git checkout -b feature/branch1');
|
||||
repo.exec('git tag v10.15.0');
|
||||
repo.makeCommit('Commit 2');
|
||||
repo.exec('git checkout master');
|
||||
repo.exec('git merge feature/branch1');
|
||||
repo.exec('git checkout -b feature/branch2');
|
||||
repo.makeCommit('Commit 3');
|
||||
repo.exec('git tag v10.7.0');
|
||||
repo.makeCommit('Commit 4');
|
||||
repo.exec('git checkout master');
|
||||
repo.makeCommit('Commit 5');
|
||||
repo.exec('git merge feature/branch2');
|
||||
const result = await repo.runAction();
|
||||
|
||||
expect(result.versionTag).toBe('v10.15.1');
|
||||
}, 15000);
|
||||
|
|
@ -21,17 +21,20 @@ export class TagLastReleaseResolver implements LastReleaseResolver {
|
|||
)).trim();
|
||||
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
|
||||
|
||||
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (await cmd(
|
||||
'git',
|
||||
`describe`,
|
||||
`--tags`,
|
||||
`--abbrev=0`,
|
||||
`--match=${releasePattern}`,
|
||||
`${current}~1`
|
||||
)).trim();
|
||||
if (!!currentTag) {
|
||||
// If we already have the current branch tagged, we are checking for the previous 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} refs/tags/${releasePattern}`;
|
||||
tag = await cmd(command);
|
||||
tag = tag.split('\n').at(-1) || '';
|
||||
} else {
|
||||
const command = `git for-each-ref --count=1 --sort=-v:*refname --format=%(refname:short) --merged=${current} refs/tags/${releasePattern}`;
|
||||
tag = await cmd(command);
|
||||
}
|
||||
|
||||
tag = tag.trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
|
|
|
|||
Loading…
Reference in a new issue