Skip to content

Commit

Permalink
Merge pull request #1812 from lshadler/fix-prefer-prerelease-tags
Browse files Browse the repository at this point in the history
fix: prefer prerelease tags when determining latest
  • Loading branch information
hipstersmoothie committed Feb 18, 2021
2 parents 63d64e0 + 46ea98f commit 1a26fdd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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");
});

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

0 comments on commit 1a26fdd

Please sign in to comment.