Skip to content

Commit

Permalink
fix: get correct version if prerelease branch shares version with oth…
Browse files Browse the repository at this point in the history
…er branches

Fix #2415
  • Loading branch information
Tlepel committed Dec 13, 2022
1 parent fa241a2 commit 15aad9e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/get-last-release.js
Expand Up @@ -30,7 +30,11 @@ module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
const [{version, gitTag, channels} = {}] = branch.tags
.filter(
(tag) =>
((branch.type === 'prerelease' && tag.channels.some((channel) => isSameChannel(branch.channel, channel))) ||
((branch.type === 'prerelease' &&
tag.channels.some((channel) => isSameChannel(branch.channel, channel)) &&
semver
.parse(tag.version)
.prerelease.includes(branch.prerelease === true ? branch.name : branch.prerelease)) ||
!semver.prerelease(tag.version)) &&
(isUndefined(before) || semver.lt(tag.version, before))
)
Expand Down
37 changes: 37 additions & 0 deletions test/get-last-release.test.js
Expand Up @@ -43,6 +43,43 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere
});
});

test('Get the correct prerelease tag, when other prereleases share the same git HEAD', (t) => {
const testConfig = {
branch: {
name: 'alpha',
prerelease: 'alpha',
channel: 'alpha',
tags: [
{version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1', gitHead: 'v1.0.0-beta.1', channels: ['beta']},
{version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2', gitHead: 'v1.0.0-alpha.1', channels: ['alpha', 'beta']},
{version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1', gitHead: 'v1.0.0-alpha.1', channels: ['alpha', 'beta']},
],
type: 'prerelease',
},
options: {tagFormat: `v\${version}`, debug: true},
};
const firstResult = getLastRelease(testConfig);

t.deepEqual(firstResult, {
version: '1.0.0-alpha.1',
gitTag: 'v1.0.0-alpha.1',
name: 'v1.0.0-alpha.1',
gitHead: 'v1.0.0-alpha.1',
channels: ['alpha', 'beta'],
});

testConfig.branch.prerelease = true;
const secondResult = getLastRelease(testConfig);

t.deepEqual(secondResult, {
version: '1.0.0-alpha.1',
gitTag: 'v1.0.0-alpha.1',
name: 'v1.0.0-alpha.1',
gitHead: 'v1.0.0-alpha.1',
channels: ['alpha', 'beta'],
});
});

test('Return empty object if no valid tag is found', (t) => {
const result = getLastRelease({
branch: {
Expand Down
21 changes: 21 additions & 0 deletions test/get-next-version.test.js
Expand Up @@ -275,3 +275,24 @@ test('Increase version for release on prerelease branch when there is no regular
'1.0.0-beta.2'
);
});

test('Increase patch when previous version shares HEAD with other releases', (t) => {
t.is(
getNextVersion({
branch: {
name: 'alpha',
type: 'prerelease',
prerelease: 'alpha',
tags: [
{gitTag: 'v1.0.0-beta.1', version: '1.0.0-beta.1', channels: ['beta']},
{gitTag: 'v1.0.0-beta.2', version: '1.0.0-beta.2', channels: ['alpha', 'beta']},
{gitTag: 'v1.0.0-alpha.1', version: '1.0.0-alpha.1', channels: ['alpha', 'beta']},
],
},
nextRelease: {type: 'patch', channel: 'alpha'},
lastRelease: {version: 'v1.0.0-alpha.1', channels: ['alpha', 'beta']},
logger: t.context.logger,
}),
'1.0.0-alpha.2'
);
});

0 comments on commit 15aad9e

Please sign in to comment.