Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea0d3155e4 | |||
| 37f42c53d0 | |||
| 8204e76db8 | |||
| e9da44231a |
@@ -9,9 +9,11 @@ GitHub Action for creating a GitHub App installation access token.
|
|||||||
In order to use this action, you need to:
|
In order to use this action, you need to:
|
||||||
|
|
||||||
1. [Register new GitHub App](https://docs.github.com/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app).
|
1. [Register new GitHub App](https://docs.github.com/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app).
|
||||||
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`).
|
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`).
|
||||||
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`).
|
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`).
|
||||||
|
|
||||||
|
Pass the App's Client ID using the `client-id` input. The legacy `app-id` input remains available for compatibility, but is deprecated.
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> 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.
|
> 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,7 +33,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
- uses: ./actions/staging-tests
|
- uses: ./actions/staging-tests
|
||||||
with:
|
with:
|
||||||
@@ -51,7 +53,7 @@ jobs:
|
|||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
# required
|
# required
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
@@ -77,7 +79,7 @@ jobs:
|
|||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
# required
|
# required
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
- name: Get GitHub App User ID
|
- name: Get GitHub App User ID
|
||||||
id: get-user-id
|
id: get-user-id
|
||||||
@@ -102,7 +104,7 @@ jobs:
|
|||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
# required
|
# required
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
- name: Get GitHub App User ID
|
- name: Get GitHub App User ID
|
||||||
id: get-user-id
|
id: get-user-id
|
||||||
@@ -138,7 +140,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: ${{ github.repository_owner }}
|
owner: ${{ github.repository_owner }}
|
||||||
- uses: peter-evans/create-or-update-comment@v4
|
- uses: peter-evans/create-or-update-comment@v4
|
||||||
@@ -160,7 +162,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: ${{ github.repository_owner }}
|
owner: ${{ github.repository_owner }}
|
||||||
repositories: |
|
repositories: |
|
||||||
@@ -185,7 +187,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: another-owner
|
owner: another-owner
|
||||||
- uses: peter-evans/create-or-update-comment@v4
|
- uses: peter-evans/create-or-update-comment@v4
|
||||||
@@ -210,7 +212,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: ${{ github.repository_owner }}
|
owner: ${{ github.repository_owner }}
|
||||||
permission-issues: write
|
permission-issues: write
|
||||||
@@ -252,7 +254,7 @@ jobs:
|
|||||||
- uses: actions/create-github-app-token@v3
|
- uses: actions/create-github-app-token@v3
|
||||||
id: app-token
|
id: app-token
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: ${{ matrix.owners-and-repos.owner }}
|
owner: ${{ matrix.owners-and-repos.owner }}
|
||||||
repositories: ${{ join(matrix.owners-and-repos.repos) }}
|
repositories: ${{ join(matrix.owners-and-repos.repos) }}
|
||||||
@@ -281,7 +283,7 @@ jobs:
|
|||||||
id: create_token
|
id: create_token
|
||||||
uses: actions/create-github-app-token@v3
|
uses: actions/create-github-app-token@v3
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.GHES_APP_ID }}
|
client-id: ${{ vars.GHES_APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
|
||||||
owner: ${{ vars.GHES_INSTALLATION_ORG }}
|
owner: ${{ vars.GHES_INSTALLATION_ORG }}
|
||||||
github-api-url: ${{ vars.GITHUB_API_URL }}
|
github-api-url: ${{ vars.GITHUB_API_URL }}
|
||||||
@@ -310,15 +312,24 @@ If you set `HTTP_PROXY` or `HTTPS_PROXY`, also set `NODE_USE_ENV_PROXY: "1"` on
|
|||||||
NO_PROXY: github.example.com
|
NO_PROXY: github.example.com
|
||||||
NODE_USE_ENV_PROXY: "1"
|
NODE_USE_ENV_PROXY: "1"
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
|
### `client-id`
|
||||||
|
|
||||||
|
**Optional:** GitHub App Client ID. This is the recommended input.
|
||||||
|
|
||||||
### `app-id`
|
### `app-id`
|
||||||
|
|
||||||
**Required:** GitHub App ID.
|
**Optional:** GitHub App ID.
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> `app-id` is deprecated. Use `client-id` instead.
|
||||||
|
|
||||||
|
You must set either `client-id` or `app-id`. If both are set, `client-id` takes precedence.
|
||||||
|
|
||||||
### `private-key`
|
### `private-key`
|
||||||
|
|
||||||
@@ -338,7 +349,7 @@ steps:
|
|||||||
id: app-token
|
id: app-token
|
||||||
uses: actions/create-github-app-token@v3
|
uses: actions/create-github-app-token@v3
|
||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ steps.decode.outputs.private-key }}
|
private-key: ${{ steps.decode.outputs.private-key }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -5,9 +5,13 @@ branding:
|
|||||||
icon: "lock"
|
icon: "lock"
|
||||||
color: "gray-dark"
|
color: "gray-dark"
|
||||||
inputs:
|
inputs:
|
||||||
|
client-id:
|
||||||
|
description: "GitHub App Client ID"
|
||||||
|
required: false
|
||||||
app-id:
|
app-id:
|
||||||
description: "GitHub App ID"
|
description: "GitHub App ID"
|
||||||
required: true
|
required: false
|
||||||
|
deprecationMessage: "Use 'client-id' instead."
|
||||||
private-key:
|
private-key:
|
||||||
description: "GitHub App private key"
|
description: "GitHub App private key"
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
Vendored
+7
-4
@@ -23153,7 +23153,7 @@ async function pRetry(input, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lib/main.js
|
// lib/main.js
|
||||||
async function main(appId, privateKey, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
|
async function main(clientId, privateKey, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
|
||||||
let parsedOwner = "";
|
let parsedOwner = "";
|
||||||
let parsedRepositoryNames = [];
|
let parsedRepositoryNames = [];
|
||||||
if (!owner && repositories.length === 0) {
|
if (!owner && repositories.length === 0) {
|
||||||
@@ -23188,7 +23188,7 @@ async function main(appId, privateKey, owner, repositories, permissions, core, c
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const auth5 = createAppAuth2({
|
const auth5 = createAppAuth2({
|
||||||
appId,
|
appId: clientId,
|
||||||
privateKey,
|
privateKey,
|
||||||
request: request2
|
request: request2
|
||||||
});
|
});
|
||||||
@@ -23307,14 +23307,17 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
|
|||||||
}
|
}
|
||||||
async function run() {
|
async function run() {
|
||||||
ensureNativeProxySupport();
|
ensureNativeProxySupport();
|
||||||
const appId = getInput("app-id");
|
const clientId = getInput("client-id") || getInput("app-id");
|
||||||
|
if (!clientId) {
|
||||||
|
throw new Error("Either 'client-id' or 'app-id' input must be set");
|
||||||
|
}
|
||||||
const privateKey = getInput("private-key");
|
const privateKey = getInput("private-key");
|
||||||
const owner = getInput("owner");
|
const owner = getInput("owner");
|
||||||
const repositories = getInput("repositories").split(/[\n,]+/).map((s) => s.trim()).filter((x) => x !== "");
|
const repositories = getInput("repositories").split(/[\n,]+/).map((s) => s.trim()).filter((x) => x !== "");
|
||||||
const skipTokenRevoke = getBooleanInput("skip-token-revoke");
|
const skipTokenRevoke = getBooleanInput("skip-token-revoke");
|
||||||
const permissions = getPermissionsFromInputs(process.env);
|
const permissions = getPermissionsFromInputs(process.env);
|
||||||
return main(
|
return main(
|
||||||
appId,
|
clientId,
|
||||||
privateKey,
|
privateKey,
|
||||||
owner,
|
owner,
|
||||||
repositories,
|
repositories,
|
||||||
|
|||||||
+3
-3
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} appId
|
* @param {string} clientId
|
||||||
* @param {string} privateKey
|
* @param {string} privateKey
|
||||||
* @param {string} owner
|
* @param {string} owner
|
||||||
* @param {string[]} repositories
|
* @param {string[]} repositories
|
||||||
@@ -13,7 +13,7 @@ import pRetry from "p-retry";
|
|||||||
* @param {boolean} skipTokenRevoke
|
* @param {boolean} skipTokenRevoke
|
||||||
*/
|
*/
|
||||||
export async function main(
|
export async function main(
|
||||||
appId,
|
clientId,
|
||||||
privateKey,
|
privateKey,
|
||||||
owner,
|
owner,
|
||||||
repositories,
|
repositories,
|
||||||
@@ -70,7 +70,7 @@ export async function main(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auth = createAppAuth({
|
const auth = createAppAuth({
|
||||||
appId,
|
appId: clientId,
|
||||||
privateKey,
|
privateKey,
|
||||||
request,
|
request,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ if (!process.env.GITHUB_REPOSITORY_OWNER) {
|
|||||||
async function run() {
|
async function run() {
|
||||||
ensureNativeProxySupport();
|
ensureNativeProxySupport();
|
||||||
|
|
||||||
const appId = core.getInput("app-id");
|
const clientId = core.getInput("client-id") || core.getInput("app-id");
|
||||||
|
if (!clientId) {
|
||||||
|
throw new Error("Either 'client-id' or 'app-id' input must be set");
|
||||||
|
}
|
||||||
const privateKey = core.getInput("private-key");
|
const privateKey = core.getInput("private-key");
|
||||||
const owner = core.getInput("owner");
|
const owner = core.getInput("owner");
|
||||||
const repositories = core
|
const repositories = core
|
||||||
@@ -32,7 +35,7 @@ async function run() {
|
|||||||
const permissions = getPermissionsFromInputs(process.env);
|
const permissions = getPermissionsFromInputs(process.env);
|
||||||
|
|
||||||
return main(
|
return main(
|
||||||
appId,
|
clientId,
|
||||||
privateKey,
|
privateKey,
|
||||||
owner,
|
owner,
|
||||||
repositories,
|
repositories,
|
||||||
|
|||||||
+1
-1
@@ -33,4 +33,4 @@ node --test --test-update-snapshots tests/index.js
|
|||||||
We have tests both for the `main.js` and `post.js` scripts.
|
We have tests both for the `main.js` and `post.js` scripts.
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
- 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.
|
- 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.
|
||||||
|
|||||||
@@ -1,3 +1,24 @@
|
|||||||
|
exports[`action-deprecated-inputs.test.js > stdout 1`] = `
|
||||||
|
app-id — Use 'client-id' instead.
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`main-client-id.test.js > stdout 1`] = `
|
||||||
|
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
|
||||||
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||||
|
|
||||||
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||||
|
|
||||||
|
::set-output name=installation-id::123456
|
||||||
|
|
||||||
|
::set-output name=app-slug::github-actions
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z
|
||||||
|
--- REQUESTS ---
|
||||||
|
GET /repos/actions/create-github-app-token/installation
|
||||||
|
POST /app/installations/123456/access_tokens
|
||||||
|
{"repositories":["create-github-app-token"]}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`main-custom-github-api-url.test.js > stdout 1`] = `
|
exports[`main-custom-github-api-url.test.js > stdout 1`] = `
|
||||||
Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:
|
Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:
|
||||||
|
|
||||||
@@ -17,6 +38,19 @@ POST /api/v3/app/installations/123456/access_tokens
|
|||||||
{"repositories":["create-github-app-token"]}
|
{"repositories":["create-github-app-token"]}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`main-missing-client-and-app-id.test.js > stderr 1`] = `
|
||||||
|
Error: Either 'client-id' or 'app-id' input must be set
|
||||||
|
at run [90m(file:///home/runner/work/create-github-app-token/create-github-app-token/[39mmain.js:23:11[90m)[39m
|
||||||
|
at [90mfile:///home/runner/work/create-github-app-token/create-github-app-token/[39mmain.js:51:16
|
||||||
|
[90m at ModuleJob.run (node:internal/modules/esm/module_job:430:25)[39m
|
||||||
|
[90m at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:661:26)[39m
|
||||||
|
at async [90mfile:///home/runner/work/create-github-app-token/create-github-app-token/[39mtests/main-missing-client-and-app-id.test.js:12:30
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`main-missing-client-and-app-id.test.js > stdout 1`] = `
|
||||||
|
::error::Either 'client-id' or 'app-id' input must be set
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`main-missing-owner.test.js > stderr 1`] = `
|
exports[`main-missing-owner.test.js > stderr 1`] = `
|
||||||
GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
|
GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { DEFAULT_ENV, test } from "./main.js";
|
||||||
|
|
||||||
|
// Verify `main` accepts a GitHub App client ID via the `client-id` input
|
||||||
|
await test(
|
||||||
|
() => {},
|
||||||
|
{
|
||||||
|
...DEFAULT_ENV,
|
||||||
|
"INPUT_CLIENT-ID": "Iv1.0123456789abcdef",
|
||||||
|
"INPUT_APP-ID": "",
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { DEFAULT_ENV } from "./main.js";
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries({
|
||||||
|
...DEFAULT_ENV,
|
||||||
|
"INPUT_CLIENT-ID": "",
|
||||||
|
"INPUT_APP-ID": "",
|
||||||
|
})) {
|
||||||
|
process.env[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify `main` exits with an error when neither `client-id` nor `app-id` is set.
|
||||||
|
const { default: promise } = await import("../main.js");
|
||||||
|
await promise;
|
||||||
|
process.exitCode = 0;
|
||||||
Reference in New Issue
Block a user