Skip to content

Commit f4d30ae

Browse files
committed
Makefile: improve golangci-lint installer, clean up
generate_testdata.sh,test.sh: use 'command -v', which won't print if a binary isn't found, over 'which' to avoid unnecessary error text
1 parent 71a77cd commit f4d30ae

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# Makefile with some common workflow for dev, build and test
1919
#
2020
export GOPROXY?=https://proxy.golang.org/
21-
CONTROLLER_GEN_BIN_PATH := $(shell which controller-gen)
2221

2322
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2423
ifeq (,$(shell go env GOBIN))
@@ -46,7 +45,7 @@ build: ## Build the project locally
4645
.PHONY: install
4746
install: ## Build and install the binary with the current source code. Use it to test your changes locally.
4847
make build
49-
cp ./bin/kubebuilder $(shell go env GOPATH)/bin/kubebuilder
48+
cp ./bin/kubebuilder $(GOBIN)/kubebuilder
5049

5150
##@ Development
5251

@@ -60,22 +59,19 @@ generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/ku
6059
./generate_testdata.sh
6160

6261
.PHONY: lint
63-
lint: golangci-lint ## Run golangci lint checks
64-
@$(GOLANGCI_LINT) run
62+
lint: golangci-lint ## Run golangci-lint linter
63+
$(GOLANGCI_LINT) run
6564

66-
lint-fix: golangci-lint ## Run golangci lint to automatically perform fixes
67-
@$(GOLANGCI_LINT) run --fix
65+
.PHONY: lint-fix
66+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
67+
$(GOLANGCI_LINT) run --fix
6868

69+
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
6970
golangci-lint:
70-
ifeq (, $(shell which golangci-lint))
71-
@{ \
71+
@[ -f $(GOLANGCI_LINT) ] || { \
7272
set -e ;\
73-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.29.0 ;\
73+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.29.0 ;\
7474
}
75-
GOLANGCI_LINT=$(shell go env GOPATH)/bin/golangci-lint
76-
else
77-
GOLANGCI_LINT=$(shell which golangci-lint)
78-
endif
7975

8076
##@ Tests
8177

generate_testdata.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ scaffold_test_project() {
3939
local plugin_flag="${plugin:+--plugins $plugin}"
4040

4141
# Remove tool binaries so the correct versions are used for each plugin version.
42-
rm -f "$(which controller-gen)"
43-
rm -f "$(which kustomize)"
42+
rm -f "$(command -v controller-gen)"
43+
rm -f "$(command -v kustomize)"
4444

4545
if [ $version == "2" ] || [ $version == "3-alpha" ]; then
4646
if [ $version == "2" ] && [ -n "$plugin_flag" ]; then

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ EOF
9292
function test_project {
9393
local project_dir=$1
9494
local version=$2
95-
rm -f "$(which controller-gen)"
96-
rm -f "$(which kustomize)"
95+
rm -f "$(command -v controller-gen)"
96+
rm -f "$(command -v kustomize)"
9797
header_text "performing tests in dir $project_dir for project version v$version"
9898
cd testdata/$project_dir
9999
make all test

0 commit comments

Comments
 (0)