Skip to content

Commit 8ee0b22

Browse files
kolyshkindims
authored andcommitted
Makefile: fix golangci-lint install issues
With commit 300242c, my intention was to use whatever version of golangci-lint is available locally, and if not (which is usually the case in CI), install the version recommended by the Makefile. The code was changed since, and currently has two issues wrt how golangci-lint is installed: 1. golangci-lint prints version without v prefix (e.g. "... version 1.23.45 ..."), while grep looks for v1.23.45. As a result, golangci-lint is *always* reinstalled. 2. If a newer golangci-lint version is installed locally, running "make lint" will downgrade it. This is not what most developers would expect. Let's fix both. A version in the Makefile is now minimally required version, and no attempt to downgrade is made. Fixes: ea3afbc ("Build changes for golang 1.18") Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 2531201 commit 8ee0b22

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
GO := go
16-
GOLANGCI_VER := v1.56.2
16+
GOLANGCI_VER := 1.56.2
1717
GO_TEST ?= $(GO) test $(or $(GO_FLAGS),-race)
1818
arch ?= $(shell go env GOARCH)
1919

@@ -82,9 +82,15 @@ presubmit: lint
8282

8383
lint:
8484
@# This assumes GOPATH/bin is in $PATH -- if not, the target will fail.
85-
@if ! golangci-lint version | grep $(GOLANGCI_VER); then \
86-
echo ">> installing golangci-lint $(GOLANGCI_VER)"; \
87-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_VER); \
85+
@# Extract the current golangci-lint version (empty if not installed),
86+
@# then use GNU sort to check if GOT >= GOLANGCI_VER.
87+
@GOT=$$(golangci-lint version 2>/dev/null | sed 's/^.* version \([^ ]*\) .*$$/\1/'); \
88+
if ! printf $(GOLANGCI_VER)\\n$$GOT\\n | sort --version-sort --check=quiet; then \
89+
echo ">> upgrading golangci-lint from $$GOT to $(GOLANGCI_VER)"; \
90+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v$(GOLANGCI_VER); \
91+
GOT=$(GOLANGCI_VER); \
92+
else \
93+
echo ">> using installed golangci-lint $$GOT >= $(GOLANGCI_VER)"; \
8894
fi
8995
@echo ">> running golangci-lint using configuration at .golangci.yml"
9096
@golangci-lint run

0 commit comments

Comments
 (0)