From 4c0c74d27336cd0a23c5e2567f3f97b227c6ed88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Tue, 23 Nov 2021 16:46:58 +0100 Subject: [PATCH] build: add linting action before publishing --- .github/workflows/publish.yaml | 26 +++++++--- .golangci.yaml | 95 ++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 9f7776e..854f35c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,10 +1,23 @@ name: Test and publish -on: - push: - branches: ['main'] +on: [push, pull_request] jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.17 + stable: true + + - name: Install golangci-lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + version: v1.43.0 + skip-go-installation: true + test: runs-on: ubuntu-latest steps: @@ -14,7 +27,8 @@ jobs: go-version: 1.17 stable: true - - run: | + - name: Download K8s envtest - local K8s cluster control plane + run: | go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest mkdir -p local/envtest-bin/ setup-envtest use -p env 1.21.x --bin-dir local/envtest-bin > local/envtest-bin/env @@ -35,7 +49,7 @@ jobs: release-tagged: if: "startsWith(github.ref, 'refs/tags/v')" needs: - # - lint + - lint - test runs-on: ubuntu-latest steps: @@ -60,7 +74,7 @@ jobs: release-untagged: if: "!startsWith(github.ref, 'refs/tags/v')" needs: - # - lint + - lint - test runs-on: ubuntu-latest steps: diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..92297ec --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,95 @@ +--- +run: + tests: false + skip-dirs: + - .github + - build + - web + - .go +linters-settings: + dupl: + threshold: 100 + funlen: + lines: 100 + statements: 50 + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - whyNoLint + - hugeParam + gocyclo: + min-complexity: 15 + revive: + min-confidence: 0.8 + govet: + check-shadowing: true + lll: + line-length: 140 + misspell: + locale: US + nolintlint: + allow-leading-space: false + require-explanation: true + allow-no-explanation: + - gocognit + - funlen + - gocyclo + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - funlen + - nolintlint + - gochecknoglobals + - gochecknoinits + - gocognit + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - revive + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - prealloc + - rowserrcheck + - exportloopref + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + - wsl + +issues: + exclude: + # Very commonly not checked. + - 'Error return value of .(l.Sync|.*Close|.*.Write|.*Flush|os\.Remove(All)?|os\.(Un)?Setenv). is not checked' + - 'G104:.*' + - 'exported method (.*\.MarshalJSON|.*\.UnmarshalJSON) should have comment or be unexported' + - 'shadow: declaration of "err" shadows declaration.*' + max-same-issues: 0 + exclude-use-default: false