Skip to content

Commit 37f42c5

Browse files
Copilotparkerbxyz
andcommitted
feat: add client-id input and deprecate app-id
Co-authored-by: parkerbxyz <[email protected]>
1 parent 8204e76 commit 37f42c5

8 files changed

Lines changed: 80 additions & 25 deletions

File tree

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ GitHub Action for creating a GitHub App installation access token.
99
In order to use this action, you need to:
1010

1111
1. [Register new GitHub App](https://docs.github.com/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app).
12-
2. [Store the App's Client ID (recommended) or App ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_ID`).
12+
2. [Store the App's Client ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_CLIENT_ID`).
1313
3. [Store the App's private key in your repository secrets](https://docs.github.com/actions/security-guides/encrypted-secrets?tool=webui#creating-encrypted-secrets-for-a-repository) (example: `PRIVATE_KEY`).
1414

15-
Pass the App's Client ID or App ID using the `app-id` input. GitHub recommends using the Client ID when available.
15+
Pass the App's Client ID using the `client-id` input. The legacy `app-id` input remains available for compatibility, but is deprecated.
1616

1717
> [!IMPORTANT]
1818
> An installation access token expires after 1 hour. Please [see this comment](https://github.com/actions/create-github-app-token/issues/121#issuecomment-2043214796) for alternative approaches if you have long-running processes.
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/create-github-app-token@v3
3434
id: app-token
3535
with:
36-
app-id: ${{ vars.APP_ID }}
36+
client-id: ${{ vars.APP_CLIENT_ID }}
3737
private-key: ${{ secrets.PRIVATE_KEY }}
3838
- uses: ./actions/staging-tests
3939
with:
@@ -53,7 +53,7 @@ jobs:
5353
id: app-token
5454
with:
5555
# required
56-
app-id: ${{ vars.APP_ID }}
56+
client-id: ${{ vars.APP_CLIENT_ID }}
5757
private-key: ${{ secrets.PRIVATE_KEY }}
5858
- uses: actions/checkout@v6
5959
with:
@@ -79,7 +79,7 @@ jobs:
7979
id: app-token
8080
with:
8181
# required
82-
app-id: ${{ vars.APP_ID }}
82+
client-id: ${{ vars.APP_CLIENT_ID }}
8383
private-key: ${{ secrets.PRIVATE_KEY }}
8484
- name: Get GitHub App User ID
8585
id: get-user-id
@@ -104,7 +104,7 @@ jobs:
104104
id: app-token
105105
with:
106106
# required
107-
app-id: ${{ vars.APP_ID }}
107+
client-id: ${{ vars.APP_CLIENT_ID }}
108108
private-key: ${{ secrets.PRIVATE_KEY }}
109109
- name: Get GitHub App User ID
110110
id: get-user-id
@@ -140,7 +140,7 @@ jobs:
140140
- uses: actions/create-github-app-token@v3
141141
id: app-token
142142
with:
143-
app-id: ${{ vars.APP_ID }}
143+
client-id: ${{ vars.APP_CLIENT_ID }}
144144
private-key: ${{ secrets.PRIVATE_KEY }}
145145
owner: ${{ github.repository_owner }}
146146
- uses: peter-evans/create-or-update-comment@v4
@@ -162,7 +162,7 @@ jobs:
162162
- uses: actions/create-github-app-token@v3
163163
id: app-token
164164
with:
165-
app-id: ${{ vars.APP_ID }}
165+
client-id: ${{ vars.APP_CLIENT_ID }}
166166
private-key: ${{ secrets.PRIVATE_KEY }}
167167
owner: ${{ github.repository_owner }}
168168
repositories: |
@@ -187,7 +187,7 @@ jobs:
187187
- uses: actions/create-github-app-token@v3
188188
id: app-token
189189
with:
190-
app-id: ${{ vars.APP_ID }}
190+
client-id: ${{ vars.APP_CLIENT_ID }}
191191
private-key: ${{ secrets.PRIVATE_KEY }}
192192
owner: another-owner
193193
- uses: peter-evans/create-or-update-comment@v4
@@ -212,7 +212,7 @@ jobs:
212212
- uses: actions/create-github-app-token@v3
213213
id: app-token
214214
with:
215-
app-id: ${{ vars.APP_ID }}
215+
client-id: ${{ vars.APP_CLIENT_ID }}
216216
private-key: ${{ secrets.PRIVATE_KEY }}
217217
owner: ${{ github.repository_owner }}
218218
permission-issues: write
@@ -254,7 +254,7 @@ jobs:
254254
- uses: actions/create-github-app-token@v3
255255
id: app-token
256256
with:
257-
app-id: ${{ vars.APP_ID }}
257+
client-id: ${{ vars.APP_CLIENT_ID }}
258258
private-key: ${{ secrets.PRIVATE_KEY }}
259259
owner: ${{ matrix.owners-and-repos.owner }}
260260
repositories: ${{ join(matrix.owners-and-repos.repos) }}
@@ -283,7 +283,7 @@ jobs:
283283
id: create_token
284284
uses: actions/create-github-app-token@v3
285285
with:
286-
app-id: ${{ vars.GHES_APP_ID }}
286+
client-id: ${{ vars.GHES_APP_CLIENT_ID }}
287287
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
288288
owner: ${{ vars.GHES_INSTALLATION_ORG }}
289289
github-api-url: ${{ vars.GITHUB_API_URL }}
@@ -312,15 +312,24 @@ If you set `HTTP_PROXY` or `HTTPS_PROXY`, also set `NODE_USE_ENV_PROXY: "1"` on
312312
NO_PROXY: github.example.com
313313
NODE_USE_ENV_PROXY: "1"
314314
with:
315-
app-id: ${{ vars.APP_ID }}
315+
client-id: ${{ vars.APP_CLIENT_ID }}
316316
private-key: ${{ secrets.PRIVATE_KEY }}
317317
```
318318

319319
## Inputs
320320

321+
### `client-id`
322+
323+
**Optional:** GitHub App Client ID. This is the recommended input.
324+
321325
### `app-id`
322326

323-
**Required:** GitHub App Client ID or App ID. GitHub recommends using the Client ID when available.
327+
**Optional:** GitHub App ID.
328+
329+
> [!WARNING]
330+
> `app-id` is deprecated. Use `client-id` instead.
331+
332+
You must set either `client-id` or `app-id`. If both are set, `client-id` takes precedence.
324333

325334
### `private-key`
326335

@@ -340,7 +349,7 @@ steps:
340349
id: app-token
341350
uses: actions/create-github-app-token@v3
342351
with:
343-
app-id: ${{ vars.APP_ID }}
352+
client-id: ${{ vars.APP_CLIENT_ID }}
344353
private-key: ${{ steps.decode.outputs.private-key }}
345354
```
346355

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ branding:
55
icon: "lock"
66
color: "gray-dark"
77
inputs:
8+
client-id:
9+
description: "GitHub App Client ID"
10+
required: false
811
app-id:
9-
description: "GitHub App ID or Client ID"
10-
required: true
12+
description: "GitHub App ID"
13+
required: false
14+
deprecationMessage: "Use 'client-id' instead."
1115
private-key:
1216
description: "GitHub App private key"
1317
required: true

dist/main.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23307,7 +23307,10 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
2330723307
}
2330823308
async function run() {
2330923309
ensureNativeProxySupport();
23310-
const appId = getInput("app-id");
23310+
const appId = getInput("client-id") || getInput("app-id");
23311+
if (!appId) {
23312+
throw new Error("Either 'client-id' or 'app-id' input must be set");
23313+
}
2331123314
const privateKey = getInput("private-key");
2331223315
const owner = getInput("owner");
2331323316
const repositories = getInput("repositories").split(/[\n,]+/).map((s) => s.trim()).filter((x) => x !== "");

main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
1818
async function run() {
1919
ensureNativeProxySupport();
2020

21-
const appId = core.getInput("app-id");
21+
const appId = core.getInput("client-id") || core.getInput("app-id");
22+
if (!appId) {
23+
throw new Error("Either 'client-id' or 'app-id' input must be set");
24+
}
2225
const privateKey = core.getInput("private-key");
2326
const owner = core.getInput("owner");
2427
const repositories = core

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ node --test --test-update-snapshots tests/index.js
3333
We have tests both for the `main.js` and `post.js` scripts.
3434

3535
- If you do not expect an error, take [main-token-permissions-set.test.js](tests/main-token-permissions-set.test.js) as a starting point.
36-
- If your test has an expected error, take [main-missing-app-id.test.js](tests/main-missing-app-id.test.js) as a starting point.
36+
- If your test has an expected error, take [main-missing-client-and-app-id.test.js](tests/main-missing-client-and-app-id.test.js) as a starting point.

tests/index.js.snapshot

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
exports[`action-deprecated-inputs.test.js > stdout 1`] = `
2+
app-id — Use 'client-id' instead.
3+
`;
4+
15
exports[`main-client-id.test.js > stdout 1`] = `
26
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
37
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
@@ -34,6 +38,19 @@ POST /api/v3/app/installations/123456/access_tokens
3438
{"repositories":["create-github-app-token"]}
3539
`;
3640

41+
exports[`main-missing-client-and-app-id.test.js > stderr 1`] = `
42+
Error: Either 'client-id' or 'app-id' input must be set
43+
at run (file:///home/runner/work/create-github-app-token/create-github-app-token/main.js:23:11)
44+
at file:///home/runner/work/create-github-app-token/create-github-app-token/main.js:51:16
45+
 at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
46+
 at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:661:26)
47+
at async file:///home/runner/work/create-github-app-token/create-github-app-token/tests/main-missing-client-and-app-id.test.js:12:30
48+
`;
49+
50+
exports[`main-missing-client-and-app-id.test.js > stdout 1`] = `
51+
::error::Either 'client-id' or 'app-id' input must be set
52+
`;
53+
3754
exports[`main-missing-owner.test.js > stderr 1`] = `
3855
GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
3956
`;

tests/main-client-id.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { test } from "./main.js";
1+
import { DEFAULT_ENV, test } from "./main.js";
22

3-
// Verify `main` accepts a GitHub App client ID via the `app-id` input
4-
await test(() => {
5-
process.env["INPUT_APP-ID"] = "Iv1.0123456789abcdef";
6-
});
3+
// Verify `main` accepts a GitHub App client ID via the `client-id` input
4+
await test(
5+
() => {},
6+
{
7+
...DEFAULT_ENV,
8+
"INPUT_CLIENT-ID": "Iv1.0123456789abcdef",
9+
"INPUT_APP-ID": "",
10+
}
11+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { DEFAULT_ENV } from "./main.js";
2+
3+
for (const [key, value] of Object.entries({
4+
...DEFAULT_ENV,
5+
"INPUT_CLIENT-ID": "",
6+
"INPUT_APP-ID": "",
7+
})) {
8+
process.env[key] = value;
9+
}
10+
11+
// Verify `main` exits with an error when neither `client-id` nor `app-id` is set.
12+
const { default: promise } = await import("../main.js");
13+
await promise;
14+
process.exitCode = 0;

0 commit comments

Comments
 (0)