Skip to content

Commit 58d6a56

Browse files
Improve lint target to check and fix Go version mismatches
- Add version checking logic to detect golangci-lint Go version compatibility - Automatically reinstall golangci-lint with correct Go version if mismatch detected - Use GOTOOLCHAIN to ensure installation with project's required Go version - Prevents future 'Go language version used to build golangci-lint is lower than targeted Go version' errors Co-Authored-By: Alec Fong <alecsanf@usc.edu>
1 parent a83ca1e commit 58d6a56

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ bench:
110110
lint:
111111
@echo "Running linter..."
112112
@if ! command -v $(GOLINT) > /dev/null 2>&1; then \
113-
$(GOINSTALL) $(ARTIFACT_GOLINT); \
113+
echo "golangci-lint not found. Installing..."; \
114+
GOTOOLCHAIN=go$(shell $(GOCMD) list -m -f '{{.GoVersion}}') $(GOINSTALL) $(ARTIFACT_GOLINT); \
115+
else \
116+
REQUIRED_GO_VERSION=$$($(GOCMD) list -m -f '{{.GoVersion}}'); \
117+
LINTER_GO_VERSION=$$($(GOLINT) version 2>/dev/null | grep -o 'go[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | sed 's/go//'); \
118+
if [ -n "$$LINTER_GO_VERSION" ] && [ -n "$$REQUIRED_GO_VERSION" ]; then \
119+
if ! printf '%s\n%s\n' "$$REQUIRED_GO_VERSION" "$$LINTER_GO_VERSION" | sort -V -C 2>/dev/null; then \
120+
echo "golangci-lint was built with Go $$LINTER_GO_VERSION but project requires Go $$REQUIRED_GO_VERSION. Reinstalling..."; \
121+
GOTOOLCHAIN=go$$REQUIRED_GO_VERSION $(GOINSTALL) $(ARTIFACT_GOLINT); \
122+
fi; \
123+
fi; \
114124
fi
115125
$(GOLINT) run ./...
116126

@@ -219,4 +229,4 @@ help:
219229
@echo " docs - Generate documentation"
220230
@echo " check - Run all checks (lint, vet, fmt-check, test)"
221231
@echo " install-tools - Install development tools"
222-
@echo " help - Show this help message"
232+
@echo " help - Show this help message"

0 commit comments

Comments
 (0)