Skip to content

Commit 300242c

Browse files
committed
Makefile: install golangci-lint if not found
Check if golangci-lint is available locally -- if not, install it to GOPATH/bin. This helps with cases when golangci-lint is not available on the host (such as in prow). As we now have golangci-lint installation in Makefile, remove the code installing it from .github/workflows/test.yml for better maintainability. While at it, add lint to .PHONY targets. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent a4f66a3 commit 300242c

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Test
22
on: [push, pull_request]
33
jobs:
44
lint:
5-
env:
6-
GOLANGCI_LINT_V: 1.34.1
75
strategy:
86
matrix:
97
environment-variables: [build/config/plain.sh, build/config/libpfm4.sh, build/config/libipmctl.sh]
@@ -14,14 +12,6 @@ jobs:
1412
uses: actions/setup-go@v2
1513
with:
1614
go-version: 1.17
17-
- name: Install golangci-lint
18-
run: >
19-
cd /tmp &&
20-
mkdir -p $(go env GOPATH)/bin &&
21-
wget -q https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_V}/golangci-lint-${GOLANGCI_LINT_V}-linux-amd64.tar.gz &&
22-
tar xf golangci-lint-${GOLANGCI_LINT_V}-linux-amd64.tar.gz &&
23-
mv golangci-lint-${GOLANGCI_LINT_V}-linux-amd64/golangci-lint $(go env GOPATH)/bin &&
24-
rm -fr golangci-lint-*
2515
- name: Checkout code
2616
uses: actions/checkout@v2
2717
- name: Run golangci-lint

Makefile

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

1515
GO := go
16+
GOLANGCI_VER := v1.42.1
1617
pkgs = $(shell $(GO) list ./... | grep -v vendor)
1718
cmd_pkgs = $(shell cd cmd && $(GO) list ./... | grep -v vendor)
1819
arch ?= $(shell go env GOARCH)
19-
go_path = $(shell go env GOPATH)
2020

2121
ifeq ($(arch), amd64)
2222
Dockerfile_tag := ''
@@ -97,10 +97,15 @@ presubmit: vet
9797
@./build/check_boilerplate.sh
9898

9999
lint:
100+
@# This assumes GOPATH/bin is in $PATH -- if not, the target will fail.
101+
@if ! golangci-lint version; then \
102+
echo ">> installing golangci-lint $(GOLANGCI_VER)"; \
103+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_VER); \
104+
fi
100105
@echo ">> running golangci-lint using configuration at .golangci.yml"
101-
@GOFLAGS="$(GO_FLAGS)" $(go_path)/bin/golangci-lint run
106+
@golangci-lint run
102107

103108
clean:
104109
@rm -f *.test cadvisor
105110

106-
.PHONY: all build docker format release test test-integration vet presubmit tidy
111+
.PHONY: all build docker format release test test-integration vet lint presubmit tidy

0 commit comments

Comments
 (0)