Skip to content

Commit

Permalink
add prDraft input to changeset signed-commits action (#269)
Browse files Browse the repository at this point in the history
* add prDraft and labels input to changeset signed-commits action

* update snapshot and add default false to prDraft param

* add unit test

* rename labels to prLabels

* remove labels

* update changeset message

* remove do-not-merge label text in test
  • Loading branch information
momentmaker authored Apr 5, 2024
1 parent f389df7 commit 7748941
Show file tree
Hide file tree
Showing 6 changed files with 120 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 optional prDraft input
32 changes: 24 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,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:
Expand Down
39 changes: 39 additions & 0 deletions actions/signed-commits/src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
17 changes: 9 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,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
githubToken,
prTitle: getOptionalInput("title"),
commitMessage: getOptionalInput("commit"),
prDraft: core.getBooleanInput("prDraft"),
hasPublishScript,
});

Expand Down
40 changes: 40 additions & 0 deletions actions/signed-commits/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions actions/signed-commits/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ type VersionOptions = {
cwd?: string;
prTitle?: string;
commitMessage?: string;
prDraft?: boolean;
hasPublishScript?: boolean;
prBodyMaxCharacters?: number;
};
Expand All @@ -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<RunVersionResult> {
Expand Down Expand Up @@ -440,6 +442,7 @@ export async function runVersion({
base: branch,
head: versionBranch,
title: finalPrTitle,
draft: prDraft,
body: prBody,
...github.context.repo,
});
Expand Down

0 comments on commit 7748941

Please sign in to comment.