LoginSignup
4
1

More than 1 year has passed since last update.

actions/setup-go@v3にキャッシュ機能が実装されたのでGithub Actionsの設定を書き替える

Posted at

目次

はじめに

初めまして、Rasといいます。普段はデジタル創作同好会traPというところで活動しています。

Github ActionsでGoを使うときはactions/setup-goを使うのが一般的だと思います。

先日v3.2.0がリリースされ、キャッシュ機能が実装されました。Github Actionsのワークフローの記述がより簡潔になります。

CIの実行時間が1分以上短縮できた話や移行でハマってしまった話をしています。良ければこちらもどうぞ (今日投稿されたばかりのピチピチ記事です:fish::sparkles:)。

これまで

(ワークフローの発火条件等は省略しています)

build:
    name: Build
    runs-on: ubuntu-latest
    env:
      GOCACHE: /tmp/go/cache
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v3
        with:
          go-version: 1.19
      - uses: actions/cache@v3
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-gomod-
      - uses: actions/cache@v3
        with:
          path: /tmp/go/cache
          key: ${{ runner.os }}-go-build-${{ github.ref }}-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-go-build-${{ github.ref }}-
            ${{ runner.os }}-go-build-
      - run: go mod download
      - run: go build -o myApp .

これから

build:
  name: Build
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-go@v3
      with:
        go-version-file: ./go.mod # v3.1.0で実装された。go.modからバージョンを取得できる
        cache: true               # デフォルトはfalse
    - run: go mod download
    - run: go build -o myApp .

おわりに

是非使ってみてください。

ちなみにGo強化月間が開催されているみたいですね。

もう1回貼るんですが本題はこっちなのでこちらも是非ご覧ください!

4
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
4
1