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: prefer prerelease tags when determining latest #1812

Merged
merged 3 commits into from Feb 18, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -215,4 +215,7 @@ GitHub.sublime-settings
.history

# End of https://www.gitignore.io/api/node,intellij,sublimetext,visualstudiocode

### Files generated from testing ###
packages/cli/auto
docs/public/search-index.json
25 changes: 25 additions & 0 deletions packages/core/src/__tests__/git.test.ts
Expand Up @@ -167,6 +167,31 @@ describe("github", () => {
);
});

test("will prefer latest tags from prerelease branch if available", async () => {
const gh = new Git(options);

gh.getTags = (ref: string) => {
if (ref === "origin/main") {
return Promise.resolve(["1.0.0", "1.2.3", "1.4.0"]);
}

return Promise.resolve([
"1.0.0",
"1.2.3",
"1.4.0",
"1.4.1-beta.0",
"1.4.1-beta.1",
"1.4.1-beta.2",
"1.4.1-alpha.0",
"1.4.1-alpha.1",
]);
};

expect(await gh.getTagNotInBaseBranch("alpha")).toBe("1.4.1-alpha.1");

expect(await gh.getTagNotInBaseBranch("beta")).toBe("1.4.1-beta.2");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is 🔥

});

test("handles tags with package names", async () => {
const baseTags = ["@monorepo/models@2.0.0", "@monorepo/core@2.0.0"];
const branchTags = [
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/git.ts
Expand Up @@ -904,7 +904,15 @@ export default class Git {
const baseTags = (
await this.getTags(`origin/${this.options.baseBranch}`)
).reverse();
const branchTags = (await this.getTags(`heads/${branch}`)).reverse();
let branchTags = (await this.getTags(`heads/${branch}`)).reverse();
const branchTagsWithPrereleaseSuffix = branchTags.filter(
(tag) => tag.indexOf(`-${branch.toLowerCase()}`) >= 0
);

if (branchTagsWithPrereleaseSuffix.length) {
branchTags = branchTagsWithPrereleaseSuffix;
}

const comparator = options.first ? lt : gt;
let firstGreatestUnique: string | undefined;

Expand Down