From 2d67a35ba5fc0ee1096eaba7188dd8ae37e9f970 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Thu, 17 Mar 2022 12:33:55 +0000 Subject: [PATCH] Use golangci-lint GitHub action. - Rather than manually downloading and invoking golangci-lint, use the GitHub action provided by the developers. - Configure golangci with a config file rather than passing command line args. This enables the same config to be used locally and on CI without introducing duplication. It also allows much more flexibililty in configuration than using CLI args alone. --- .github/workflows/go.yml | 10 ++++++---- .golangci.yml | 20 ++++++++++++++++++++ run_tests.sh | 25 +------------------------ 3 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e758ce6..7df88d2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,10 +14,12 @@ jobs: go-version: ${{ matrix.go }} - name: Check out source uses: actions/checkout@v2 - - name: Install Linters - run: "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0" - name: Build run: go build ./... - name: Test - run: | - ./run_tests.sh + run: env GORACE="halt_on_error=1" go test -race ./... + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44 + diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c9a90a4 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,20 @@ +run: + deadline: 10m + +linters: + disable-all: true + enable: + - asciicheck + - deadcode + - errcheck + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - misspell + - revive + - structcheck + - unconvert + - unparam + - unused diff --git a/run_tests.sh b/run_tests.sh index 0f3ef66..c239180 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,28 +14,5 @@ go version # run tests env GORACE="halt_on_error=1" go test -race ./... -# set output format for linter -if [[ -v CI ]]; then - OUT_FORMAT="github-actions" -else - OUT_FORMAT="colored-line-number" -fi - # run linter -golangci-lint run --disable-all --deadline=10m \ - --out-format=$OUT_FORMAT \ - --enable=gofmt \ - --enable=revive \ - --enable=govet \ - --enable=gosimple \ - --enable=unconvert \ - --enable=ineffassign \ - --enable=structcheck \ - --enable=goimports \ - --enable=misspell \ - --enable=unparam \ - --enable=deadcode \ - --enable=unused \ - --enable=errcheck \ - --enable=asciicheck - \ No newline at end of file +golangci-lint run