You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for enterprise-level GitHub Apps (#263)
This pull request adds support for generating GitHub App installation
tokens for enterprise-level installations.
### What changed
- Added a new `enterprise` input to `action.yml`.
- Wired `enterprise` through `main.js` and `lib/main.js`.
- Added validation so `enterprise` cannot be combined with `owner` or
`repositories`.
- Implemented enterprise installation lookup using the direct GitHub API
route `GET /enterprises/{enterprise}/installation`, then used the
returned installation ID to mint an installation token through
`@octokit/auth-app`.
- Updated `README.md` with enterprise installation usage and input
documentation.
- Updated `dist/main.cjs` for the bundled action.
- Shared token creation retry behavior across repository, owner, and
enterprise paths so server errors and transient network errors are
retried, while client errors fail immediately.
### Tests
Added focused test coverage for:
- enterprise token creation
- enterprise token creation with explicit permissions
- enterprise installation not found
- mutual exclusivity with `owner`
- mutual exclusivity with `repositories`
- owner installation client errors are not retried
- transient network errors are retried during token creation
### Notes
- This keeps the existing repository-scoped token behavior unchanged.
- Owner, repository, and enterprise token creation now share the same
retry policy: server errors and recognized transient network errors are
retried, while client errors fail immediately. This intentionally fixes
the previous owner-path behavior that retried client errors.
Refs:
-
https://github.blog/changelog/2025-07-01-enterprise-level-access-for-github-apps-and-installation-automation-apis/
-
https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-enterprise-installation-for-the-authenticated-app
---------
Co-authored-by: Parker Brown <17183625+parkerbxyz@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+37-7Lines changed: 37 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -195,10 +195,32 @@ jobs:
195
195
body: "Hello, World!"
196
196
```
197
197
198
+
### Create a token for an enterprise installation
199
+
200
+
```yaml
201
+
on: [workflow_dispatch]
202
+
203
+
jobs:
204
+
hello-world:
205
+
runs-on: ubuntu-latest
206
+
steps:
207
+
- uses: actions/create-github-app-token@v3
208
+
id: app-token
209
+
with:
210
+
client-id: ${{ vars.APP_CLIENT_ID }}
211
+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
212
+
enterprise: my-enterprise-slug
213
+
- name: Call enterprise management REST API with gh
214
+
run: |
215
+
gh api /enterprises/my-enterprise-slug/apps/installable_organizations
216
+
env:
217
+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
218
+
```
219
+
198
220
### Create a token with specific permissions
199
221
200
222
> [!NOTE]
201
-
> Selected permissions must be granted to the installation of the specified app and repository owner. Setting a permission that the installation does not have will result in an error.
223
+
> Selected permissions must be granted to the specified app installation. Setting a permission that the installation does not have will result in an error.
202
224
203
225
```yaml
204
226
on: [issues]
@@ -356,6 +378,13 @@ steps:
356
378
> [!NOTE]
357
379
> 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.
358
380
381
+
### `enterprise`
382
+
383
+
**Optional:** The slug of the enterprise account to generate a token for an enterprise installation.
384
+
385
+
> [!NOTE]
386
+
> The `enterprise` input is mutually exclusive with `owner` and `repositories`. Use it when the GitHub App is installed on an enterprise account. Enterprise installation tokens can call enterprise APIs, but do not grant organization or repository access.
387
+
359
388
### `permission-<permission name>`
360
389
361
390
**Optional:** The permissions to grant to the token. By default, the token inherits all of the installation's permissions. We recommend to explicitly list the permissions that are required for a use case. This follows GitHub's own recommendation to [control permissions of `GITHUB_TOKEN` in workflows](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token). The documentation also lists all available permissions, just prefix the permission key with `permission-` (e.g., `pull-requests` → `permission-pull-requests`).
@@ -386,13 +415,14 @@ GitHub App slug.
386
415
387
416
## How it works
388
417
389
-
The action creates an installation access token using [the `POST /app/installations/{installation_id}/access_tokens` endpoint](https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app). By default,
418
+
The action creates an installation access token using [the `POST /app/installations/{installation_id}/access_tokens` endpoint](https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app).
419
+
420
+
The token target depends on the inputs: `enterprise`creates a token for an enterprise installation, `owner` without `repositories` creates a token for all repositories in the owner's installation, `repositories` scopes the token to those repositories, and no target inputs scopes the token to the current repository.
390
421
391
-
1. The token is scoped to the current repository or `repositories` if set.
392
-
2. The token inherits all the installation's permissions.
393
-
3. The token is set as output `token` which can be used in subsequent steps.
394
-
4. Unless the `skip-token-revoke` input is set to true, the token is revoked in the `post` step of the action, which means it cannot be passed to another job.
395
-
5. The token is masked, it cannot be logged accidentally.
422
+
1. The token inherits all the installation's permissions.
423
+
2. The token is set as output `token` which can be used in subsequent steps.
424
+
3. Unless the `skip-token-revoke` input is set to true, the token is revoked in the `post` step of the action, which means it cannot be passed to another job.
425
+
4. The token is masked, it cannot be logged accidentally.
396
426
397
427
> [!NOTE]
398
428
> Installation permissions can differ from the app's permissions they belong to. Installation permissions are set when an app is installed on an account. When the app adds more permissions after the installation, an account administrator will have to approve the new permissions before they are set on the installation.
throw new Error("The 'client-id' (or deprecated 'app-id') input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
23356
23398
}
23357
23399
const privateKey = getInput("private-key");
23400
+
const enterprise = getInput("enterprise");
23358
23401
const owner = getInput("owner");
23359
23402
const repositories = getInput("repositories").split(/[\n,]+/).map((s) => s.trim()).filter((x) => x !== "");
0 commit comments