From 7fb303a5f643a9fbbeadd735063bbb4b2a80791e Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Wed, 20 Jan 2021 11:43:37 -0800 Subject: [PATCH] use `main` branch if it exists --- docs/pages/docs/configuration/autorc.mdx | 1 + docs/pages/docs/extras/shipit.md | 4 +- packages/cli/src/parse-args.ts | 4 +- .../__tests__/__snapshots__/auto.test.ts.snap | 4 +- .../__snapshots__/changelog.test.ts.snap | 12 +- .../__snapshots__/release.test.ts.snap | 6 +- .../src/__tests__/auto-canary-local.test.ts | 2 +- .../src/__tests__/auto-ci-base-branch.test.ts | 7 +- .../src/__tests__/auto-make-changelog.test.ts | 2 +- packages/core/src/__tests__/auto.test.ts | 30 +++-- packages/core/src/__tests__/changelog.test.ts | 16 +-- .../core/src/__tests__/get-remote.test.ts | 13 +++ packages/core/src/__tests__/git.test.ts | 10 +- packages/core/src/__tests__/release.test.ts | 103 ++++++++++-------- packages/core/src/__tests__/semver.test.ts | 2 +- packages/core/src/auto-args.ts | 6 +- packages/core/src/auto.ts | 68 ++++++++---- packages/core/src/changelog.ts | 2 +- packages/core/src/git.ts | 6 +- packages/core/src/release.ts | 11 +- packages/core/src/types.ts | 4 +- .../src/utils/__tests__/verify-auth.test.ts | 6 +- packages/core/src/utils/get-current-branch.ts | 2 +- plugins/crates/__tests__/crates.test.ts | 4 +- plugins/docker/__tests__/docker.test.ts | 4 +- plugins/jira/__tests__/jira.test.ts | 2 +- plugins/npm/__tests__/monorepo-log.test.ts | 10 +- plugins/npm/__tests__/npm-next.test.ts | 22 ++-- plugins/npm/__tests__/npm.test.ts | 78 ++++++------- plugins/npm/src/index.ts | 6 +- .../released/__tests__/released-label.test.ts | 2 +- 31 files changed, 252 insertions(+), 197 deletions(-) diff --git a/docs/pages/docs/configuration/autorc.mdx b/docs/pages/docs/configuration/autorc.mdx index 9d1e336262..d3a8c13abe 100644 --- a/docs/pages/docs/configuration/autorc.mdx +++ b/docs/pages/docs/configuration/autorc.mdx @@ -38,6 +38,7 @@ Configure the default release behavior. ### Base Branch Configure what your repo considers the base branch. +Defaults to either `main` or `master`. ```json { diff --git a/docs/pages/docs/extras/shipit.md b/docs/pages/docs/extras/shipit.md index 28fde84e99..85480ad872 100644 --- a/docs/pages/docs/extras/shipit.md +++ b/docs/pages/docs/extras/shipit.md @@ -42,8 +42,8 @@ Read more about preparing you project for pre-releases [here](./next#setting-up- #### "next" Branch (default) -The suggested way to create pre-releases is by managing 2 branches for your repo: `master` and `next`. -`master` contains the `latest` stable version of the code, and `next` contains future updates. +The suggested way to create pre-releases is by managing 2 branches for your repo: `baseBranch` and `next`. +`baseBranch` contains the `latest` stable version of the code, and `next` contains future updates. You can change what branches `auto` treats as pre-release branches in your [`.autorc`](../configuration/autorc#prerelease-branches). diff --git a/packages/cli/src/parse-args.ts b/packages/cli/src/parse-args.ts index 1230717f37..e0e31ccec5 100644 --- a/packages/cli/src/parse-args.ts +++ b/packages/cli/src/parse-args.ts @@ -129,7 +129,7 @@ const defaultOptions: AutoOption[] = [ const baseBranch: AutoOption = { name: "base-branch", type: String, - description: 'Branch to treat as the "master" branch', + description: "Branch to treat as the base branch", group: "global", }; @@ -515,7 +515,7 @@ export const commands: AutoCommand[] = [ defaultValue: false, group: "main", description: - 'Make auto publish prerelease versions when merging to master. Only PRs merged with "release" label will generate a "latest" release. Only use this flag if you do not want to maintain a prerelease branch, and instead only want to use master.', + 'Make auto publish prerelease versions when merging to baseBranch. Only PRs merged with "release" label will generate a "latest" release. Only use this flag if you do not want to maintain a prerelease branch, and instead only want to use baseBranch.', config: true, }, ], diff --git a/packages/core/src/__tests__/__snapshots__/auto.test.ts.snap b/packages/core/src/__tests__/__snapshots__/auto.test.ts.snap index f9ed08b7e1..9c5c8d3d69 100644 --- a/packages/core/src/__tests__/__snapshots__/auto.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/auto.test.ts.snap @@ -84,7 +84,7 @@ exports[`Auto createLabels should create the labels 1`] = ` exports[`Auto should extend config 1`] = ` Object { - "baseBranch": "master", + "baseBranch": "main", "extends": "@artsy/auto-config/package.json", "labels": Array [ Object { @@ -171,7 +171,7 @@ Object { exports[`Auto should extend local config 1`] = ` Object { - "baseBranch": "master", + "baseBranch": "main", "extends": "fake.json", "labels": Array [ Object { diff --git a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap index f9905d86c1..edacfbf523 100644 --- a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap @@ -78,7 +78,7 @@ exports[`generateReleaseNotes should add "Push to Next" 1`] = ` #### ⚠️ Pushed to \`next\` -- I was a push to master (adam@dierkens.com) +- I was a push to main (adam@dierkens.com) #### Authors: 1 @@ -110,7 +110,7 @@ exports[`generateReleaseNotes should be able to customize pushToBaseBranch title #### Custom Title -- I was a push to master (adam@dierkens.com) +- I was a push to main (adam@dierkens.com) #### Authors: 1 @@ -183,9 +183,9 @@ exports[`generateReleaseNotes should include PR-less commits as patches 1`] = ` - First Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) (adam@dierkens.com) -#### ⚠️ Pushed to \`master\` +#### ⚠️ Pushed to \`main\` -- I was a push to master (adam@dierkens.com) +- I was a push to main (adam@dierkens.com) #### Authors: 1 @@ -195,7 +195,7 @@ exports[`generateReleaseNotes should include PR-less commits as patches 1`] = ` exports[`generateReleaseNotes should include PR-less commits as the default label 1`] = ` "#### 🚀 Enhancement -- I was a push to master (adam@dierkens.com) +- I was a push to main (adam@dierkens.com) - First Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) (adam@dierkens.com) #### Authors: 1 @@ -298,7 +298,7 @@ exports[`generateReleaseNotes should order the section major, minor, patch, then #### 🐛 Bug Fix -- I was a push to master (adam@dierkens.com) +- I was a push to main (adam@dierkens.com) #### 📝 Documentation diff --git a/packages/core/src/__tests__/__snapshots__/release.test.ts.snap b/packages/core/src/__tests__/__snapshots__/release.test.ts.snap index 710523cb4f..f420cf22b3 100644 --- a/packages/core/src/__tests__/__snapshots__/release.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/release.test.ts.snap @@ -76,7 +76,7 @@ exports[`Release generateReleaseNotes should include PR-less commits 1`] = ` - First Feature [#1235](https://github.com/web/site/pull/1235) (adam@dierkens.com) -#### ⚠️ Pushed to \`master\` +#### ⚠️ Pushed to \`main\` - I should be included (adam@dierkens.com) @@ -116,9 +116,9 @@ exports[`Release generateReleaseNotes should match rebased commits to PRs 1`] = - Feature [#124](https://github.com/web/site/pull/124) (adam@dierkens.com) - I was rebased [#123](https://github.com/web/site/pull/123) (adam@dierkens.com) -#### ⚠️ Pushed to \`master\` +#### ⚠️ Pushed to \`main\` -- I am a commit to master (adam@dierkens.com) +- I am a commit to main (adam@dierkens.com) #### Authors: 1 diff --git a/packages/core/src/__tests__/auto-canary-local.test.ts b/packages/core/src/__tests__/auto-canary-local.test.ts index ab5ac0e048..c3165c1f81 100644 --- a/packages/core/src/__tests__/auto-canary-local.test.ts +++ b/packages/core/src/__tests__/auto-canary-local.test.ts @@ -31,7 +31,7 @@ jest.mock("@octokit/rest", () => { return { Octokit }; }); -test("shipit should publish canary in locally when not on master", async () => { +test("shipit should publish canary in locally when not on baseBranch", async () => { const auto = new Auto({ ...defaults, plugins: [] }); auto.logger = dummyLog(); // @ts-ignore diff --git a/packages/core/src/__tests__/auto-ci-base-branch.test.ts b/packages/core/src/__tests__/auto-ci-base-branch.test.ts index 927ca70e5b..ecced0a633 100644 --- a/packages/core/src/__tests__/auto-ci-base-branch.test.ts +++ b/packages/core/src/__tests__/auto-ci-base-branch.test.ts @@ -6,12 +6,13 @@ jest.mock("env-ci"); const envSpy = envCi as jest.Mock; envSpy.mockImplementation(() => ({ isCi: true, - branch: "master", + branch: "main", })); import { Auto } from "../auto"; const defaults = { + baseBranch: "main", owner: "foo", repo: "bar", }; @@ -51,13 +52,13 @@ describe("Auto", () => { url: "https://google.com", }; - test("should exit successfully if ran from master + CI", async () => { + test("should exit successfully if ran from main + CI", async () => { const auto = new Auto(defaults); const exit = jest.fn(); envSpy.mockImplementationOnce(() => ({ isCi: true, - branch: "master", + branch: "main", })); // @ts-ignore diff --git a/packages/core/src/__tests__/auto-make-changelog.test.ts b/packages/core/src/__tests__/auto-make-changelog.test.ts index 22c42f0092..0ef1808208 100644 --- a/packages/core/src/__tests__/auto-make-changelog.test.ts +++ b/packages/core/src/__tests__/auto-make-changelog.test.ts @@ -10,7 +10,7 @@ jest const importMock = jest.fn(); jest.mock("import-cwd", () => (path: string) => importMock(path)); -jest.mock("env-ci", () => () => ({ isCi: false, branch: "master" })); +jest.mock("env-ci", () => () => ({ isCi: false, branch: "main" })); jest.mock("../utils/exec-promise", () => () => Promise.resolve("")); const defaults = { diff --git a/packages/core/src/__tests__/auto.test.ts b/packages/core/src/__tests__/auto.test.ts index 31e185e463..0d7a897c91 100644 --- a/packages/core/src/__tests__/auto.test.ts +++ b/packages/core/src/__tests__/auto.test.ts @@ -5,6 +5,13 @@ import { dummyLog } from "../utils/logger"; import makeCommitFromMsg from "./make-commit-from-msg"; import { loadPlugin } from "../utils/load-plugins"; import child from "child_process"; +import execPromise from "../utils/exec-promise"; + +const exec = jest.fn(); +jest.mock("../utils/exec-promise"); +// @ts-ignore +execPromise.mockImplementation(exec); +exec.mockResolvedValue(""); const importMock = jest.fn(); @@ -12,9 +19,10 @@ jest.mock("../utils/git-reset.ts"); jest.mock("../utils/load-plugins.ts"); jest.mock("../utils/verify-auth.ts", () => () => true); jest.mock("import-cwd", () => (path: string) => importMock(path)); -jest.mock("env-ci", () => () => ({ isCi: false, branch: "master" })); +jest.mock("env-ci", () => () => ({ isCi: false, branch: "main" })); const defaults = { + baseBranch: "main", owner: "foo", repo: "bar", }; @@ -114,7 +122,7 @@ describe("Auto", () => { const auto = new Auto(); auto.logger = dummyLog(); await auto.loadConfig(); - expect(auto.baseBranch).toBe("master"); + expect(auto.baseBranch).toBe("main"); }); test("should set custom baseBranch", async () => { @@ -162,9 +170,11 @@ describe("Auto", () => { process.pkg = undefined; }); - test("should throw if now GH_TOKEN set", async () => { + test("should throw if no GH_TOKEN set", async () => { const auto = new Auto(); auto.logger = dummyLog(); + // @ts-ignore + auto.getRepo = () => ({}); process.env.GH_TOKEN = undefined; await expect(auto.loadConfig()).rejects.toBeInstanceOf(Error); process.env.GH_TOKEN = "XXXX"; @@ -187,7 +197,7 @@ describe("Auto", () => { test("should exit with errors in config", async () => { search.mockReturnValueOnce({ config: { name: 123 } }); process.exit = jest.fn() as any; - const auto = new Auto(); + const auto = new Auto({ owner: "foo", repo: "bar" }); auto.logger = dummyLog(); await auto.loadConfig(); expect(process.exit).toHaveBeenCalled(); @@ -1426,12 +1436,16 @@ describe("Auto", () => { }); test("should not publish when behind remote", async () => { - jest.spyOn(child, "execSync").mockImplementation((command) => { - if (command.startsWith("git")) { - throw new Error(); + exec.mockImplementation((command, args) => { + if ( + command.startsWith("git") && + args[0] === "ls-remote" && + args[1] === "--heads" + ) { + return Promise.reject(new Error()); } - return Buffer.from(""); + return Promise.resolve(""); }); const auto = new Auto({ ...defaults, plugins: [] }); diff --git a/packages/core/src/__tests__/changelog.test.ts b/packages/core/src/__tests__/changelog.test.ts index d758da1c01..9987250033 100644 --- a/packages/core/src/__tests__/changelog.test.ts +++ b/packages/core/src/__tests__/changelog.test.ts @@ -15,7 +15,7 @@ const testOptions = (): IGenerateReleaseNotesOptions => ({ repo: "auto", baseUrl: "https://github.custom.com/foobar/auto", labels: [...defaultLabels], - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); @@ -28,7 +28,7 @@ describe("createUserLink", () => { repo: "", baseUrl: "https://github.custom.com/", labels: [...defaultLabels], - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); changelog.loadDefaultHooks(); @@ -68,7 +68,7 @@ describe("createUserLink", () => { repo: "", baseUrl: "https://github.custom.com/", labels: [...defaultLabels], - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); changelog.loadDefaultHooks(); @@ -345,7 +345,7 @@ describe("generateReleaseNotes", () => { files: [], authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I was a push to master\n\nfoo bar", + subject: "I was a push to main\n\nfoo bar", labels: ["pushToBaseBranch"], }, { @@ -376,7 +376,7 @@ describe("generateReleaseNotes", () => { files: [], authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I was a push to master\n\nfoo bar", + subject: "I was a push to main\n\nfoo bar", }, { hash: "2", @@ -402,7 +402,7 @@ describe("generateReleaseNotes", () => { files: [], authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I was a push to master\n\n", + subject: "I was a push to main\n\n", labels: ["pushToBaseBranch"], }, { @@ -454,7 +454,7 @@ describe("generateReleaseNotes", () => { files: [], authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I was a push to master\n\n", + subject: "I was a push to main\n\n", labels: ["patch"], }, { @@ -543,7 +543,7 @@ describe("generateReleaseNotes", () => { files: [], authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I was a push to master\n\n", + subject: "I was a push to main\n\n", labels: ["pushToBaseBranch"], }, { diff --git a/packages/core/src/__tests__/get-remote.test.ts b/packages/core/src/__tests__/get-remote.test.ts index ffc633edf2..76f17d9bdf 100644 --- a/packages/core/src/__tests__/get-remote.test.ts +++ b/packages/core/src/__tests__/get-remote.test.ts @@ -1,4 +1,10 @@ import { Auto } from "../auto"; +import { execSync } from "child_process"; + +const exec = jest.fn(); +// @ts-ignore +execSync.mockImplementation(exec); +exec.mockReturnValue(""); jest.mock("child_process"); @@ -69,4 +75,11 @@ describe("getRemote", () => { "https://x-access-token:XXXX@github.com/fake/remote" ); }); + + test("should use main if it exists", async () => { + exec.mockReturnValue("foo\nbar\nbaz\nmain"); + const auto = new Auto(); + + expect(auto.baseBranch).toBe("main"); + }); }); diff --git a/packages/core/src/__tests__/git.test.ts b/packages/core/src/__tests__/git.test.ts index 2a1d7e7c81..61acb5694e 100644 --- a/packages/core/src/__tests__/git.test.ts +++ b/packages/core/src/__tests__/git.test.ts @@ -88,7 +88,7 @@ const options = { owner: "Adam Dierkens", repo: "test", token: "MyToken", - baseBranch: "master", + baseBranch: "main", }; describe("github", () => { @@ -129,7 +129,7 @@ describe("github", () => { const gh = new Git(options); gh.getTags = (ref: string) => { - if (ref === "origin/master") { + if (ref === "origin/main") { return Promise.resolve(["1.0.0", "1.2.3", "1.4.0"]); } @@ -149,7 +149,7 @@ describe("github", () => { const gh = new Git(options); gh.getTags = (ref: string) => { - if (ref === "origin/master") { + if (ref === "origin/main") { return Promise.resolve(["1.0.0", "1.2.3", "1.4.0"]); } @@ -179,7 +179,7 @@ describe("github", () => { const gh = new Git(options); gh.getTags = (ref: string) => { - if (ref === "origin/master") { + if (ref === "origin/main") { return Promise.resolve(baseTags); } @@ -280,7 +280,7 @@ describe("github", () => { test("getTags", async () => { const gh = new Git(options); - expect(Array.isArray(await gh.getTags("master"))).toBe(true); + expect(Array.isArray(await gh.getTags("main"))).toBe(true); }); test("getLastTagNotInBaseBranch", async () => { diff --git a/packages/core/src/__tests__/release.test.ts b/packages/core/src/__tests__/release.test.ts index 16ccfec0fb..ad9077e7b9 100644 --- a/packages/core/src/__tests__/release.test.ts +++ b/packages/core/src/__tests__/release.test.ts @@ -6,6 +6,7 @@ import { dummyLog } from "../utils/logger"; import makeCommitFromMsg from "./make-commit-from-msg"; import child from "child_process"; import { getCurrentBranch } from "../utils/get-current-branch"; +import { DEFAULT_PRERELEASE_BRANCHES } from "../config"; const { execSync } = child; const exec = jest.fn(); @@ -91,7 +92,7 @@ const execSpy = jest.fn(); jest.mock("../utils/exec-promise.ts", () => (...args) => execSpy(...args)); const currentBranch = jest.fn(); -currentBranch.mockReturnValue("master"); +currentBranch.mockReturnValue("main"); jest.mock("../utils/get-current-branch.ts"); // @ts-ignore getCurrentBranch.mockImplementation(currentBranch); @@ -101,6 +102,12 @@ const writeSpy = jest.fn(); let readResult = "{}"; +const config = { + baseBranch: "main", + prereleaseBranches: DEFAULT_PRERELEASE_BRANCHES, + labels: defaultLabels, +}; + jest.mock("fs", () => ({ // @ts-ignore existsSync: (...args) => existsSync(...args), @@ -123,7 +130,7 @@ const git = new Git({ owner: "Andrew", repo: "test", token: "MY_TOKEN", - baseBranch: "master", + baseBranch: "main", }); describe("getVersionMap", () => { @@ -158,13 +165,13 @@ describe("Release", () => { describe("getCommits", () => { test("should default to HEAD", async () => { - const gh = new Release(git); + const gh = new Release(git, config); await gh.getCommits("12345"); expect(getGitLog).toHaveBeenCalled(); }); test("should use configured HEAD", async () => { - const gh = new Release(git); + const gh = new Release(git, config); await gh.getCommits("12345", "1234"); expect(getGitLog).toHaveBeenCalled(); }); @@ -177,7 +184,7 @@ describe("Release", () => { ]; getGitLog.mockReturnValueOnce(commits); - const gh = new Release(git); + const gh = new Release(git, config); expect(await gh.getCommits("12345", "1234")).toMatchSnapshot(); }); @@ -223,7 +230,7 @@ describe("Release", () => { }; }); - const gh = new Release(git); + const gh = new Release(git, config); const modifiedCommits = await gh.getCommits("12345", "1234"); expect(getUserByUsername).toHaveBeenCalled(); expect(modifiedCommits).toMatchSnapshot(); @@ -271,7 +278,7 @@ describe("Release", () => { }; }); - const gh = new Release(git); + const gh = new Release(git, config); gh.hooks.onCreateLogParse.tap("test", (parser) => { parser.hooks.omitCommit.tap("test", (commit) => Boolean(commit.authors.find((author) => author.username === "adam")) @@ -282,7 +289,7 @@ describe("Release", () => { }); test("should ignore rebased commits if no last release", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getLatestReleaseInfo.mockReturnValueOnce({}); const commits = await logParse.normalizeCommits([ @@ -295,7 +302,7 @@ describe("Release", () => { }); test("should match rebased commits to PRs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getLatestReleaseInfo.mockReturnValueOnce({ published_at: "2019-01-16", @@ -327,7 +334,7 @@ describe("Release", () => { }); test("should match rebased commits to PRs with first commit", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getLatestReleaseInfo.mockImplementationOnce(() => { throw new Error("no releases yet"); @@ -360,7 +367,7 @@ describe("Release", () => { }); test("should omit commits that have already been released", async () => { - const gh = new Release(git); + const gh = new Release(git, config); jest.spyOn(console, "log").mockImplementationOnce(() => {}); getLatestReleaseInfo.mockReturnValueOnce({ @@ -391,7 +398,7 @@ describe("Release", () => { }); test("should not omit commits in next branch", async () => { - const gh = new Release(git); + const gh = new Release(git, config); jest.spyOn(console, "log").mockImplementationOnce(() => {}); getLatestReleaseInfo.mockReturnValueOnce({ @@ -425,7 +432,7 @@ describe("Release", () => { }); test("should include PR opener in authors (in case of external rebase)", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const info = { data: { @@ -456,7 +463,7 @@ describe("Release", () => { }); test("should use latest title of PR", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const info = { data: { @@ -491,7 +498,7 @@ describe("Release", () => { describe("addToChangelog", () => { test("creates new changelog if one didn't exist - from 0", async () => { - const gh = new Release(git); + const gh = new Release(git, config); await gh.addToChangelog( "# My new Notes", "klajsdlfk4lj51l43k5hj234l", @@ -502,7 +509,7 @@ describe("Release", () => { }); test("creates new changelog if one didn't exist", async () => { - const gh = new Release(git); + const gh = new Release(git, config); await gh.addToChangelog("# My new Notes", "v1.0.0", "v1.0.0"); expect(writeSpy.mock.calls[0][1].includes(`v1.0.1`)).toBe(true); @@ -513,7 +520,7 @@ describe("Release", () => { noVersionPrefix: true, prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); await gh.addToChangelog("# My new Notes", "1.0.0", "1.0.0"); @@ -521,7 +528,7 @@ describe("Release", () => { }); test("prepends to old changelog", async () => { - const gh = new Release(git); + const gh = new Release(git, config); existsSync.mockReturnValueOnce(true); readResult = "# My old Notes"; @@ -537,17 +544,17 @@ describe("Release", () => { describe("generateReleaseNotes", () => { test("should default to HEAD", async () => { - const gh = new Release(git); + const gh = new Release(git, config); expect(await gh.generateReleaseNotes("1234")).toBe(""); }); test("should use configured HEAD", async () => { - const gh = new Release(git); + const gh = new Release(git, config); expect(await gh.generateReleaseNotes("1234", "123")).toBe(""); }); test("should include PR-less commits", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ { @@ -603,7 +610,7 @@ describe("Release", () => { }); test("should get extra user data for login", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ { @@ -631,7 +638,7 @@ describe("Release", () => { }); test("should allow user to configure section headings", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First (#1234)"), @@ -652,7 +659,7 @@ describe("Release", () => { }); test("should match rebased commits to PRs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getLatestReleaseInfo.mockReturnValueOnce({ published_at: "2019-01-16", @@ -679,7 +686,7 @@ describe("Release", () => { hash: "1", authorName: "Adam Dierkens", authorEmail: "adam@dierkens.com", - subject: "I am a commit to master", + subject: "I am a commit to main", }, ]); graphql.mockReturnValueOnce({ @@ -690,7 +697,7 @@ describe("Release", () => { }); test("should match commits with related PRs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getLatestReleaseInfo.mockReturnValueOnce({ published_at: "2019-01-16", @@ -729,7 +736,7 @@ describe("Release", () => { }); test("should find matching PRs for shas through search", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getGitLog.mockReturnValueOnce([ makeCommitFromMsg("Doom Patrol enabled", { @@ -761,7 +768,7 @@ describe("Release", () => { }); test("should ignore closed prs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getGitLog.mockReturnValueOnce([ makeCommitFromMsg("Doom Patrol enabled", { @@ -795,7 +802,7 @@ describe("Release", () => { }); test("should detect pre-release branches", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getGitLog.mockReturnValueOnce([ makeCommitFromMsg("Doom Patrol enabled", { @@ -834,7 +841,7 @@ describe("Release", () => { }); test("should include PRs merged to other PRs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); getGitLog.mockReturnValueOnce([ makeCommitFromMsg("Doom (#12343)", { @@ -900,7 +907,7 @@ describe("Release", () => { }); test("should gracefully handle failed fetches to merged PRs", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = await logParse.normalizeCommits([ makeCommitFromMsg("First"), @@ -921,7 +928,7 @@ describe("Release", () => { describe("getSemverBump", () => { test("default to patch", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First"), makeCommitFromMsg("Second"), @@ -934,7 +941,7 @@ describe("Release", () => { }); test("should use higher version", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First (#1234)"), makeCommitFromMsg("Second"), @@ -948,7 +955,7 @@ describe("Release", () => { }); test("should not publish a release", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First (#1234)"), makeCommitFromMsg("Second (#1235)"), @@ -970,7 +977,7 @@ describe("Release", () => { }); test("should publish a release", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First (#1234)"), makeCommitFromMsg("Second (#1235)"), @@ -990,7 +997,7 @@ describe("Release", () => { }); test("should default to publish a prepatch", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const commits = [ makeCommitFromMsg("First (#1234)"), makeCommitFromMsg("Second (#1235)"), @@ -1010,7 +1017,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); const commits = [ makeCommitFromMsg("First (#1234)"), @@ -1031,7 +1038,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); const commits = [ makeCommitFromMsg("First (#1234)"), @@ -1062,7 +1069,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: customLabels, - baseBranch: "master", + baseBranch: "main", }); const commits = [ makeCommitFromMsg("First (#1234)"), @@ -1098,7 +1105,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: customLabels, - baseBranch: "master", + baseBranch: "main", }); const commits = [ makeCommitFromMsg("First (#1234)"), @@ -1124,7 +1131,7 @@ describe("Release", () => { describe("addLabelsToProject", () => { test("should add labels", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const customLabels: ILabelDefinition[] = [ { name: "1", description: "major", releaseType: SEMVER.major }, { name: "2", description: "minor", releaseType: SEMVER.minor }, @@ -1159,7 +1166,7 @@ describe("Release", () => { { prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }, mockLogger ); @@ -1177,7 +1184,7 @@ describe("Release", () => { }); test("should not add old labels", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const labels: ILabelDefinition[] = [ { name: "1", description: "major", releaseType: SEMVER.major }, { name: "2", description: "minor", releaseType: SEMVER.minor }, @@ -1199,7 +1206,7 @@ describe("Release", () => { }); test("should not add old labels - case sensitive", async () => { - const gh = new Release(git); + const gh = new Release(git, config); const labels: ILabelDefinition[] = [ { name: "major", description: "", releaseType: SEMVER.major }, { name: "Minor", description: "", releaseType: SEMVER.minor }, @@ -1224,7 +1231,7 @@ describe("Release", () => { let gh = new Release(git, { prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); const labels: ILabelDefinition[] = [ { @@ -1245,7 +1252,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); await gh.addLabelsToProject(labels); expect(createLabel).toHaveBeenCalledWith({ @@ -1260,7 +1267,7 @@ describe("Release", () => { onlyPublishWithReleaseLabel: true, prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); const labels: ILabelDefinition[] = [ { @@ -1280,7 +1287,7 @@ describe("Release", () => { gh = new Release(git, { prereleaseBranches: ["next"], labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", }); await gh.addLabelsToProject(labels); expect(createLabel).toHaveBeenCalledWith({ diff --git a/packages/core/src/__tests__/semver.test.ts b/packages/core/src/__tests__/semver.test.ts index d59e7742ad..2655f7488a 100644 --- a/packages/core/src/__tests__/semver.test.ts +++ b/packages/core/src/__tests__/semver.test.ts @@ -84,7 +84,7 @@ describe("calculateSemVerBump", () => { ).toBe(SEMVER.noVersion); }); - test("should respect onlyPublishWithReleaseLabel when no labels present on push to master", () => { + test("should respect onlyPublishWithReleaseLabel when no labels present on push to baseBranch", () => { expect( calculateSemVerBump([], semverMap, { onlyPublishWithReleaseLabel: true, diff --git a/packages/core/src/auto-args.ts b/packages/core/src/auto-args.ts index 1503cf63c2..c9ed1f93e7 100644 --- a/packages/core/src/auto-args.ts +++ b/packages/core/src/auto-args.ts @@ -83,7 +83,7 @@ interface Prerelease { } interface BaseBranch { - /** The branch to treat as the base. Default is master */ + /** The branch to treat as the base */ baseBranch?: string; } @@ -146,10 +146,10 @@ export type ILatestOptions = BaseBranch & export type IShipItOptions = ILatestOptions & { /** - * Make auto publish prerelease versions when merging to master. + * Make auto publish prerelease versions when merging to baseBranch. * Only PRs merged with "release" label will generate a "latest" release. * Only use this flag if you do not want to maintain a prerelease branch, - * and instead only want to use master. + * and instead only want to use baseBranch. */ onlyGraduateWithReleaseLabel?: boolean; }; diff --git a/packages/core/src/auto.ts b/packages/core/src/auto.ts index 74a1c7c546..24f6e35a20 100644 --- a/packages/core/src/auto.ts +++ b/packages/core/src/auto.ts @@ -347,6 +347,19 @@ function escapeRegExp(str: string) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string } +/** Check if a repo has a branch */ +function hasBranch(branch: string) { + const branches = execSync("git branch --list --all", { + encoding: "utf-8", + }).split("\n"); + + return branches.some((b) => { + const parts = b.split("/"); + + return b === branch || parts[parts.length - 1] === branch; + }); +} + /** The Error that gets thrown when a label existence check fails */ export class LabelExistsError extends Error { /** @@ -369,7 +382,7 @@ export default class Auto { logger: ILogger; /** Options auto was initialized with */ options: ApiOptions; - /** The branch auto uses as master. */ + /** The branch auto uses as the base. */ baseBranch: string; /** The remote git to push changes to. This is the full URL with auth */ remote!: string; @@ -391,7 +404,8 @@ export default class Auto { /** Initialize auto and it's environment */ constructor(options: ApiOptions = {}) { this.options = options; - this.baseBranch = options.baseBranch || "master"; + this.baseBranch = + options.baseBranch || (hasBranch("main") && "main") || "master"; setLogLevel( "quiet" in options && options.quiet ? "quiet" @@ -931,10 +945,13 @@ export default class Auto { const prNumber = getPrNumberFromEnv(pr); if (!prNumber) { - // If pr-check is ran on CI on master then we exit successfully since + // If pr-check is ran on CI on baseBranch then we exit successfully since // running pr-check in this scenario wouldn't make sense anyway. Enables // adding this command without resorting to bash if/else statements. - if (env.isCi && (env.branch === "master" || this.inPrereleaseBranch())) { + if ( + env.isCi && + (env.branch === this.baseBranch || this.inPrereleaseBranch()) + ) { process.exit(0); } @@ -1189,7 +1206,10 @@ export default class Auto { const from = (await this.git.shaExists("HEAD^")) ? "HEAD^" : "HEAD"; const commitsInRelease = await this.release.getCommitsInRelease(from); - this.logger.veryVerbose.info('Found commits in canary release', commitsInRelease); + this.logger.veryVerbose.info( + "Found commits in canary release", + commitsInRelease + ); const labels = commitsInRelease.map((commit) => commit.labels); @@ -1284,7 +1304,7 @@ export default class Auto { } /** - * Create a next (or test) version of the project. If on master will + * Create a next (or test) version of the project. If on baseBranch will * release to the default "next" branch. */ async next(args: INextOptions): Promise { @@ -1308,18 +1328,26 @@ export default class Auto { await this.checkClean(); await this.setGitUser(); - this.hooks.onCreateLogParse.tap("Omit merges from master", (logParse) => { - logParse.hooks.omitCommit.tap("Omit merges from master", (commit) => { - const shouldOmit = commit.subject.match(/^Merge (?:\S+\/)*master/); - - if (shouldOmit) { - this.logger.verbose.info( - `Omitting merge commit from master: ${commit.subject}` - ); - return true; - } - }); - }); + this.hooks.onCreateLogParse.tap( + `Omit merges from ${this.baseBranch}`, + (logParse) => { + logParse.hooks.omitCommit.tap( + `Omit merges from ${this.baseBranch}`, + (commit) => { + const shouldOmit = commit.subject.match( + new RegExp(`^Merge (?:\\S+\\/)*${this.baseBranch}`) + ); + + if (shouldOmit) { + this.logger.verbose.info( + `Omitting merge commit from ${this.baseBranch}: ${commit.subject}` + ); + return true; + } + } + ); + } + ); const currentBranch = getCurrentBranch(); const forkPoints = ( @@ -1473,7 +1501,7 @@ export default class Auto { const isPR = "isPr" in env && env.isPr; const from = (await this.git.shaExists("HEAD^")) ? "HEAD^" : "HEAD"; const head = await this.release.getCommitsInRelease(from); - // env-ci sets branch to target branch (ex: master) in some CI services. + // env-ci sets branch to target branch (ex: main) in some CI services. // so we should make sure we aren't in a PR just to be safe const currentBranch = getCurrentBranch(); const isBaseBranch = !isPR && currentBranch === this.baseBranch; @@ -1527,7 +1555,7 @@ export default class Auto { if (options.dryRun && !options.quiet) { this.logger.log.success( - "Below is what would happen upon merge of the current branch into master" + `Below is what would happen upon merge of the current branch into ${this.baseBranch}` ); await this.publishFullRelease(options); } diff --git a/packages/core/src/changelog.ts b/packages/core/src/changelog.ts index a689697b23..48d00c8120 100644 --- a/packages/core/src/changelog.ts +++ b/packages/core/src/changelog.ts @@ -19,7 +19,7 @@ export interface IGenerateReleaseNotesOptions { baseUrl: string; /** The labels configured by the user */ labels: ILabelDefinition[]; - /** The branch that is used as the base. defaults to master */ + /** The branch that is used as the base */ baseBranch: string; /** The branches that is used as prerelease branches. defaults to next */ prereleaseBranches: string[]; diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index a8da2170a6..047971f3d0 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -36,7 +36,7 @@ export interface IGitOptions { repo: string; /** The URL to the GitHub (public or enterprise) the project is using */ baseUrl?: string; - /** The main branch of the repo. Usually master */ + /** The main branch of the repo */ baseBranch: string; /** The URL to the GitHub graphql API (public or enterprise) the project is using */ graphqlBaseUrl?: string; @@ -439,14 +439,14 @@ export default class Git { /** Get the users associated with the GH_TOKEN */ @memoize() async getUser() { - const [, user] = await on(this.github.users.getAuthenticated()) || {}; + const [, user] = (await on(this.github.users.getAuthenticated())) || {}; return user?.data; } /** Get collaborator permission level to the repo. */ @memoize() async getTokenPermissionLevel() { - const user = await this.getUser() + const user = await this.getUser(); if (!user) { return { diff --git a/packages/core/src/release.ts b/packages/core/src/release.ts index 7c7463953b..10b01cdf61 100644 --- a/packages/core/src/release.ts +++ b/packages/core/src/release.ts @@ -29,7 +29,6 @@ import { ISearchQuery, } from "./match-sha-to-pr"; import { LoadedAutoRc } from "./types"; -import { DEFAULT_PRERELEASE_BRANCHES } from "./config"; /** Construct a map of label => semver label */ export const getVersionMap = (labels = defaultLabels) => @@ -71,15 +70,7 @@ export default class Release { private readonly versionLabels: IVersionLabels; /** Initialize the release manager */ - constructor( - git: Git, - config: LoadedAutoRc = { - baseBranch: "master", - prereleaseBranches: DEFAULT_PRERELEASE_BRANCHES, - labels: defaultLabels, - }, - logger: ILogger = dummyLog() - ) { + constructor(git: Git, config: LoadedAutoRc, logger: ILogger = dummyLog()) { this.config = config; this.logger = logger; this.hooks = makeReleaseHooks(); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 1d5d212558..108d0bbba7 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -18,7 +18,7 @@ const githubInformation = t.partial({ githubApi: t.string, /** The github graphql api to interact with */ githubGraphqlApi: t.string, - /** The branch that is used as the base. defaults to master */ + /** The branch that is used as the base */ baseBranch: t.string, }); @@ -128,7 +128,7 @@ export const loadedAutoRc = t.intersection([ labels: t.array(labelDefinition), /** Branches to create pre-releases from */ prereleaseBranches: t.array(t.string), - /** The branch that is used as the base. defaults to master */ + /** The branch that is used as the base */ baseBranch: t.string, }), ]); diff --git a/packages/core/src/utils/__tests__/verify-auth.test.ts b/packages/core/src/utils/__tests__/verify-auth.test.ts index 3b369acb48..66d852ff57 100644 --- a/packages/core/src/utils/__tests__/verify-auth.test.ts +++ b/packages/core/src/utils/__tests__/verify-auth.test.ts @@ -13,7 +13,7 @@ describe("verify-auth", () => { throw new Error(); }, })); - expect(await verifyAuth("origin", "master")).toBe(false); + expect(await verifyAuth("origin", "main")).toBe(false); }); test("should verify auth when we can push to remote", async () => { @@ -22,7 +22,7 @@ describe("verify-auth", () => { kill: () => {}, on: (_: string, cb: () => void) => cb(), })); - expect(await verifyAuth("origin", "master")).toBe(true); + expect(await verifyAuth("origin", "main")).toBe(true); }); test("should not verify auth when we can't push to remote", async () => { @@ -34,6 +34,6 @@ describe("verify-auth", () => { kill: () => {}, on: (_: string, cb: () => void) => cb(), })); - expect(await verifyAuth("bad", "master")).toBe(false); + expect(await verifyAuth("bad", "main")).toBe(false); }); }); diff --git a/packages/core/src/utils/get-current-branch.ts b/packages/core/src/utils/get-current-branch.ts index a89034ccab..cbc6e07d97 100644 --- a/packages/core/src/utils/get-current-branch.ts +++ b/packages/core/src/utils/get-current-branch.ts @@ -7,7 +7,7 @@ const env = envCi(); export function getCurrentBranch() { const isPR = "isPr" in env && env.isPr; let branch: string | undefined; - // env-ci sets branch to target branch (ex: master) in some CI services. + // env-ci sets branch to target branch (ex: main) in some CI services. // so we should make sure we aren't in a PR just to be safe if (isPR && "prBranch" in env) { diff --git a/plugins/crates/__tests__/crates.test.ts b/plugins/crates/__tests__/crates.test.ts index 44c6911e09..160bebdac8 100644 --- a/plugins/crates/__tests__/crates.test.ts +++ b/plugins/crates/__tests__/crates.test.ts @@ -224,7 +224,7 @@ describe("CratesPlugin", () => { hooks, logger: dummyLog(), remote: "origin", - baseBranch: "master", + baseBranch: "main", } as Auto.Auto); await hooks.publish.promise({ bump: Auto.SEMVER.patch }); expect(exec).toHaveBeenCalledWith("cargo", ["publish"]); @@ -233,7 +233,7 @@ describe("CratesPlugin", () => { "--follow-tags", "--set-upstream", "origin", - "master", + "main", ]); }); }); diff --git a/plugins/docker/__tests__/docker.test.ts b/plugins/docker/__tests__/docker.test.ts index 416ddd9d6d..9fd38fa499 100644 --- a/plugins/docker/__tests__/docker.test.ts +++ b/plugins/docker/__tests__/docker.test.ts @@ -289,7 +289,7 @@ describe("Docker Plugin", () => { const hooks = setup( { getLatestTagInBranch: () => "v1.0.0", - getCurrentBranch: () => "master", + getCurrentBranch: () => "main", remote: "github.com", }, { registry, image: sourceImage, tagLatest: false } @@ -308,7 +308,7 @@ describe("Docker Plugin", () => { const hooks = setup( { getLatestTagInBranch: () => "v1.0.0", - getCurrentBranch: () => "master", + getCurrentBranch: () => "main", remote: "github.com", }, { registry, image: sourceImage, tagLatest: true } diff --git a/plugins/jira/__tests__/jira.test.ts b/plugins/jira/__tests__/jira.test.ts index af12ff1367..1f6742ea5f 100644 --- a/plugins/jira/__tests__/jira.test.ts +++ b/plugins/jira/__tests__/jira.test.ts @@ -112,7 +112,7 @@ const testOptions = (): IGenerateReleaseNotesOptions => ({ repo: "auto", baseUrl: "https://github.custom.com/foobar/auto", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); const logParse = new LogParse(); diff --git a/plugins/npm/__tests__/monorepo-log.test.ts b/plugins/npm/__tests__/monorepo-log.test.ts index 1500548d1e..e50c2f3bdd 100644 --- a/plugins/npm/__tests__/monorepo-log.test.ts +++ b/plugins/npm/__tests__/monorepo-log.test.ts @@ -103,7 +103,7 @@ test("should group sections for packages", async () => { repo: "test", baseUrl: "https://github.custom.com/", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); @@ -167,7 +167,7 @@ test("should create sections for packages", async () => { repo: "test", baseUrl: "https://github.custom.com/", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); @@ -227,7 +227,7 @@ test("should be able to disable sections for packages", async () => { repo: "test", baseUrl: "https://github.custom.com/", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); @@ -287,7 +287,7 @@ test("should add versions for independent packages", async () => { repo: "test", baseUrl: "https://github.custom.com/", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); @@ -344,7 +344,7 @@ test("should create extra change logs for sub-packages", async () => { repo: "test", baseUrl: "https://github.custom.com/", labels: defaultLabels, - baseBranch: "master", + baseBranch: "main", prereleaseBranches: ["next"], }); t.hooks.renderChangelogTitle.tap("test", (label) => label); diff --git a/plugins/npm/__tests__/npm-next.test.ts b/plugins/npm/__tests__/npm-next.test.ts index 669d07d8ff..877bbec602 100644 --- a/plugins/npm/__tests__/npm-next.test.ts +++ b/plugins/npm/__tests__/npm-next.test.ts @@ -68,7 +68,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -121,7 +121,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -155,7 +155,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -199,7 +199,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -259,7 +259,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -304,7 +304,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -343,7 +343,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -387,7 +387,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", prefixRelease: (v: string) => v, @@ -456,7 +456,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (v: string) => `v${v}`, git: { @@ -536,7 +536,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (v: string) => `v${v}`, git: { @@ -593,7 +593,7 @@ describe("next", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (v: string) => `v${v}`, git: { diff --git a/plugins/npm/__tests__/npm.test.ts b/plugins/npm/__tests__/npm.test.ts index d4ea442aea..9fefa7c967 100644 --- a/plugins/npm/__tests__/npm.test.ts +++ b/plugins/npm/__tests__/npm.test.ts @@ -33,7 +33,7 @@ jest.mock( () => (...args: any[]) => execPromise(...args) ); jest.mock("../../../packages/core/dist/utils/get-current-branch", () => ({ - getCurrentBranch: () => "master", + getCurrentBranch: () => "main", })); jest.mock( "../../../packages/core/dist/utils/get-lerna-packages", @@ -180,7 +180,7 @@ describe("getAuthor", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -200,7 +200,7 @@ describe("getAuthor", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -227,7 +227,7 @@ describe("getAuthor", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -253,7 +253,7 @@ describe("getRepository", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -285,7 +285,7 @@ describe("getPreviousVersion", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, } as Auto.Auto); @@ -308,7 +308,7 @@ describe("getPreviousVersion", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, } as Auto.Auto); @@ -332,7 +332,7 @@ describe("getPreviousVersion", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, } as Auto.Auto); @@ -366,7 +366,7 @@ describe("getPreviousVersion", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, } as Auto.Auto); @@ -401,7 +401,7 @@ describe("modifyConfig", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger, } as Auto.Auto); @@ -417,7 +417,7 @@ describe("modifyConfig", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger, } as Auto.Auto); @@ -448,7 +448,7 @@ describe("modifyConfig", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger, } as Auto.Auto); @@ -473,7 +473,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger, } as Auto.Auto); @@ -503,7 +503,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -531,7 +531,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -567,7 +567,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -603,7 +603,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -651,7 +651,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -676,7 +676,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -703,7 +703,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -731,7 +731,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -762,7 +762,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -799,7 +799,7 @@ describe("publish", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); @@ -817,7 +817,7 @@ describe("publish", () => { "--follow-tags", "--set-upstream", "origin", - "master", + "main", ]); }); }); @@ -835,7 +835,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -866,7 +866,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -901,7 +901,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -935,7 +935,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -972,7 +972,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -1007,7 +1007,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), getCurrentVersion: () => "1.2.3", git: { @@ -1038,7 +1038,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("1.2.3"), @@ -1086,7 +1086,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("1.2.3"), @@ -1138,7 +1138,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("1.2.3"), @@ -1197,7 +1197,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("1.2.3"), @@ -1245,7 +1245,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), } as Auto.Auto); existsSync.mockReturnValueOnce(true); @@ -1295,7 +1295,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("@foo/lib:1.1.0"), @@ -1342,7 +1342,7 @@ describe("canary", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), git: { getLatestRelease: () => Promise.resolve("@foo/lib:1.1.0"), @@ -1400,7 +1400,7 @@ describe("makeRelease", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, git: { publish } as any, @@ -1469,7 +1469,7 @@ describe("beforeCommitChangelog", () => { config: { prereleaseBranches: ["next"] }, hooks, remote: "origin", - baseBranch: "master", + baseBranch: "main", logger: dummyLog(), prefixRelease: (str) => str, release: { diff --git a/plugins/npm/src/index.ts b/plugins/npm/src/index.ts index ef2d8cd77a..040f6d2172 100644 --- a/plugins/npm/src/index.ts +++ b/plugins/npm/src/index.ts @@ -651,7 +651,7 @@ export default class NPMPlugin implements IPlugin { const prereleaseBranches = auto.config?.prereleaseBranches || DEFAULT_PRERELEASE_BRANCHES; const branch = getCurrentBranch(); - // if ran from master we publish the prerelease to the first + // if ran from baseBranch we publish the prerelease to the first // configured prerelease branch const prereleaseBranch = branch && prereleaseBranches.includes(branch) @@ -1263,7 +1263,7 @@ export default class NPMPlugin implements IPlugin { if (!this.commitNextVersion) { // we do not want to commit the next version. this causes - // merge conflicts when merged into master. We also do not want + // merge conflicts when merged into baseBranch. We also do not want // to re-implement the magic lerna does. So instead we let lerna // commit+tag the new version and roll back all the tags to the // previous commit. @@ -1304,7 +1304,7 @@ export default class NPMPlugin implements IPlugin { "version", newVersion, // we do not want to commit the next version. this causes - // merge conflicts when merged into master + // merge conflicts when merged into baseBranch "--no-git-tag-version", ...verboseArgs, ]); diff --git a/plugins/released/__tests__/released-label.test.ts b/plugins/released/__tests__/released-label.test.ts index db9d780408..be69ec43d6 100644 --- a/plugins/released/__tests__/released-label.test.ts +++ b/plugins/released/__tests__/released-label.test.ts @@ -12,7 +12,7 @@ import botList from "@auto-it/bot-list"; import ReleasedLabelPlugin from "../src"; -const git = new Git({ owner: "1", repo: "2", baseBranch: "master" }); +const git = new Git({ owner: "1", repo: "2", baseBranch: "main" }); const log = new LogParse(); const comment = jest.fn();