Skip to content

Commit 0eae789

Browse files
authored
Rename to kebab-case for root action inputs and outputs (#668)
* Rename to kebab-case for root action inputs and outputs * Throw on renamed inputs
1 parent 164652b commit 0eae789

4 files changed

Lines changed: 44 additions & 17 deletions

File tree

‎.changeset/yellow-roses-fix.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": major
3+
---
4+
5+
Rename the input and output names to kebab-case instead of camelCase to match the official GitHub actions pattern

‎action.yml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ inputs:
2121
title:
2222
description: The pull request title. Default to `Version Packages`
2323
required: false
24-
setupGitUser:
24+
setup-git-user:
2525
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
2626
required: false
2727
default: true
28-
createGithubReleases:
28+
create-github-releases:
2929
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
3030
required: false
3131
default: true
32-
commitMode:
32+
commit-mode:
3333
description: >
3434
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
3535
or "github-api" to push changes via the GitHub API. When using "github-api",
@@ -40,18 +40,18 @@ inputs:
4040
branch:
4141
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
4242
required: false
43-
prDraft:
43+
pr-draft:
4444
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.'
4545
required: false
4646
outputs:
4747
published:
4848
description: A boolean value to indicate whether a publishing is happened or not
49-
publishedPackages:
49+
published-packages:
5050
description: >
5151
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"}]`
52-
hasChangesets:
52+
has-changesets:
5353
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
54-
pullRequestNumber:
54+
pull-request-number:
5555
description: The pull request number that was created or updated
5656
branding:
5757
icon: "package"

‎src/index.ts‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ import * as core from "@actions/core";
33
import { GitHub } from "./github.ts";
44
import readChangesetState from "./readChangesetState.ts";
55
import { runPublish, runVersion } from "./run.ts";
6-
import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
6+
import {
7+
fileExists,
8+
getOptionalInput,
9+
getRequiredInput,
10+
throwOnRenamedInputs,
11+
} from "./utils.ts";
712

813
(async () => {
14+
throwOnRenamedInputs({
15+
commitMode: "commit-mode",
16+
createGithubReleases: "create-github-releases",
17+
prDraft: "pr-draft",
18+
setupGitUser: "setup-git-user",
19+
});
20+
921
const githubToken = getRequiredInput("github-token");
1022
if (process.env.GITHUB_TOKEN && process.env.GITHUB_TOKEN !== githubToken) {
1123
throw new Error(
@@ -18,14 +30,14 @@ import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
1830
// If the user needs to change the cwd, set `working-directory` in the step instead
1931
const cwd = process.cwd();
2032

21-
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
22-
const prDraft = getOptionalInput("prDraft");
33+
const commitMode = getOptionalInput("commit-mode") ?? "git-cli";
34+
const prDraft = getOptionalInput("pr-draft");
2335
if (commitMode !== "git-cli" && commitMode !== "github-api") {
2436
core.setFailed(`Invalid commit mode: ${commitMode}`);
2537
return;
2638
}
2739
if (prDraft !== undefined && prDraft !== "always" && prDraft !== "create") {
28-
core.setFailed(`Invalid prDraft: ${prDraft}`);
40+
core.setFailed(`Invalid pr-draft: ${prDraft}`);
2941
return;
3042
}
3143
const github = new GitHub({
@@ -34,7 +46,7 @@ import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
3446
commitMode,
3547
});
3648

37-
let setupGitUser = core.getBooleanInput("setupGitUser");
49+
let setupGitUser = core.getBooleanInput("setup-git-user");
3850

3951
if (setupGitUser) {
4052
core.info("setting git user");
@@ -51,8 +63,8 @@ import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
5163
let hasPublishScript = !!publishScript;
5264

5365
core.setOutput("published", "false");
54-
core.setOutput("publishedPackages", "[]");
55-
core.setOutput("hasChangesets", String(hasChangesets));
66+
core.setOutput("published-packages", "[]");
67+
core.setOutput("has-changesets", String(hasChangesets));
5668

5769
switch (true) {
5870
case !hasChangesets && !hasPublishScript:
@@ -113,14 +125,14 @@ import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
113125
const result = await runPublish({
114126
script: publishScript,
115127
github,
116-
createGithubReleases: core.getBooleanInput("createGithubReleases"),
128+
createGithubReleases: core.getBooleanInput("create-github-releases"),
117129
cwd,
118130
});
119131

120132
if (result.published) {
121133
core.setOutput("published", "true");
122134
core.setOutput(
123-
"publishedPackages",
135+
"published-packages",
124136
JSON.stringify(result.publishedPackages),
125137
);
126138
}
@@ -154,7 +166,7 @@ import { fileExists, getOptionalInput, getRequiredInput } from "./utils.ts";
154166
branch: getOptionalInput("branch"),
155167
});
156168

157-
core.setOutput("pullRequestNumber", String(pullRequestNumber));
169+
core.setOutput("pull-request-number", String(pullRequestNumber));
158170

159171
return;
160172
}

‎src/utils.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ export function getRequiredInput(name: string) {
135135
return core.getInput(name, { required: true });
136136
}
137137

138+
export function throwOnRenamedInputs(renames: Record<string, string>) {
139+
for (const [oldInput, newInput] of Object.entries(renames)) {
140+
if (core.getInput(oldInput)) {
141+
throw new Error(
142+
`The input "${oldInput}" has been renamed to "${newInput}". Please update your workflow file.`,
143+
);
144+
}
145+
}
146+
}
147+
138148
function resolveChangesetsCli(cwd: string) {
139149
return require.resolve("@changesets/cli/bin.js", {
140150
paths: [cwd],

0 commit comments

Comments
 (0)