Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get correct version if prerelease branch shares version with ... #2416

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/get-last-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default ({ 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
);
});