Token to create orgA/repo from orgB template
Closed this issue ยท 2 comments
I have been trying to enable a Github Workflow that should be able to create a new repo at orgA, using a template repo from orgB, I don't believe there is a chance to support this since the GitHub Apps tokens are scoped to an individual account or a specific org afaik, but it could be pretty useful to have a way to support this using GitHub Apps.
These are the steps, I'm trying to use:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.ZCLOUD_BOT_APP_ID }}
private-key: ${{ secrets.ZCLOUD_BOT_APP_PRIVATE_KEY }}
owner: ${{ github.event.inputs.repo-org }}
- name: Create the new repo
id: create-repo
env:
GITHUB_TOKEN: ${{ steps.generate-token-template.outputs.token }}
run: |
gh repo create ${{ github.event.inputs.repo-org }}/${{ github.event.inputs.repo-name }} \
--internal \
--template ${{ github.repository }}
This is similar to Issue 45, but I can't use the matrix approach since permission to both orgs is required between the same command exec.
Unless the template repository is open source, I don't think this is possible with a GitHub App installation access token, because by design an installation access token only has access to the account that the installation belongs to. There are no cross-account installations
Thanks for the clarification @gr2m ๐๐ผ, my workaround for this was to git checkout the repo using the GitHub Workflow token, clean the git repo history, and then use the GitHub App access token to create the new repo.
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
owner: ${{ github.event.inputs.repo-org }}
- name: Checkout template repo
id: checkout
uses: actions/checkout@v4
- name: Initialize the new repo
id: init-repo
run: |
## clean git
rm -rf .git
## set git config
git config --global init.defaultBranch main
## commit initial files
git init
git config user.name "${{ vars.BOT_APP_NAME }}[bot]"
git config user.email "${{ secrets.BOT_APP_ID }}+${{ vars.BOT_APP_NAME }}[bot]@users.noreply.github.com"
git add .
git commit -m "initial commit [skip ci]"
- name: Create the new repo
id: create-repo
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
gh repo create ${{ github.event.inputs.repo-org }}/${{ github.event.inputs.repo-name }} \
--internal \
--source=. \
--remote=upstream \
--push
##--template ${{ github.repository }}