Skip to content

Commit 7b1d2ae

Browse files
authored
feat: use dash notation for inputs (deprecates underscore notation) (#59)
Fixes #57 This PR implements the 3-step plan proposed by @gr2m in #57 (comment): > 1. Support both input types > 2. Log a deprecation warning for the old notation > 3. Add a test for deprecations Although this PR supports both input formats simultaneously, I opted _not_ to document the old format in the updated README. That’s a decision I’m happy to revisit, if y’all would prefer to have documentation for both the old and new formats.
1 parent bdb2377 commit 7b1d2ae

17 files changed

+145
-33
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
- uses: actions/create-github-app-token@v1
1818
id: app-token
1919
with:
20-
app_id: ${{ vars.RELEASER_APP_ID }}
21-
private_key: ${{ secrets.RELEASER_APP_PRIVATE_KEY }}
20+
app-id: ${{ vars.RELEASER_APP_ID }}
21+
private-key: ${{ secrets.RELEASER_APP_PRIVATE_KEY }}
2222
- uses: actions/checkout@v4
2323
with:
2424
token: ${{ steps.app-token.outputs.token }}

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
- uses: ./ # Uses the action in the root directory
3939
id: test
4040
with:
41-
app_id: ${{ vars.TEST_APP_ID }}
42-
private_key: ${{ secrets.TEST_APP_PRIVATE_KEY }}
41+
app-id: ${{ vars.TEST_APP_ID }}
42+
private-key: ${{ secrets.TEST_APP_PRIVATE_KEY }}
4343
- uses: octokit/request-action@v2.x
4444
id: get-repository
4545
env:

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
- uses: actions/create-github-app-token@v1
2323
id: app-token
2424
with:
25-
app_id: ${{ vars.APP_ID }}
26-
private_key: ${{ secrets.PRIVATE_KEY }}
25+
app-id: ${{ vars.APP_ID }}
26+
private-key: ${{ secrets.PRIVATE_KEY }}
2727
- uses: peter-evans/create-or-update-comment@v3
2828
with:
2929
token: ${{ steps.app-token.outputs.token }}
@@ -44,8 +44,8 @@ jobs:
4444
id: app-token
4545
with:
4646
# required
47-
app_id: ${{ vars.APP_ID }}
48-
private_key: ${{ secrets.PRIVATE_KEY }}
47+
app-id: ${{ vars.APP_ID }}
48+
private-key: ${{ secrets.PRIVATE_KEY }}
4949
- uses: actions/checkout@v3
5050
with:
5151
token: ${{ steps.app-token.outputs.token }}
@@ -69,8 +69,8 @@ jobs:
6969
- uses: actions/create-github-app-token@v1
7070
id: app-token
7171
with:
72-
app_id: ${{ vars.APP_ID }}
73-
private_key: ${{ secrets.PRIVATE_KEY }}
72+
app-id: ${{ vars.APP_ID }}
73+
private-key: ${{ secrets.PRIVATE_KEY }}
7474
owner: ${{ github.repository_owner }}
7575
- uses: peter-evans/create-or-update-comment@v3
7676
with:
@@ -91,8 +91,8 @@ jobs:
9191
- uses: actions/create-github-app-token@v1
9292
id: app-token
9393
with:
94-
app_id: ${{ vars.APP_ID }}
95-
private_key: ${{ secrets.PRIVATE_KEY }}
94+
app-id: ${{ vars.APP_ID }}
95+
private-key: ${{ secrets.PRIVATE_KEY }}
9696
owner: ${{ github.repository_owner }}
9797
repositories: "repo1,repo2"
9898
- uses: peter-evans/create-or-update-comment@v3
@@ -114,8 +114,8 @@ jobs:
114114
- uses: actions/create-github-app-token@v1
115115
id: app-token
116116
with:
117-
app_id: ${{ vars.APP_ID }}
118-
private_key: ${{ secrets.PRIVATE_KEY }}
117+
app-id: ${{ vars.APP_ID }}
118+
private-key: ${{ secrets.PRIVATE_KEY }}
119119
owner: another-owner
120120
- uses: peter-evans/create-or-update-comment@v3
121121
with:
@@ -126,11 +126,11 @@ jobs:
126126

127127
## Inputs
128128

129-
### `app_id`
129+
### `app-id`
130130

131131
**Required:** GitHub App ID.
132132

133-
### `private_key`
133+
### `private-key`
134134

135135
**Required:** GitHub App private key.
136136

@@ -145,7 +145,7 @@ jobs:
145145
> [!NOTE]
146146
> If `owner` is set and `repositories` is empty, access will be scoped to all repositories in the provided repository owner's installation. If `owner` and `repositories` are empty, access will be scoped to only the current repository.
147147

148-
### `skip_token_revoke`
148+
### `skip-token-revoke`
149149

150150
**Optional:** If truthy, the token will not be revoked when the current job is complete.
151151

action.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,33 @@ branding:
55
icon: "lock"
66
color: "gray-dark"
77
inputs:
8+
app-id:
9+
description: "GitHub App ID"
10+
required: false # TODO: When 'app_id' is removed, make 'app-id' required
811
app_id:
912
description: "GitHub App ID"
10-
required: true
13+
required: false
14+
deprecationMessage: "'app_id' is deprecated and will be removed in a future version. Use 'app-id' instead."
15+
private-key:
16+
description: "GitHub App private key"
17+
required: false # TODO: When 'private_key' is removed, make 'private-key' required
1118
private_key:
1219
description: "GitHub App private key"
13-
required: true
20+
required: false
21+
deprecationMessage: "'private_key' is deprecated and will be removed in a future version. Use 'private-key' instead."
1422
owner:
1523
description: "GitHub App owner (defaults to current repository owner)"
1624
required: false
1725
repositories:
1826
description: "Repositories to install the GitHub App on (defaults to current repository if owner is unset)"
1927
required: false
28+
skip-token-revoke:
29+
description: "If truthy, the token will not be revoked when the current job is complete"
30+
required: false
2031
skip_token_revoke:
2132
description: "If truthy, the token will not be revoked when the current job is complete"
2233
required: false
34+
deprecationMessage: "'skip_token_revoke' is deprecated and will be removed in a future version. Use 'skip-token-revoke' instead."
2335
outputs:
2436
token:
2537
description: "GitHub installation access token"

dist/main.cjs

+11-3
Original file line numberDiff line numberDiff line change
@@ -10103,11 +10103,19 @@ if (!process.env.GITHUB_REPOSITORY) {
1010310103
if (!process.env.GITHUB_REPOSITORY_OWNER) {
1010410104
throw new Error("GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'");
1010510105
}
10106-
var appId = import_core.default.getInput("app_id");
10107-
var privateKey = import_core.default.getInput("private_key");
10106+
var appId = import_core.default.getInput("app-id") || import_core.default.getInput("app_id");
10107+
if (!appId) {
10108+
throw new Error("Input required and not supplied: app-id");
10109+
}
10110+
var privateKey = import_core.default.getInput("private-key") || import_core.default.getInput("private_key");
10111+
if (!privateKey) {
10112+
throw new Error("Input required and not supplied: private-key");
10113+
}
1010810114
var owner = import_core.default.getInput("owner");
1010910115
var repositories = import_core.default.getInput("repositories");
10110-
var skipTokenRevoke = Boolean(import_core.default.getInput("skip_token_revoke"));
10116+
var skipTokenRevoke = Boolean(
10117+
import_core.default.getInput("skip-token-revoke") || import_core.default.getInput("skip_token_revoke")
10118+
);
1011110119
main(
1011210120
appId,
1011310121
privateKey,

dist/post.cjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,9 @@ var import_core = __toESM(require_core(), 1);
29732973

29742974
// lib/post.js
29752975
async function post(core2, request2) {
2976-
const skipTokenRevoke = Boolean(core2.getInput("skip_token_revoke"));
2976+
const skipTokenRevoke = Boolean(
2977+
core2.getInput("skip-token-revoke") || core2.getInput("skip_token_revoke")
2978+
);
29772979
if (skipTokenRevoke) {
29782980
core2.info("Token revocation was skipped");
29792981
return;

lib/post.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* @param {import("@octokit/request").request} request
66
*/
77
export async function post(core, request) {
8-
const skipTokenRevoke = Boolean(core.getInput("skip_token_revoke"));
8+
const skipTokenRevoke = Boolean(
9+
core.getInput("skip-token-revoke") || core.getInput("skip_token_revoke")
10+
);
911

1012
if (skipTokenRevoke) {
1113
core.info("Token revocation was skipped");

main.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
1414
throw new Error("GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'");
1515
}
1616

17-
const appId = core.getInput("app_id");
18-
const privateKey = core.getInput("private_key");
17+
const appId = core.getInput("app-id") || core.getInput("app_id");
18+
if (!appId) {
19+
// The 'app_id' input was previously required, but it and 'app-id' are both optional now, until the former is removed. Still, we want to ensure that at least one of them is set.
20+
throw new Error("Input required and not supplied: app-id");
21+
}
22+
const privateKey = core.getInput("private-key") || core.getInput("private_key");
23+
if (!privateKey) {
24+
// The 'private_key' input was previously required, but it and 'private-key' are both optional now, until the former is removed. Still, we want to ensure that at least one of them is set.
25+
throw new Error("Input required and not supplied: private-key");
26+
}
1927
const owner = core.getInput("owner");
2028
const repositories = core.getInput("repositories");
2129

22-
const skipTokenRevoke = Boolean(core.getInput("skip_token_revoke"));
30+
const skipTokenRevoke = Boolean(
31+
core.getInput("skip-token-revoke") || core.getInput("skip_token_revoke")
32+
);
2333

2434
main(
2535
appId,

package-lock.json

+11-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"esbuild": "^0.19.4",
2424
"execa": "^8.0.1",
2525
"open-cli": "^7.2.0",
26-
"undici": "^5.25.2"
26+
"undici": "^5.25.2",
27+
"yaml": "^2.3.2"
2728
},
2829
"release": {
2930
"branches": [
@@ -48,4 +49,4 @@
4849
]
4950
]
5051
}
51-
}
52+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { readFileSync } from "node:fs";
2+
import * as url from "node:url";
3+
import YAML from "yaml";
4+
5+
const action = YAML.parse(
6+
readFileSync(
7+
url.fileURLToPath(new URL("../action.yml", import.meta.url)),
8+
"utf8"
9+
)
10+
);
11+
12+
for (const [key, value] of Object.entries(action.inputs)) {
13+
if ("deprecationMessage" in value) {
14+
console.log(`${key}${value.deprecationMessage}`);
15+
}
16+
}

tests/main-missing-app-id.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
process.env.GITHUB_REPOSITORY_OWNER = "actions";
2+
process.env.GITHUB_REPOSITORY = "actions/create-github-app-token";
3+
4+
// Verify `main` exits with an error when neither the `app-id` nor `app_id` input is set.
5+
try {
6+
await import("../main.js");
7+
} catch (error) {
8+
console.error(error.message);
9+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
process.env.GITHUB_REPOSITORY_OWNER = "actions";
2+
process.env.GITHUB_REPOSITORY = "actions/create-github-app-token";
3+
process.env["INPUT_APP-ID"] = "123456";
4+
5+
// Verify `main` exits with an error when neither the `private-key` nor `private_key` input is set.
6+
try {
7+
await import("../main.js");
8+
} catch (error) {
9+
console.error(error.message);
10+
}

tests/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export async function test(cb = (_mockPool) => {}) {
88
process.env.GITHUB_REPOSITORY = "actions/create-github-app-token";
99
// inputs are set as environment variables with the prefix INPUT_
1010
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
11-
process.env.INPUT_APP_ID = "123456";
12-
process.env.INPUT_PRIVATE_KEY = `-----BEGIN RSA PRIVATE KEY-----
11+
process.env["INPUT_APP-ID"] = "123456";
12+
process.env["INPUT_PRIVATE-KEY"] = `-----BEGIN RSA PRIVATE KEY-----
1313
MIIEowIBAAKCAQEA280nfuUM9w00Ib9E2rvZJ6Qu3Ua3IqR34ZlK53vn/Iobn2EL
1414
Z9puc5Q/nFBU15NKwHyQNb+OG2hTCkjd1Xi9XPzEOH1r42YQmTGq8YCkUSkk6KZA
1515
5dnhLwN9pFquT9fQgrf4r1D5GJj3rqvj8JDr1sBmunArqY5u4gziSrIohcjLIZV0

tests/post-token-skipped.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ process.env.STATE_token = "secret123";
66

77
// inputs are set as environment variables with the prefix INPUT_
88
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
9-
process.env.INPUT_SKIP_TOKEN_REVOKE = "true";
9+
process.env["INPUT_SKIP-TOKEN-REVOKE"] = "true";
1010

1111
const mockAgent = new MockAgent();
1212

tests/snapshots/index.js.md

+32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ The actual snapshot is saved in `index.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7+
## action-deprecated-inputs.test.js
8+
9+
> stderr
10+
11+
''
12+
13+
> stdout
14+
15+
`app_id — 'app_id' is deprecated and will be removed in a future version. Use 'app-id' instead.␊
16+
private_key — 'private_key' is deprecated and will be removed in a future version. Use 'private-key' instead.␊
17+
skip_token_revoke — 'skip_token_revoke' is deprecated and will be removed in a future version. Use 'skip-token-revoke' instead.`
18+
19+
## main-missing-app-id.test.js
20+
21+
> stderr
22+
23+
'Input required and not supplied: app-id'
24+
25+
> stdout
26+
27+
''
28+
729
## main-missing-owner.test.js
830

931
> stderr
@@ -14,6 +36,16 @@ Generated by [AVA](https://avajs.dev).
1436
1537
''
1638

39+
## main-missing-private-key.test.js
40+
41+
> stderr
42+
43+
'Input required and not supplied: private-key'
44+
45+
> stdout
46+
47+
''
48+
1749
## main-missing-repository.test.js
1850

1951
> stderr

tests/snapshots/index.js.snap

188 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)