Skip to content

Commit 7359107

Browse files
authored
Rename root action inputs and outputs (#681)
1 parent f71ae04 commit 7359107

6 files changed

Lines changed: 66 additions & 32 deletions

File tree

.changeset/eighty-parks-tickle.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"@changesets/action": major
3+
---
4+
5+
Rename the root action inputs and outputs to better match the sub-actions' conventions.
6+
7+
Inputs:
8+
9+
- `version` -> `version-script`
10+
- `publish` -> `publish-script`
11+
- `commit` -> `commit-message`
12+
- `title` -> `pr-title`
13+
- `branch` -> `pr-base-branch`
14+
15+
Outputs:
16+
17+
- `pull-request-number` -> `pr-number`

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
uses: changesets/action@v2
107107
with:
108108
# This expects you to have a script called release which does a build for your packages and calls changeset publish
109-
publish: pnpm release
109+
publish-script: pnpm release
110110
env:
111111
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
112112
@@ -217,7 +217,7 @@ jobs:
217217
uses: changesets/action@v2
218218
with:
219219
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
220-
version: pnpm version
220+
version-script: pnpm version
221221
```
222222
223223
#### With Yarn 2 / Plug'n'Play
@@ -227,6 +227,6 @@ If you are using [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp), you shoul
227227
```yaml
228228
- uses: changesets/action@v2
229229
with:
230-
version: yarn changeset version
230+
version-script: yarn changeset version
231231
# ...
232232
```

action.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@ inputs:
88
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
99
required: false
1010
default: ${{ github.token }}
11-
publish:
11+
publish-script:
1212
description: "The command to use to build and publish packages"
1313
required: false
14-
version:
14+
version-script:
1515
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided"
1616
required: false
17-
commit:
18-
description: |
19-
The commit message. Default to `Version Packages`
17+
commit-message:
18+
description: "The commit message. Default to `Version Packages`"
2019
required: false
21-
title:
22-
description: The pull request title. Default to `Version Packages`
20+
default: "Version Packages"
21+
pr-title:
22+
description: "The pull request title. Default to `Version Packages`"
2323
required: false
24-
setup-git-user:
25-
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
24+
default: "Version Packages"
25+
pr-draft:
26+
description: "Controls draft PR behavior. Use 'create' to create new version PRs as draft, or 'always' to also convert existing version PRs back to draft when updating them."
27+
required: false
28+
pr-base-branch:
29+
description: "Sets the base branch of the PR. Defaults to `github.ref_name`."
2630
required: false
27-
default: true
2831
create-github-releases:
29-
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
32+
description: "Whether to create Github releases after publish"
3033
required: false
3134
default: true
3235
push-git-tags:
@@ -43,12 +46,10 @@ inputs:
4346
or app who owns the GITHUB_TOKEN.
4447
required: false
4548
default: "git-cli"
46-
branch:
47-
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
48-
required: false
49-
pr-draft:
50-
description: 'Controls draft PR behavior. Use "create" to create new version PRs as draft, or "always" to also convert existing version PRs back to draft when updating them.'
49+
setup-git-user:
50+
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
5151
required: false
52+
default: true
5253
outputs:
5354
published:
5455
description: A boolean value to indicate whether a publishing is happened or not
@@ -57,7 +58,7 @@ outputs:
5758
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"}]`
5859
has-changesets:
5960
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
60-
pull-request-number:
61+
pr-number:
6162
description: The pull request number that was created or updated
6263
branding:
6364
icon: "package"

src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import {
1212

1313
(async () => {
1414
throwOnRenamedInputs({
15-
commitMode: "commit-mode",
16-
createGithubReleases: "create-github-releases",
15+
publish: "publish-script",
16+
version: "version-script",
17+
commit: "commit-mesage",
18+
title: "pr-title",
19+
branch: "pr-base-branch",
1720
prDraft: "pr-draft",
21+
createGithubReleases: "create-github-releases",
22+
commitMode: "commit-mode",
1823
setupGitUser: "setup-git-user",
1924
});
2025

@@ -55,7 +60,7 @@ import {
5560

5661
let { changesets } = await readChangesetState(cwd);
5762

58-
let publishScript = core.getInput("publish");
63+
let publishScript = core.getInput("publish-script");
5964
let hasChangesets = changesets.length !== 0;
6065
const hasNonEmptyChangesets = changesets.some(
6166
(changeset) => changeset.releases.length > 0,
@@ -168,17 +173,17 @@ import {
168173
return;
169174
case hasChangesets: {
170175
const { pullRequestNumber } = await runVersion({
171-
script: getOptionalInput("version"),
176+
script: getOptionalInput("version-script"),
172177
github,
173178
cwd,
174-
prTitle: getOptionalInput("title"),
175-
commitMessage: getOptionalInput("commit"),
179+
prTitle: getOptionalInput("pr-title"),
180+
commitMessage: getOptionalInput("commit-message"),
176181
hasPublishScript,
177182
prDraft,
178-
branch: getOptionalInput("branch"),
183+
branch: getOptionalInput("pr-base-branch"),
179184
});
180185

181-
core.setOutput("pull-request-number", String(pullRequestNumber));
186+
core.setOutput("pr-number", String(pullRequestNumber));
182187

183188
return;
184189
}

src/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,22 @@ export function getRequiredInput(name: string) {
136136
}
137137

138138
export function throwOnRenamedInputs(renames: Record<string, string>) {
139+
const references: Record<string, string> = {};
140+
139141
for (const [oldInput, newInput] of Object.entries(renames)) {
140142
if (core.getInput(oldInput)) {
141-
throw new Error(
142-
`The input "${oldInput}" has been renamed to "${newInput}". Please update your workflow file.`,
143-
);
143+
references[oldInput] = newInput;
144144
}
145145
}
146+
147+
if (Object.keys(references).length > 0) {
148+
const list = Object.entries(references)
149+
.map(([oldInput, newInput]) => `- "${oldInput}" -> "${newInput}"`)
150+
.join("\n");
151+
throw new Error(
152+
`The following inputs have been renamed:\n${list}\nPlease update your workflow file.`,
153+
);
154+
}
146155
}
147156

148157
function resolveChangesetsCli(cwd: string) {

version/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ inputs:
3737
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
3838
required: false
3939
default: true
40-
outputs: {}
40+
outputs:
41+
pr-number:
42+
description: The pull request number that was created or updated
4143
branding:
4244
icon: package
4345
color: blue

0 commit comments

Comments
 (0)