Skip to content

Commit

Permalink
use main branch if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Jan 20, 2021
1 parent 45870dd commit 7fb303a
Show file tree
Hide file tree
Showing 31 changed files with 252 additions and 197 deletions.
1 change: 1 addition & 0 deletions docs/pages/docs/configuration/autorc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/extras/shipit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down Expand Up @@ -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,
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/__snapshots__/auto.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -171,7 +171,7 @@ Object {

exports[`Auto should extend local config 1`] = `
Object {
"baseBranch": "master",
"baseBranch": "main",
"extends": "<PROJECT_ROOT>fake.json",
"labels": Array [
Object {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-canary-local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/__tests__/auto-ci-base-branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-make-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
30 changes: 22 additions & 8 deletions packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ 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();

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",
};
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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: [] });
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/__tests__/changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const testOptions = (): IGenerateReleaseNotesOptions => ({
repo: "auto",
baseUrl: "https://github.custom.com/foobar/auto",
labels: [...defaultLabels],
baseBranch: "master",
baseBranch: "main",
prereleaseBranches: ["next"],
});

Expand All @@ -28,7 +28,7 @@ describe("createUserLink", () => {
repo: "",
baseUrl: "https://github.custom.com/",
labels: [...defaultLabels],
baseBranch: "master",
baseBranch: "main",
prereleaseBranches: ["next"],
});
changelog.loadDefaultHooks();
Expand Down Expand Up @@ -68,7 +68,7 @@ describe("createUserLink", () => {
repo: "",
baseUrl: "https://github.custom.com/",
labels: [...defaultLabels],
baseBranch: "master",
baseBranch: "main",
prereleaseBranches: ["next"],
});
changelog.loadDefaultHooks();
Expand Down Expand Up @@ -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"],
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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"],
},
{
Expand Down Expand Up @@ -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"],
},
{
Expand Down Expand Up @@ -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"],
},
{
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/__tests__/get-remote.test.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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");
});
});
10 changes: 5 additions & 5 deletions packages/core/src/__tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const options = {
owner: "Adam Dierkens",
repo: "test",
token: "MyToken",
baseBranch: "master",
baseBranch: "main",
};

describe("github", () => {
Expand Down Expand Up @@ -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"]);
}

Expand All @@ -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"]);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 () => {
Expand Down
Loading

0 comments on commit 7fb303a

Please sign in to comment.