fix(ci): run lint tools via 'go run' to match the toolchain

Installed staticcheck/govulncheck binaries can fail when built with an
older Go than the module targets, and GOPATH/bin is not always on PATH.
Compile them on demand with 'go run <tool>@latest' in both the workflow
and the Makefile.
This commit is contained in:
2026-09-03 21:25:27 +02:00
parent 96281c9f03
commit 4d4bc09b86
2 changed files with 11 additions and 19 deletions
+3 -8
View File
@@ -25,8 +25,7 @@ jobs:
- name: gofumpt (golangci-lint fmt) - name: gofumpt (golangci-lint fmt)
run: | run: |
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest diff=$(go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest fmt --diff 2>&1)
diff=$(golangci-lint fmt --diff 2>&1)
if [ -n "$diff" ]; then if [ -n "$diff" ]; then
echo "$diff" echo "$diff"
echo "Formatting issues found. Run: make fmt" echo "Formatting issues found. Run: make fmt"
@@ -34,14 +33,10 @@ jobs:
fi fi
- name: staticcheck - name: staticcheck
run: | run: go run honnef.co/go/tools/cmd/staticcheck@latest ./...
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
- name: govulncheck - name: govulncheck
run: | run: go run golang.org/x/vuln/cmd/govulncheck@latest ./...
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Test - name: Test
run: go test ./... run: go test ./...
+8 -11
View File
@@ -14,9 +14,10 @@ GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod GOMOD=$(GOCMD) mod
GOCLEAN=$(GOCMD) clean GOCLEAN=$(GOCMD) clean
# Resolve Go tool binaries (GOPATH/bin may not be on PATH in CI) # Tool versions (compiled on demand via `go run` so they match the local toolchain)
GOBIN_DIR := $(shell $(GOCMD) env GOPATH)/bin GOLANGCI_LINT = go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
TOOL = $(if $(shell command -v $(1) 2>/dev/null),$(1),$(GOBIN_DIR)/$(1)) STATICCHECK = go run honnef.co/go/tools/cmd/staticcheck@latest
GOVULNCHECK = go run golang.org/x/vuln/cmd/govulncheck@latest
# Version information # Version information
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
@@ -53,24 +54,20 @@ vet: ## Run go vet
fmt: ## Format code (gofumpt + goimports via golangci-lint) fmt: ## Format code (gofumpt + goimports via golangci-lint)
@echo "Formatting..." @echo "Formatting..."
@command -v golangci-lint > /dev/null || test -x $(GOBIN_DIR)/golangci-lint || $(GOCMD) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest $(GOLANGCI_LINT) fmt --config=.golangci.json
$(call TOOL,golangci-lint) fmt --config=.golangci.json
fmt-check: ## Check formatting (gofumpt + goimports via golangci-lint) fmt-check: ## Check formatting (gofumpt + goimports via golangci-lint)
@echo "Checking formatting..." @echo "Checking formatting..."
@command -v golangci-lint > /dev/null || test -x $(GOBIN_DIR)/golangci-lint || $(GOCMD) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest @diff=$$($(GOLANGCI_LINT) fmt --diff --config=.golangci.json 2>&1); \
@diff=$$($(call TOOL,golangci-lint) fmt --diff --config=.golangci.json 2>&1); \
if [ -n "$$diff" ]; then echo "$$diff"; echo "Run: make fmt"; exit 1; fi if [ -n "$$diff" ]; then echo "$$diff"; echo "Run: make fmt"; exit 1; fi
staticcheck: ## Run staticcheck staticcheck: ## Run staticcheck
@echo "Running staticcheck..." @echo "Running staticcheck..."
@command -v staticcheck > /dev/null || test -x $(GOBIN_DIR)/staticcheck || $(GOCMD) install honnef.co/go/tools/cmd/staticcheck@latest $(STATICCHECK) ./...
$(call TOOL,staticcheck) ./...
govulncheck: ## Run govulncheck govulncheck: ## Run govulncheck
@echo "Running govulncheck..." @echo "Running govulncheck..."
@command -v govulncheck > /dev/null || test -x $(GOBIN_DIR)/govulncheck || $(GOCMD) install golang.org/x/vuln/cmd/govulncheck@latest $(GOVULNCHECK) ./...
$(call TOOL,govulncheck) ./...
build: deps ## Build the binary build: deps ## Build the binary
@echo "Building $(BINARY_NAME) $(VERSION)..." @echo "Building $(BINARY_NAME) $(VERSION)..."