1
1

Github ActionsでもPrivate Repoをgo getしたい

Last updated at Posted at 2024-02-27

目的

CIを回している時に、プライベートリポジトリのgo getに失敗したので、それを解決します。
普段ローカルでプライベートリポジトリをインポートする際、GOPRIVATE環境変数を利用しているかと思いますが、同様のことをCI環境(Github Actions)で行うといった内容です。

準備

Githubの自動トークン認証を使います。
Personal Access Token(PAT)はセキュリティ的な観点から利用しません。
自動トークン認証は${{ secrets.GITHUB_TOKEN }}で一時的なトークンを発行できます。権限はPATより弱いですが、go getするには十分です。

解決方法

このように指定すると解決されます。

run: |
    git config --global url."https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
    GOPRIVATE="github.com/<org>"
    
    // go get ~~

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1