LoginSignup
6

More than 3 years have passed since last update.

posted at

updated at

Github actionsでgo mod download, test, lint

Github Actions

https://github.co.jp/features/actions
GithubのCI/CDサービス

モチベーション

現職ではほとんどcircleciで回しているが、Github actionsが便利ということを聞いたので試した。
go.modのキャッシュの問題などあり、実際にやってみて記事としてこれ持って来ればOKみたいのが見当たらず、
githubでpublic repoを徘徊したので、最低限自分にあったやり方をまとめておきたい

workflow

stepなどはほぼ他のciサービスと同じだと思うので割愛
実際のyamlは以下

github/workflows/ci.yaml
// 好きな名前
name: golang_ci
// フック
on: [push]

jobs:
  build:
    name: all
    runs-on: ubuntu-latest
    steps:
      # GOPATHなどのセットアップ
      - name: set up
        uses: actions/setup-go@v1
        with:
          go-version: 1.13
        id: go
      # repositoryの中身にアクセスするためのチェックアウト
      - name: checkout
        uses: actions/checkout@v1
      # cache store
      - name: cache
        uses: actions/cache@v1
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-
        # golang-ci
      - name: install lint
        run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
      - name: lint
        run: golangci-lint run
      - name: test
        run: go test ./... -v

基本的にactionを指定して環境を構築 -> 実行という流れ

参照できるactionは以下で
- public repository
- workflowと同一repository
- Dockerhubで公開されているDockerコンテナイメージ

感想

circleciと比べてみての感想になってしまうが以下のようなメリデメを感じた

メリット

デメリット

  • 参考にできる実例が少ない これは仕方ない。実際に公開repositoryでgo.modのキャッシュ関連をAll Githubで調べても100件はなさそうだった
  • sshがちょっとめんどくさそう workflowに変更を入れないとsshできない様子

手軽にsshしたいなと感じたくらいで、あとはCI構築のためには最適なGithub上でのtry and error、確認が手軽にできるのが嬉しい
今後個人repoなら使っていくかもしれない

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
What you can do with signing up
6