Skip to content

Commit

Permalink
add prDraft and labels input to changeset signed-commits action
Browse files Browse the repository at this point in the history
  • Loading branch information
momentmaker committed Apr 4, 2024
1 parent f389df7 commit 9b07a4f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-dryers-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"changesets-signed-commits": minor
---

Add prDraft and labels inputs
35 changes: 27 additions & 8 deletions actions/signed-commits/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand All @@ -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:
Expand Down
18 changes: 10 additions & 8 deletions actions/signed-commits/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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();

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;

Expand All @@ -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`;
Expand All @@ -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`,
);
}

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

Expand Down
14 changes: 14 additions & 0 deletions actions/signed-commits/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ type VersionOptions = {
cwd?: string;
prTitle?: string;
commitMessage?: string;
prDraft?: boolean;
labels?: string;
hasPublishScript?: boolean;
prBodyMaxCharacters?: number;
};
Expand All @@ -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<RunVersionResult> {
Expand Down Expand Up @@ -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,
};
Expand Down

0 comments on commit 9b07a4f

Please sign in to comment.