Skip to content

Commit e6bd4e6

Browse files
CopilotparkerbxyzCopilot
authored
feat: add client-id input and deprecate app-id (#353)
GitHub now recommends using a GitHub App's Client ID for authentication. This PR adds a first-class `client-id` input, keeps `app-id` available for compatibility, and makes the migration path explicit in both runtime behavior and documentation. ### Action inputs - Adds a new `client-id` input - Removes `required` from `app-id` - Marks `app-id` as deprecated in `action.yml` ### Runtime behavior - Updates input parsing to prefer `client-id` - Falls back to `app-id` for existing workflows - Adds a clear error when neither `client-id` nor `app-id` is provided ### Docs - Updates the README to recommend `client-id` - Switches usage examples to `client-id` - Documents that `app-id` is deprecated and that `client-id` takes precedence if both are set ### Regression coverage - Adds a focused test proving a client-ID-shaped value works through the new `client-id` input - Adds coverage for the missing-ID validation path - Updates snapshots to lock in the new metadata and runtime behavior ### Resulting usage Users can migrate to the new input name directly: ```yaml - uses: actions/create-github-app-token@v3 with: client-id: ${{ vars.GITHUB_APP_CLIENT_ID }} private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }} ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkerbxyz <17183625+parkerbxyz@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 076e948 commit e6bd4e6

File tree

11 files changed

+141
-40
lines changed

11 files changed

+141
-40
lines changed

README.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ 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 ID or Client ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_ID`).
13-
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`).
12+
2. [Store the App's Client ID in your repository environment variables](https://docs.github.com/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables#defining-configuration-variables-for-multiple-workflows) (example: `GITHUB_APP_CLIENT_ID`).
13+
3. [Store the App's private key in your repository secrets](https://docs.github.com/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets?tool=webui#creating-secrets-for-a-repository) (example: `GITHUB_APP_PRIVATE_KEY`).
1414

1515
> [!IMPORTANT]
1616
> 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.
@@ -31,8 +31,8 @@ jobs:
3131
- uses: actions/create-github-app-token@v3
3232
id: app-token
3333
with:
34-
app-id: ${{ vars.APP_ID }}
35-
private-key: ${{ secrets.PRIVATE_KEY }}
34+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
35+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
3636
- uses: ./actions/staging-tests
3737
with:
3838
token: ${{ steps.app-token.outputs.token }}
@@ -51,8 +51,8 @@ jobs:
5151
id: app-token
5252
with:
5353
# required
54-
app-id: ${{ vars.APP_ID }}
55-
private-key: ${{ secrets.PRIVATE_KEY }}
54+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
55+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
5656
- uses: actions/checkout@v6
5757
with:
5858
token: ${{ steps.app-token.outputs.token }}
@@ -77,8 +77,8 @@ jobs:
7777
id: app-token
7878
with:
7979
# required
80-
app-id: ${{ vars.APP_ID }}
81-
private-key: ${{ secrets.PRIVATE_KEY }}
80+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
81+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
8282
- name: Get GitHub App User ID
8383
id: get-user-id
8484
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
@@ -102,8 +102,8 @@ jobs:
102102
id: app-token
103103
with:
104104
# required
105-
app-id: ${{ vars.APP_ID }}
106-
private-key: ${{ secrets.PRIVATE_KEY }}
105+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
106+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
107107
- name: Get GitHub App User ID
108108
id: get-user-id
109109
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
@@ -138,8 +138,8 @@ jobs:
138138
- uses: actions/create-github-app-token@v3
139139
id: app-token
140140
with:
141-
app-id: ${{ vars.APP_ID }}
142-
private-key: ${{ secrets.PRIVATE_KEY }}
141+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
142+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
143143
owner: ${{ github.repository_owner }}
144144
- uses: peter-evans/create-or-update-comment@v4
145145
with:
@@ -160,8 +160,8 @@ jobs:
160160
- uses: actions/create-github-app-token@v3
161161
id: app-token
162162
with:
163-
app-id: ${{ vars.APP_ID }}
164-
private-key: ${{ secrets.PRIVATE_KEY }}
163+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
164+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
165165
owner: ${{ github.repository_owner }}
166166
repositories: |
167167
repo1
@@ -185,8 +185,8 @@ jobs:
185185
- uses: actions/create-github-app-token@v3
186186
id: app-token
187187
with:
188-
app-id: ${{ vars.APP_ID }}
189-
private-key: ${{ secrets.PRIVATE_KEY }}
188+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
189+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
190190
owner: another-owner
191191
- uses: peter-evans/create-or-update-comment@v4
192192
with:
@@ -210,8 +210,8 @@ jobs:
210210
- uses: actions/create-github-app-token@v3
211211
id: app-token
212212
with:
213-
app-id: ${{ vars.APP_ID }}
214-
private-key: ${{ secrets.PRIVATE_KEY }}
213+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
214+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
215215
owner: ${{ github.repository_owner }}
216216
permission-issues: write
217217
- uses: peter-evans/create-or-update-comment@v4
@@ -252,8 +252,8 @@ jobs:
252252
- uses: actions/create-github-app-token@v3
253253
id: app-token
254254
with:
255-
app-id: ${{ vars.APP_ID }}
256-
private-key: ${{ secrets.PRIVATE_KEY }}
255+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
256+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
257257
owner: ${{ matrix.owners-and-repos.owner }}
258258
repositories: ${{ join(matrix.owners-and-repos.repos) }}
259259
- uses: octokit/request-action@v2.x
@@ -281,7 +281,7 @@ jobs:
281281
id: create_token
282282
uses: actions/create-github-app-token@v3
283283
with:
284-
app-id: ${{ vars.GHES_APP_ID }}
284+
client-id: ${{ vars.GHES_APP_CLIENT_ID }}
285285
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
286286
owner: ${{ vars.GHES_INSTALLATION_ORG }}
287287
github-api-url: ${{ vars.GITHUB_API_URL }}
@@ -310,15 +310,18 @@ If you set `HTTP_PROXY` or `HTTPS_PROXY`, also set `NODE_USE_ENV_PROXY: "1"` on
310310
NO_PROXY: github.example.com
311311
NODE_USE_ENV_PROXY: "1"
312312
with:
313-
app-id: ${{ vars.APP_ID }}
314-
private-key: ${{ secrets.PRIVATE_KEY }}
313+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
314+
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
315315
```
316316

317317
## Inputs
318318

319-
### `app-id`
319+
### `client-id` or `app-id`
320320

321-
**Required:** GitHub App ID.
321+
**Required:** GitHub App Client ID.
322+
323+
> [!NOTE]
324+
> The legacy `app-id` input is also accepted, but `client-id` is recommended.
322325

323326
### `private-key`
324327

@@ -331,14 +334,14 @@ steps:
331334
- name: Decode the GitHub App Private Key
332335
id: decode
333336
run: |
334-
private_key=$(echo "${{ secrets.PRIVATE_KEY }}" | base64 -d | awk 'BEGIN {ORS="\\n"} {print}' | head -c -2) &> /dev/null
337+
private_key=$(echo "${{ secrets.GITHUB_APP_PRIVATE_KEY }}" | base64 -d | awk 'BEGIN {ORS="\\n"} {print}' | head -c -2) &> /dev/null
335338
echo "::add-mask::$private_key"
336339
echo "private-key=$private_key" >> "$GITHUB_OUTPUT"
337340
- name: Generate GitHub App Token
338341
id: app-token
339342
uses: actions/create-github-app-token@v3
340343
with:
341-
app-id: ${{ vars.APP_ID }}
344+
client-id: ${{ vars.GITHUB_APP_CLIENT_ID }}
342345
private-key: ${{ steps.decode.outputs.private-key }}
343346
```
344347

action.yml

Lines changed: 5 additions & 1 deletion
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:
912
description: "GitHub App ID"
10-
required: true
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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23153,7 +23153,7 @@ async function pRetry(input, options = {}) {
2315323153
}
2315423154

2315523155
// lib/main.js
23156-
async function main(appId, privateKey, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
23156+
async function main(clientId, privateKey, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
2315723157
let parsedOwner = "";
2315823158
let parsedRepositoryNames = [];
2315923159
if (!owner && repositories.length === 0) {
@@ -23188,7 +23188,7 @@ async function main(appId, privateKey, owner, repositories, permissions, core, c
2318823188
);
2318923189
}
2319023190
const auth5 = createAppAuth2({
23191-
appId,
23191+
appId: clientId,
2319223192
privateKey,
2319323193
request: request2
2319423194
});
@@ -23307,14 +23307,17 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
2330723307
}
2330823308
async function run() {
2330923309
ensureNativeProxySupport();
23310-
const appId = getInput("app-id");
23310+
const clientId = getInput("client-id") || getInput("app-id");
23311+
if (!clientId) {
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 !== "");
2331423317
const skipTokenRevoke = getBooleanInput("skip-token-revoke");
2331523318
const permissions = getPermissionsFromInputs(process.env);
2331623319
return main(
23317-
appId,
23320+
clientId,
2331823321
privateKey,
2331923322
owner,
2332023323
repositories,

lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
22
// @ts-check
33

44
/**
5-
* @param {string} appId
5+
* @param {string} clientId
66
* @param {string} privateKey
77
* @param {string} owner
88
* @param {string[]} repositories
@@ -13,7 +13,7 @@ import pRetry from "p-retry";
1313
* @param {boolean} skipTokenRevoke
1414
*/
1515
export async function main(
16-
appId,
16+
clientId,
1717
privateKey,
1818
owner,
1919
repositories,
@@ -70,7 +70,7 @@ export async function main(
7070
}
7171

7272
const auth = createAppAuth({
73-
appId,
73+
appId: clientId,
7474
privateKey,
7575
request,
7676
});

main.js

Lines changed: 5 additions & 2 deletions
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 clientId = core.getInput("client-id") || core.getInput("app-id");
22+
if (!clientId) {
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
@@ -32,7 +35,7 @@ async function run() {
3235
const permissions = getPermissionsFromInputs(process.env);
3336

3437
return main(
35-
appId,
38+
clientId,
3639
privateKey,
3740
owner,
3841
repositories,

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ node --test --test-update-snapshots tests/index.js
3232

3333
We have tests both for the `main.js` and `post.js` scripts.
3434

35-
- 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.
35+
- If you do not expect an error, take [main-token-permissions-set.test.js](main-token-permissions-set.test.js) as a starting point.
36+
- If your test has an expected error, take [main-missing-client-and-app-id.test.js](main-missing-client-and-app-id.test.js) as a starting point.

tests/index.js.snapshot

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
exports[`action-deprecated-inputs.test.js > stdout 1`] = `
2+
app-id — Use 'client-id' instead.
3+
`;
4+
5+
exports[`main-app-id-fallback.test.js > stdout 1`] = `
6+
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
7+
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
8+
9+
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
10+
11+
::set-output name=installation-id::123456
12+
13+
::set-output name=app-slug::github-actions
14+
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
15+
::save-state name=expiresAt::2016-07-11T22:14:10Z
16+
--- REQUESTS ---
17+
GET /repos/actions/create-github-app-token/installation
18+
POST /app/installations/123456/access_tokens
19+
{"repositories":["create-github-app-token"]}
20+
`;
21+
22+
exports[`main-client-id-precedence.test.js > stdout 1`] = `
23+
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
24+
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
25+
26+
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
27+
28+
::set-output name=installation-id::123456
29+
30+
::set-output name=app-slug::github-actions
31+
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
32+
::save-state name=expiresAt::2016-07-11T22:14:10Z
33+
--- REQUESTS ---
34+
GET /repos/actions/create-github-app-token/installation
35+
POST /app/installations/123456/access_tokens
36+
{"repositories":["create-github-app-token"]}
37+
`;
38+
139
exports[`main-custom-github-api-url.test.js > stdout 1`] = `
240
Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:
341

@@ -17,6 +55,14 @@ POST /api/v3/app/installations/123456/access_tokens
1755
{"repositories":["create-github-app-token"]}
1856
`;
1957

58+
exports[`main-missing-client-and-app-id.test.js > stderr 1`] = `
59+
Either 'client-id' or 'app-id' input must be set
60+
`;
61+
62+
exports[`main-missing-client-and-app-id.test.js > stdout 1`] = `
63+
::error::Either 'client-id' or 'app-id' input must be set
64+
`;
65+
2066
exports[`main-missing-owner.test.js > stderr 1`] = `
2167
GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
2268
`;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DEFAULT_ENV, test } from "./main.js";
2+
3+
// Verify `main` falls back to `app-id` when `client-id` is not set
4+
await test(
5+
() => {},
6+
{
7+
...DEFAULT_ENV,
8+
"INPUT_CLIENT-ID": "",
9+
"INPUT_APP-ID": "123456",
10+
}
11+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DEFAULT_ENV, test } from "./main.js";
2+
3+
// Verify `client-id` takes precedence when both `client-id` and `app-id` are set
4+
await test(
5+
() => {},
6+
{
7+
...DEFAULT_ENV,
8+
"INPUT_CLIENT-ID": "Iv1.0123456789abcdef",
9+
"INPUT_APP-ID": "123456",
10+
}
11+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
// Log only the error message, not the full stack trace, because the stack
12+
// trace contains environment-specific paths and ANSI codes that differ
13+
// between local and CI environments.
14+
const _error = console.error;
15+
console.error = (err) => _error(err?.message ?? err);
16+
17+
// Verify `main` exits with an error when neither `client-id` nor `app-id` is set.
18+
const { default: promise } = await import("../main.js");
19+
await promise;
20+
process.exitCode = 0;

0 commit comments

Comments
 (0)