diff --git a/.changeset/grumpy-hairs-rhyme.md b/.changeset/grumpy-hairs-rhyme.md new file mode 100644 index 00000000..0512fe89 --- /dev/null +++ b/.changeset/grumpy-hairs-rhyme.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": minor +--- + +added `formatChangesetsWithPrettier` option diff --git a/action.yml b/action.yml index 86b97909..0fbc3e37 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,10 @@ inputs: branch: description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided required: false + formatChangesetsWithPrettier: + description: Set false to opt-out of prettier formatting for changelogs + default: true + required: false outputs: published: description: A boolean value to indicate whether a publishing is happened or not diff --git a/src/__snapshots__/run.test.ts.snap b/src/__snapshots__/run.test.ts.snap index 160de8ba..ca70dbe7 100644 --- a/src/__snapshots__/run.test.ts.snap +++ b/src/__snapshots__/run.test.ts.snap @@ -1,5 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`version can opt out of prettier 1`] = ` +[ + { + "base": "some-branch", + "body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated. + + +# Releases +## simple-project-pkg-b@1.1.0 + +### Minor Changes + +- This is a summary + + \`\`\`html + + \`\`\` + +## simple-project-pkg-a@1.0.1 + +### Patch Changes + +- Updated dependencies + - simple-project-pkg-b@1.1.0 +", + "head": "changeset-release/some-branch", + "owner": "changesets", + "repo": "action", + "title": "Version Packages", + }, +] +`; + exports[`version creates simple PR 1`] = ` [ { diff --git a/src/gitUtils.ts b/src/gitUtils.ts index b15151ab..dc829a11 100644 --- a/src/gitUtils.ts +++ b/src/gitUtils.ts @@ -1,11 +1,7 @@ import { exec, getExecOutput } from "@actions/exec"; export const setupUser = async () => { - await exec("git", [ - "config", - "user.name", - `"github-actions[bot]"`, - ]); + await exec("git", ["config", "user.name", `"github-actions[bot]"`]); await exec("git", [ "config", "user.email", diff --git a/src/index.ts b/src/index.ts index 31aef207..4bd84c70 100644 --- a/src/index.ts +++ b/src/index.ts @@ -109,6 +109,9 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; prTitle: getOptionalInput("title"), commitMessage: getOptionalInput("commit"), hasPublishScript, + formatChangesetsWithPrettier: core.getBooleanInput( + "formatChangesetsWithPrettier" + ), branch: getOptionalInput("branch"), }); diff --git a/src/run.test.ts b/src/run.test.ts index 15d2e096..198568f4 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -18,17 +18,17 @@ jest.mock("@actions/github", () => ({ }, })); jest.mock("@actions/github/lib/utils", () => ({ - GitHub: { - plugin: () => { - // function necessary to be used as constructor - return function() { - return { - rest: mockedGithubMethods, - } - } - }, + GitHub: { + plugin: () => { + // function necessary to be used as constructor + return function () { + return { + rest: mockedGithubMethods, + }; + }; }, - getOctokitOptions: jest.fn(), + }, + getOctokitOptions: jest.fn(), })); jest.mock("./gitUtils"); @@ -96,6 +96,44 @@ describe("version", () => { expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); }); + it("can opt out of prettier", async () => { + let cwd = f.copy("simple-project"); + linkNodeModules(cwd); + + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); + + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); + + const summary = `This is a summary +~~~html + +~~~`; + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-b", + type: "minor", + }, + ], + summary, + }, + ], + cwd + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + }); + + expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); + }); + it("only includes bumped packages in the PR body", async () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); diff --git a/src/run.ts b/src/run.ts index 326b9618..de50eea5 100644 --- a/src/run.ts +++ b/src/run.ts @@ -299,6 +299,7 @@ type VersionOptions = { commitMessage?: string; hasPublishScript?: boolean; prBodyMaxCharacters?: number; + formatChangesetsWithPrettier?: boolean; branch?: string; }; @@ -314,6 +315,7 @@ export async function runVersion({ commitMessage = "Version Packages", hasPublishScript = false, prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE, + formatChangesetsWithPrettier = true, branch, }: VersionOptions): Promise { const octokit = setupOctokit(githubToken); @@ -337,7 +339,11 @@ export async function runVersion({ let cmd = semver.lt(changesetsCliPkgJson.version, "2.0.0") ? "bump" : "version"; - await exec("node", [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd], { + + const args = [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd]; + if (formatChangesetsWithPrettier === false) + args.push("--noFormatChangesetsWithPrettier"); + await exec("node", args, { cwd, }); }