diff --git a/.gitignore b/.gitignore index 2a817db61..98062e8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/packages/core/src/__tests__/git.test.ts b/packages/core/src/__tests__/git.test.ts index 61acb5694..604538986 100644 --- a/packages/core/src/__tests__/git.test.ts +++ b/packages/core/src/__tests__/git.test.ts @@ -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 = [ diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 2a09dc0cd..d500ae6fa 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -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;