diff --git a/.evergreen/config.yml b/.evergreen/config.yml index bf164f1a94..3528e9e561 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -2348,6 +2348,7 @@ buildvariants: run_on: - rhel8.7-small expansions: + # Keep this in sync with go version used in etc/golangci-lint.sh GO_DIST: "/opt/golang/go1.22" tasks: - name: ".static-analysis" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4e5498fbf..a72ffa4ad9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,4 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + - uses: actions/setup-go@v5 + with: + go-version: 'stable' - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0449e06e50..1c82f8a5aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,11 +50,6 @@ repos: - id: markdown-link-check exclude: ^(vendor) -- repo: https://github.com/golangci/golangci-lint - rev: v1.60.1 - hooks: - - id: golangci-lint - - repo: local hooks: - id: executable-shell @@ -62,3 +57,11 @@ repos: entry: chmod +x language: system types: [shell] + + - id: golangci-lint + name: golangci-lint + language: system + types: [go] + require_serial: true + pass_filenames: false + entry: etc/golangci-lint.sh diff --git a/Taskfile.yml b/Taskfile.yml index a08d20f4ca..a87226cb5e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -57,14 +57,13 @@ tasks: # alignment of atomically accessed variables on 32-bit architectures (see # https://staticcheck.io/docs/checks#SA1027) lint: - deps: [install-golangci-lint] cmds: - - GOOS=linux GOARCH=386 golangci-lint run --config .golangci.yml ./... - - GOOS=linux GOARCH=arm golangci-lint run --config .golangci.yml ./... - - GOOS=linux GOARCH=arm64 golangci-lint run --config .golangci.yml ./... - - GOOS=linux GOARCH=amd64 golangci-lint run --config .golangci.yml ./... - - GOOS=linux GOARCH=ppc64le golangci-lint run --config .golangci.yml ./... - - GOOS=linux GOARCH=s390x golangci-lint run --config .golangci.yml ./... + - GOOS=linux GOARCH=386 etc/golangci-lint.sh + - GOOS=linux GOARCH=arm etc/golangci-lint.sh + - GOOS=linux GOARCH=arm64 etc/golangci-lint.sh + - GOOS=linux GOARCH=amd64 etc/golangci-lint.sh + - GOOS=linux GOARCH=ppc64le etc/golangci-lint.sh + - GOOS=linux GOARCH=s390x etc/golangci-lint.sh update-notices: bash etc/generate_notices.pl > THIRD-PARTY-NOTICES @@ -188,10 +187,3 @@ tasks: internal: true cmds: - go install github.com/walle/lll/...@latest - - # NOTE: A golangci-lint version is also pinned in .pre-commit-config.yaml. Make - # sure to change it there to keep it in-sync with what's used here! - install-golangci-lint: - internal: true - cmds: - - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 diff --git a/etc/golangci-lint.sh b/etc/golangci-lint.sh new file mode 100755 index 0000000000..f7e6f5c20d --- /dev/null +++ b/etc/golangci-lint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -ex + +# Unset the cross-compiler overrides while downloading binaries. +GOOS_ORIG=${GOOS:-} +export GOOS= +GOARCH_ORIG=${GOARCH:-} +export GOARCH= + +# Keep this in sync with go version used in static-analysis Evergreen build variant. +go install golang.org/dl/go1.22.7@latest +go1.22.7 download +export PATH="$(go1.22.7 env GOROOT)/bin:$PATH" +go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 + +export GOOS=$GOOS_ORIG +export GOARCH=$GOARCH_ORIG +golangci-lint run --config .golangci.yml ./...