Skip to content

Commit 4673a75

Browse files
Upgrade golangci-lint in CI runner and Makefile (#4861)
* upgrade golangci-lint * upgrade golangci-lint to v2 via go tool and align local/CI lint configuration * pinned version script for local/CI parity * resolve golangci-lint binary via GOPATH to avoid PATH shadowing * use golangci-lint-action@v7 in CI with prebuilt binary to avoid Go 1.25 toolchain fetch while restricting make lint command to same version as CI * incorporate feedback - extract exact semantic version - check system path first before GOPATH/bin to avoid potential duplication * Add cross-reference comments for lint version/args sync Made-with: Cursor --------- Co-authored-by: Bryan Beverly <bryan.beverly@trufflesec.com>
1 parent 47e7b7c commit 4673a75

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

.github/workflows/lint.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,11 @@ jobs:
2020
with:
2121
go-version: "1.24"
2222
- name: golangci-lint
23-
uses: golangci/golangci-lint-action@v6
23+
uses: golangci/golangci-lint-action@v7
2424
with:
25-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
26-
version: latest
27-
# Optional: working directory, useful for monorepos
28-
# working-directory: somedir
29-
30-
# Optional: golangci-lint command line arguments.
31-
args: --enable bodyclose --enable copyloopvar --enable misspell --timeout 10m
32-
33-
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
34-
# skip-pkg-cache: true
35-
36-
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
37-
# skip-build-cache: true
25+
# NOTE: Version and args must match scripts/lint.sh
26+
version: v2.11.4
27+
args: --disable errcheck,staticcheck --enable bodyclose,copyloopvar,misspell --timeout 10m
3828
semgrep:
3929
name: semgrep
4030
runs-on: ubuntu-latest

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ check:
2222
go vet $(shell go list ./... | grep -v /vendor/)
2323

2424
lint:
25-
golangci-lint run --enable bodyclose --enable copyloopvar --enable misspell --out-format=colored-line-number --timeout 10m
25+
./scripts/lint.sh
2626

2727
test-failing:
2828
CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/) | grep FAIL

scripts/lint.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# NOTE: Version and args must match .github/workflows/lint.yml
5+
GOLANGCI_LINT_VERSION="v2.11.4"
6+
7+
# TODO: Re-enable errcheck and staticcheck once pre-existing issues are resolved.
8+
LINT_ARGS="--disable errcheck,staticcheck --enable bodyclose,copyloopvar,misspell --timeout 10m"
9+
10+
GOBIN="$(go env GOPATH)/bin"
11+
GOLANGCI_LINT="${GOBIN}/golangci-lint"
12+
13+
# Extract and compare the exact version to avoid substring matches (e.g. 2.11.4 matching 2.11.40).
14+
check_version() {
15+
local bin="$1"
16+
local installed
17+
installed=$("${bin}" version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
18+
[[ "${installed}" == "${GOLANGCI_LINT_VERSION#v}" ]]
19+
}
20+
21+
# Check PATH first, then fall back to GOPATH/bin, otherwise install.
22+
if command -v golangci-lint &>/dev/null && check_version "$(command -v golangci-lint)"; then
23+
GOLANGCI_LINT="$(command -v golangci-lint)"
24+
echo "golangci-lint ${GOLANGCI_LINT_VERSION} found at ${GOLANGCI_LINT}"
25+
elif [[ -x "${GOLANGCI_LINT}" ]] && check_version "${GOLANGCI_LINT}"; then
26+
echo "golangci-lint ${GOLANGCI_LINT_VERSION} found at ${GOLANGCI_LINT}"
27+
else
28+
echo "Installing golangci-lint ${GOLANGCI_LINT_VERSION}..."
29+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b "${GOBIN}" "${GOLANGCI_LINT_VERSION}"
30+
fi
31+
32+
# shellcheck disable=SC2086
33+
"${GOLANGCI_LINT}" run ${LINT_ARGS}

0 commit comments

Comments
 (0)