diff --git a/.changeset/hungry-dryers-mate.md b/.changeset/hungry-dryers-mate.md new file mode 100644 index 00000000..f5955f51 --- /dev/null +++ b/.changeset/hungry-dryers-mate.md @@ -0,0 +1,5 @@ +--- +"changesets-signed-commits": minor +--- + +Add optional prDraft input diff --git a/actions/signed-commits/action.yml b/actions/signed-commits/action.yml index cd5b6bc4..16d50241 100644 --- a/actions/signed-commits/action.yml +++ b/actions/signed-commits/action.yml @@ -8,7 +8,9 @@ inputs: description: "The command to use to build and publish packages" required: false version: - description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided" + description: + "The command to update version, edit CHANGELOG, read and delete + changesets. Default to `changeset version` if not provided" required: false cwd: description: Sets the cwd for the node process. Default to `process.cwd()` @@ -20,22 +22,36 @@ inputs: title: description: The pull request title. Default to `Version Packages` required: false + prDraft: + description: + A boolean value to indicate whether the pull request should be a draft or + not. Default to `false` + required: false + default: "false" setupGitUser: - description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true` + description: + Sets up the git user for commits as `"github-actions[bot]"`. Default to + `true` required: false - default: true + default: "true" createGithubReleases: - description: "A boolean value to indicate whether to create Github releases after `publish` or not" + description: + "A boolean value to indicate whether to create Github releases after + `publish` or not" required: false - default: true + default: "true" outputs: published: - description: A boolean value to indicate whether a publishing is happened or not + description: + A boolean value to indicate whether a publishing is happened or not publishedPackages: description: > - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]` + A JSON array to present the published packages. The format is `[{"name": + "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]` hasChangesets: - description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality. + description: + A boolean about whether there were changesets. Useful if you want to + create your own publishing functionality. pullRequestNumber: description: The pull request number that was created or updated branding: diff --git a/actions/signed-commits/src/__snapshots__/run.test.ts.snap b/actions/signed-commits/src/__snapshots__/run.test.ts.snap index 160de8ba..a2a4a30c 100644 --- a/actions/signed-commits/src/__snapshots__/run.test.ts.snap +++ b/actions/signed-commits/src/__snapshots__/run.test.ts.snap @@ -25,6 +25,41 @@ exports[`version creates simple PR 1`] = ` - Awesome feature ", + "draft": false, + "head": "changeset-release/some-branch", + "owner": "changesets", + "repo": "action", + "title": "Version Packages", + }, +] +`; + +exports[`version creates simple PR in draft mode 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-a@1.1.0 + +### Minor Changes + +- Awesome feature + +### Patch Changes + +- Updated dependencies + - simple-project-pkg-b@1.1.0 + +## simple-project-pkg-b@1.1.0 + +### Minor Changes + +- Awesome feature +", + "draft": true, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", @@ -43,6 +78,7 @@ exports[`version does not include any release information if a message with simp # Releases > All release information have been omitted from this message, as the content exceeds the size limit.", + "draft": false, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", @@ -65,6 +101,7 @@ exports[`version does not include changelog entries if full message exceeds size ## simple-project-pkg-a@1.1.0 ", + "draft": false, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", @@ -87,6 +124,7 @@ exports[`version doesn't include ignored package that got a dependency update in - Awesome feature ", + "draft": false, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", @@ -109,6 +147,7 @@ exports[`version only includes bumped packages in the PR body 1`] = ` - Awesome feature ", + "draft": false, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", diff --git a/actions/signed-commits/src/index.ts b/actions/signed-commits/src/index.ts index a8a21249..21580c80 100644 --- a/actions/signed-commits/src/index.ts +++ b/actions/signed-commits/src/index.ts @@ -30,7 +30,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; core.info("setting GitHub credentials"); await fs.writeFile( `${process.env.HOME}/.netrc`, - `machine github.com\nlogin github-actions[bot]\npassword ${githubToken}` + `machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`, ); let { changesets } = await readChangesetState(); @@ -38,7 +38,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; let publishScript = core.getInput("publish"); let hasChangesets = changesets.length !== 0; const hasNonEmptyChangesets = changesets.some( - (changeset) => changeset.releases.length > 0 + (changeset) => changeset.releases.length > 0, ); let hasPublishScript = !!publishScript; @@ -52,7 +52,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; return; case !hasChangesets && hasPublishScript: { core.info( - "No changesets found, attempting to publish any unpublished packages to npm" + "No changesets found, attempting to publish any unpublished packages to npm", ); let userNpmrcPath = `${process.env.HOME}/.npmrc`; @@ -65,22 +65,22 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; }); if (authLine) { core.info( - "Found existing auth token for the npm registry in the user .npmrc file" + "Found existing auth token for the npm registry in the user .npmrc file", ); } else { core.info( - "Didn't find existing auth token for the npm registry in the user .npmrc file, creating one" + "Didn't find existing auth token for the npm registry in the user .npmrc file, creating one", ); fs.appendFileSync( userNpmrcPath, - `\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n` + `\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`, ); } } else { core.info("No user .npmrc file found, creating one"); fs.writeFileSync( userNpmrcPath, - `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n` + `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`, ); } @@ -94,7 +94,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; core.setOutput("published", "true"); core.setOutput( "publishedPackages", - JSON.stringify(result.publishedPackages) + JSON.stringify(result.publishedPackages), ); } return; @@ -108,6 +108,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; githubToken, prTitle: getOptionalInput("title"), commitMessage: getOptionalInput("commit"), + prDraft: core.getBooleanInput("prDraft"), hasPublishScript, }); diff --git a/actions/signed-commits/src/run.test.ts b/actions/signed-commits/src/run.test.ts index 5e3bfadc..ef87c77b 100644 --- a/actions/signed-commits/src/run.test.ts +++ b/actions/signed-commits/src/run.test.ts @@ -121,6 +121,46 @@ describe("version", () => { expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); }); + it("creates simple PR in draft mode", async () => { + const cwd = f.copy("simple-project"); + setupRepo(cwd); + + mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( + () => ({ data: { items: [] } }), + ); + + mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ + data: { number: 123 }, + })); + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-a", + type: "minor", + }, + { + name: "simple-project-pkg-b", + type: "minor", + }, + ], + summary: "Awesome feature", + }, + ], + cwd, + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + prDraft: true, + }); + + expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); + }); + it("only includes bumped packages in the PR body", async () => { let cwd = f.copy("simple-project"); setupRepo(cwd); diff --git a/actions/signed-commits/src/run.ts b/actions/signed-commits/src/run.ts index 8a45e1b1..349534c0 100644 --- a/actions/signed-commits/src/run.ts +++ b/actions/signed-commits/src/run.ts @@ -301,6 +301,7 @@ type VersionOptions = { cwd?: string; prTitle?: string; commitMessage?: string; + prDraft?: boolean; hasPublishScript?: boolean; prBodyMaxCharacters?: number; }; @@ -315,6 +316,7 @@ export async function runVersion({ cwd = process.cwd(), prTitle = "Version Packages", commitMessage = "Version Packages", + prDraft = false, hasPublishScript = false, prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE, }: VersionOptions): Promise { @@ -440,6 +442,7 @@ export async function runVersion({ base: branch, head: versionBranch, title: finalPrTitle, + draft: prDraft, body: prBody, ...github.context.repo, });