◾️はじめに
GitHub Actionsで別レポジトリをcloneする方法を考える
Github Actions ~ クロスレポジトリアクセス ~
https://dk521123.hatenablog.com/entry/2025/02/12/150704
目次
【1】GitHub Actionsで別レポジトリをcloneするには 1)actions/checkoutを使った場合 2)git cloneコマンドを使っている場合 【2】Tokenをどう発行するかを考える 1)自分で発行してsecretsに保持する 2)actions/create-github-app-tokenを利用する
【1】GitHub Actionsで別レポジトリをcloneするには
1)actions/checkoutを使った場合
* 以下に載っている
Checkout multiple repos (private)
https://github.com/actions/checkout?tab=readme-ov-file#checkout-multiple-repos-private
- name: Checkout uses: actions/checkout@v4 with: path: main - name: Checkout private tools uses: actions/checkout@v4 with: repository: my-org/my-private-tools token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT path: my-tools
2)git cloneコマンドを使っている場合
* 以下に載っていた
https://qiita.com/broken55/items/fd2f65474243560b71eb
name: CloneTest on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Clone another repository env: ANOTHER_ACTOR: ${{ secrets.GH_USAR }} ANOTHER_TOKEN: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT run: | git clone https://${ANOTHER_ACTOR}:${ANOTHER_TOKEN}@github.com/your-account/your-another-repo.git
【2】Tokenをどう発行するかを考える
【1】でどのような方法でもTokenが必要になるが どのように発行して管理するかを考えてみた 以下も参照。
Github Actions ~ クロスレポジトリアクセス ~
https://dk521123.hatenablog.com/entry/2025/02/12/150704
1)自分で発行してsecretsに保持する
* とりあえず、疎通テストとしてはいいが、個人で発行するTokenは、 その個人がプロジェクトから離脱した時のことを考えると 本番運用には適していない
2)actions/create-github-app-tokenを利用する
「1)自分で発行してsecretsに保持する」が嫌だったので 調べてみたら、actions/create-github-app-tokeってのがあった
https://github.com/actions/create-github-app-token
設定など含めて、以下の関連記事を参照。
Github Actions ~ クロスレポジトリアクセス ~
https://dk521123.hatenablog.com/entry/2025/02/12/150704
[サンプル] Create a token for all repositories in another owner's installation
https://github.com/actions/create-github-app-token?tab=readme-ov-file#create-a-token-for-all-repositories-in-another-owners-installation
on: [issues] jobs: hello-world: runs-on: ubuntu-latest steps: - uses: actions/create-github-app-token@v1 id: app-token with: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.PRIVATE_KEY }} owner: another-owner - uses: peter-evans/create-or-update-comment@v3 with: token: ${{ steps.app-token.outputs.token }} # ★出力結果★ issue-number: ${{ github.event.issue.number }} body: "Hello, World!"
入力値
* app-id : (必須)GitHub App ID => App ID: XXXXXXX(X:数字) ... GitHub App の [General] ページで確認できる
https://github.com/actions/create-github-app-token?tab=readme-ov-file#app-id
* private-key:(必須)GitHub App プライベートキー => GitHub App の [General] ページの下の方に「Private keys」欄があるのでそこから作成可能
* owner:(任意)GitHub App のオーナー。入力しなかったら、現在のリポジトリのオーナー => Owned by: @XXXX(X:英数字) ... GitHub App の [General] ページで確認できる
https://github.com/actions/create-github-app-token?tab=readme-ov-file#owner
関連記事
Github ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/07/18/234652
Github Actions ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2021/11/04/142835
Github Actions ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2022/06/16/151443
Github Actions ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2023/12/22/195715
Github Actions ~ GITHUB_TOKEN / permissions ~
https://dk521123.hatenablog.com/entry/2024/04/22/221027
Github Actions ~ クロスレポジトリアクセス ~
https://dk521123.hatenablog.com/entry/2025/02/12/150704
Github Actions ~ Self-hosted runners / 入門編 ~
https://dk521123.hatenablog.com/entry/2023/12/18/204119
Github Actions ~ Self-hosted runners / あれこれ編 ~
https://dk521123.hatenablog.com/entry/2024/02/07/002736
Github Actions ~ セキュリティ/Third-Party Github Action ~
https://dk521123.hatenablog.com/entry/2024/04/05/000136
Github Actions ~ セキュリティ/インジェクション攻撃 ~
https://dk521123.hatenablog.com/entry/2024/04/16/222419
Github Actions ~ deprecationによるエラー防止を考える ~
https://dk521123.hatenablog.com/entry/2025/02/01/214020
Self-hosted runner下の Github actions が突然エラー
https://dk521123.hatenablog.com/entry/2024/07/05/000212
GitHub Apps ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/07/06/230610