Skip to content

Commit 20fd863

Browse files
timreimherrgr2mparkerbxyz
authored
feat: support tokens scoped to multiple repositories within organization (actions#46)
Co-authored-by: Gregor Martynus <[email protected]> Co-authored-by: Parker Brown <[email protected]>
1 parent 5804f04 commit 20fd863

File tree

7 files changed

+927
-5729
lines changed

7 files changed

+927
-5729
lines changed

README.md

+80-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In order to use this action, you need to:
1010
2. [Store the App's ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_ID`)
1111
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`)
1212

13-
### Minimal usage
13+
### Create a token for the current repository
1414

1515
```yaml
1616
on: [issues]
@@ -57,6 +57,73 @@ jobs:
5757
github_token: ${{ steps.app-token.outputs.token }}
5858
```
5959

60+
### Create a token for all repositories in the current owner's installation
61+
62+
```yaml
63+
on: [workflow_dispatch]
64+
65+
jobs:
66+
hello-world:
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/create-github-app-token@v1
70+
id: app-token
71+
with:
72+
app_id: ${{ vars.APP_ID }}
73+
private_key: ${{ secrets.PRIVATE_KEY }}
74+
owner: ${{ github.repository_owner }}
75+
- uses: peter-evans/create-or-update-comment@v3
76+
with:
77+
token: ${{ steps.app-token.outputs.token }}
78+
issue-number: ${{ github.event.issue.number }}
79+
body: "Hello, World!"
80+
```
81+
82+
### Create a token for multiple repositories in the current owner's installation
83+
84+
```yaml
85+
on: [issues]
86+
87+
jobs:
88+
hello-world:
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/create-github-app-token@v1
92+
id: app-token
93+
with:
94+
app_id: ${{ vars.APP_ID }}
95+
private_key: ${{ secrets.PRIVATE_KEY }}
96+
owner: ${{ github.repository_owner }}
97+
repositories: "repo1,repo2"
98+
- uses: peter-evans/create-or-update-comment@v3
99+
with:
100+
token: ${{ steps.app-token.outputs.token }}
101+
issue-number: ${{ github.event.issue.number }}
102+
body: "Hello, World!"
103+
```
104+
105+
### Create a token for all repositories in another owner's installation
106+
107+
```yaml
108+
on: [issues]
109+
110+
jobs:
111+
hello-world:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/create-github-app-token@v1
115+
id: app-token
116+
with:
117+
app_id: ${{ vars.APP_ID }}
118+
private_key: ${{ secrets.PRIVATE_KEY }}
119+
owner: another-owner
120+
- uses: peter-evans/create-or-update-comment@v3
121+
with:
122+
token: ${{ steps.app-token.outputs.token }}
123+
issue-number: ${{ github.event.issue.number }}
124+
body: "Hello, World!"
125+
```
126+
60127
## Inputs
61128

62129
### `app_id`
@@ -67,6 +134,17 @@ jobs:
67134

68135
**Required:** GitHub App private key.
69136

137+
### `owner`
138+
139+
**Optional:** GitHub App installation owner. If empty, defaults to the current repository owner.
140+
141+
### `repositories`
142+
143+
**Optional:** Comma-separated list of repositories to grant access to.
144+
145+
> [!NOTE]
146+
> 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.
147+
70148
## Outputs
71149

72150
### `token`
@@ -77,7 +155,7 @@ GitHub App installation access token.
77155

78156
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,
79157

80-
1. The token is scoped to the current repository.
158+
1. The token is scoped to the current repository or `repositories` if set.
81159
2. The token inherits all the installation's permissions.
82160
3. The token is set as output `token` which can be used in subsequent steps.
83161
4. The token is revoked in the `post` step of the action, which means it cannot be passed to another job.

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ inputs:
1111
private_key:
1212
description: "GitHub App private key"
1313
required: true
14+
owner:
15+
description: "GitHub App owner (defaults to current repository owner)"
16+
required: false
17+
repositories:
18+
description: "Repositories to install the GitHub App on (defaults to current repository if owner is unset)"
19+
required: false
1420
outputs:
1521
token:
1622
description: "GitHub installation access token"

0 commit comments

Comments
 (0)