golangci-lint を GitHub Actions で使う
golangci-lint は go vet
をはじめ複数の lint を集約して結果を表示してくれる優れものである。
かつては GolangCI.com で GitHub と連携できていたのだが,2020年4月でサービスが停止してしまい,寂しい限り。
と思っていたのだが,いつの間にか公式の GitHub Actions が用意されていた。 気付かなんだよ。 不覚。
使い方は簡単。
リポジトリの .github/workflows/
ディレクトリに YAML ファイル(例えば lint.yml
)を置き,以下のように記述する。
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
golangci:
strategy:
matrix:
go-version: [1.15.x]
os: [ubuntu-latest, macos-latest, windows-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
また,リポジトリ直下の .gitattributes
ファイルに以下の記述を追加する。
*.go text eol=lf
これで pull request 時, master
ブランチ1 への push 時,およびバージョンタグを打った際に golangci-lint が走る。
golangci-lint は matrix
の組み合わせで並列処理されるようだ。

よーし,うむうむ,よーし。
まぁ,プラットフォーム依存のコードでもない限り Go 最新バージョンの ubuntu-latest
だけでいいと思うけどね。
ブックマーク
参考図書
- プログラミング言語Go
- アラン・ドノバン (著), ブライアン・カーニハン (著), 柴田芳樹 (著)
- 丸善出版 2016-06-20 (Release 2021-07-13)
- Kindle版
- B099928SJD (ASIN)
- 評価
Kindle 版出た! 一部内容が古びてしまったが,この本は Go 言語の教科書と言ってもいいだろう。感想はこちら。
-
2020年10月から GitHub の新規リポジトリの既定ブランチ名が
main
になるらしい。ご注意を。 ↩︎