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
+8 -11
View File
@@ -14,9 +14,10 @@ GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOCLEAN=$(GOCMD) clean
# Resolve Go tool binaries (GOPATH/bin may not be on PATH in CI)
GOBIN_DIR := $(shell $(GOCMD) env GOPATH)/bin
TOOL = $(if $(shell command -v $(1) 2>/dev/null),$(1),$(GOBIN_DIR)/$(1))
# Tool versions (compiled on demand via `go run` so they match the local toolchain)
GOLANGCI_LINT = go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
STATICCHECK = go run honnef.co/go/tools/cmd/staticcheck@latest
GOVULNCHECK = go run golang.org/x/vuln/cmd/govulncheck@latest
# Version information
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)
@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
$(call TOOL,golangci-lint) fmt --config=.golangci.json
$(GOLANGCI_LINT) fmt --config=.golangci.json
fmt-check: ## Check formatting (gofumpt + goimports via golangci-lint)
@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=$$($(call TOOL,golangci-lint) fmt --diff --config=.golangci.json 2>&1); \
@diff=$$($(GOLANGCI_LINT) fmt --diff --config=.golangci.json 2>&1); \
if [ -n "$$diff" ]; then echo "$$diff"; echo "Run: make fmt"; exit 1; fi
staticcheck: ## Run staticcheck
@echo "Running staticcheck..."
@command -v staticcheck > /dev/null || test -x $(GOBIN_DIR)/staticcheck || $(GOCMD) install honnef.co/go/tools/cmd/staticcheck@latest
$(call TOOL,staticcheck) ./...
$(STATICCHECK) ./...
govulncheck: ## Run govulncheck
@echo "Running govulncheck..."
@command -v govulncheck > /dev/null || test -x $(GOBIN_DIR)/govulncheck || $(GOCMD) install golang.org/x/vuln/cmd/govulncheck@latest
$(call TOOL,govulncheck) ./...
$(GOVULNCHECK) ./...
build: deps ## Build the binary
@echo "Building $(BINARY_NAME) $(VERSION)..."