-
Notifications
You must be signed in to change notification settings - Fork 88
Create token for multiple organization/user accounts #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I paired with @parkerbxyz on this problem today, and we figured out an approach for this, here is what our action workflow looks like: name: Debug
"on":
workflow_dispatch: {}
jobs:
set-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.set.outputs.matrix }}
steps:
- id: set
run: echo 'matrix=[{"owner":"gr2m"},{"owner":"gr2m-sandbox","repos":["test12"]}]' >>"$GITHUB_OUTPUT"
use-matrix:
name: '@${{ matrix.ownersAndRepos.owner }} installation'
needs: [set-matrix]
runs-on: ubuntu-latest
strategy:
matrix:
ownersAndRepos: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
steps:
- run: echo owner - ${{ matrix.ownersAndRepos.owner }}
- run: echo repos - ${{ join(matrix.ownersAndRepos.repos) }}
- uses: gr2m/create-github-app-token@main
id: app-token
with:
app_id: ${{ vars.GR2M_GITHUB_APP_ID }}
private_key: ${{ secrets.GR2M_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ matrix.ownersAndRepos.owner }}
repositories: ${{ join(matrix.ownersAndRepos.repos) }}
- uses: octokit/request-action@v2.x
id: get-installation-repositories
with:
route: GET /installation/repositories
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- run: echo $DATA
env:
DATA: ${{ steps.get-installation-repositories.outputs.data }} Note that this only works with my fork at gr2m/create-github-app-token right now. But once #46 is merged and released this approach will work, and it doesn't even require a separate github action 🎉 I think once #46 lands we should document that approach in the README as a usage example for future reference |
Adds an example workflow to the README that shows how a matrix strategy can be used to create tokens for multiple user or organization accounts. Resolves #45.
🎉 This issue has been resolved in version 1.5.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This is a follow up to #4 (comment)
@kmaehashi had posted the following request here
Unfortunately, an installation access token can by design only access a single account (GitHub user or organization account). There cannot be a single token that has access across multiple organizations.
But I've run into this requirement before and I see a possible workaround that would require an additional action and the user of matrix.
actions/get-app-installation-ids
, it would takeapp_id
andprivate_key
as arguments, and optionally a list of logins to filter down the installations. The action would haveinstallation_ids
andinstallation_logins
outputs.strategy.matrix
in a second job, so all steps would be run for each of the installation IDsactions/create-github-app-token
could be used to create an installation access token for that particular installationI'm however not sure how we could filter down to specific repositories across multiple organizations. I'd need to experiment myself to see what's possible. Maybe the
actions/get-app-installation-ids
could take an argument like you suggest (sayrepositories: orgA/repoA, orgA/repoB, orgB/repoC
) and then have a nested output like this:[["orgA", "repoA, repoB"],["orgB", "repoC"]]
which we could could iterate through using the matrix and then split out the items like["orgA", "repoA, repoB"]
intoowner: orgA, repositories: repoA, Repo B
The text was updated successfully, but these errors were encountered: