From 9b07a4fe0f6227501b3b95babe94ddbfea78b319 Mon Sep 17 00:00:00 2001 From: Frank Zhu Date: Thu, 4 Apr 2024 15:03:12 -0500 Subject: [PATCH] add prDraft and labels input to changeset signed-commits action --- .changeset/hungry-dryers-mate.md | 5 +++++ actions/signed-commits/action.yml | 35 ++++++++++++++++++++++------- actions/signed-commits/src/index.ts | 18 ++++++++------- actions/signed-commits/src/run.ts | 14 ++++++++++++ 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 .changeset/hungry-dryers-mate.md diff --git a/.changeset/hungry-dryers-mate.md b/.changeset/hungry-dryers-mate.md new file mode 100644 index 00000000..d65ba6fc --- /dev/null +++ b/.changeset/hungry-dryers-mate.md @@ -0,0 +1,5 @@ +--- +"changesets-signed-commits": minor +--- + +Add prDraft and labels inputs diff --git a/actions/signed-commits/action.yml b/actions/signed-commits/action.yml index cd5b6bc4..a1a232a3 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,39 @@ 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" + labels: + description: A comma separated list of labels to add to the pull request + required: 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/index.ts b/actions/signed-commits/src/index.ts index a8a21249..46e24194 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,8 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; githubToken, prTitle: getOptionalInput("title"), commitMessage: getOptionalInput("commit"), + prDraft: core.getBooleanInput("prDraft"), + labels: getOptionalInput("labels"), hasPublishScript, }); diff --git a/actions/signed-commits/src/run.ts b/actions/signed-commits/src/run.ts index 8a45e1b1..26de3252 100644 --- a/actions/signed-commits/src/run.ts +++ b/actions/signed-commits/src/run.ts @@ -301,6 +301,8 @@ type VersionOptions = { cwd?: string; prTitle?: string; commitMessage?: string; + prDraft?: boolean; + labels?: string; hasPublishScript?: boolean; prBodyMaxCharacters?: number; }; @@ -315,6 +317,8 @@ export async function runVersion({ cwd = process.cwd(), prTitle = "Version Packages", commitMessage = "Version Packages", + prDraft, + labels = "", hasPublishScript = false, prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE, }: VersionOptions): Promise { @@ -440,10 +444,20 @@ export async function runVersion({ base: branch, head: versionBranch, title: finalPrTitle, + draft: prDraft, body: prBody, ...github.context.repo, }); + if (labels) { + const labelsArray = labels.split(","); + await octokit.rest.issues.addLabels({ + issue_number: newPullRequest.number, + labels: labelsArray, + ...github.context.repo, + }); + } + return { pullRequestNumber: newPullRequest.number, };