From 5153356901ba0c87f99b77c1aec249221a27d351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiri=20Dan=C4=9Bk?= Date: Fri, 14 Jun 2024 10:23:59 +0200 Subject: [PATCH] Add golang-ci and other linters --- .github/workflows/code-quality.yaml | 69 +++++++++++++++++++ .../notebook-controller/.golang-ci.yaml | 45 ++++++++++++ .../odh-notebook-controller/.golang-ci.yaml | 45 ++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 .github/workflows/code-quality.yaml create mode 100644 components/notebook-controller/.golang-ci.yaml create mode 100644 components/odh-notebook-controller/.golang-ci.yaml diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml new file mode 100644 index 00000000000..9aa7980df15 --- /dev/null +++ b/.github/workflows/code-quality.yaml @@ -0,0 +1,69 @@ +--- +name: Code static analysis +"on": + push: + pull_request: + workflow_dispatch: + +permissions: + contents: read + pull-requests: read + +jobs: + golangci: + name: golangci-lint + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + component: + - components/notebook-controller + - components/odh-notebook-controller + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: stable + cache-dependency-path: ${{ matrix.component }}/go.sum + + - name: golangci-lint (components/notebook-controller) + if: "${{ !cancelled() }}" + uses: golangci/golangci-lint-action@v6 + with: + version: v1.58 + working-directory: ${{ matrix.component }} + + # additional checks not part of golangci-lint + + # https://github.com/golangci/golangci-lint/issues/4123 + - name: go mod verify + if: "${{ !cancelled() }}" + run: go mod verify + working-directory: ${{ matrix.component }} + + # https://github.com/golang/go/issues/27005 + - name: go mod tidy -diff + if: "${{ !cancelled() }}" + run: | + set -x + + go mod tidy + + # if the above changed any files, report the differences and fail the step + if [[ $(git ls-files . -d -m -o --exclude-standard --full-name -v | wc -l) -gt 0 ]]; then + echo "There are changes:" + git diff + exit 1 + fi + working-directory: ${{ matrix.component }} + + # https://github.com/golangci/golangci-lint/issues/3094 + - name: govulncheck + if: "${{ !cancelled() }}" + run: | + # https://go.googlesource.com/vuln + go install golang.org/x/vuln/cmd/govulncheck@latest + govulncheck ./... + working-directory: ${{ matrix.component }} diff --git a/components/notebook-controller/.golang-ci.yaml b/components/notebook-controller/.golang-ci.yaml new file mode 100644 index 00000000000..13191570fa2 --- /dev/null +++ b/components/notebook-controller/.golang-ci.yaml @@ -0,0 +1,45 @@ +# https://github.com/golangci/golangci-lint + +# Newer Kubebuilder adds this as a default +# https://github.com/kubernetes-sigs/kubebuilder/issues/1887 + +run: + timeout: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/components/odh-notebook-controller/.golang-ci.yaml b/components/odh-notebook-controller/.golang-ci.yaml new file mode 100644 index 00000000000..13191570fa2 --- /dev/null +++ b/components/odh-notebook-controller/.golang-ci.yaml @@ -0,0 +1,45 @@ +# https://github.com/golangci/golangci-lint + +# Newer Kubebuilder adds this as a default +# https://github.com/kubernetes-sigs/kubebuilder/issues/1887 + +run: + timeout: 5m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll +linters: + disable-all: true + enable: + - dupl + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused