Skip to content

Commit

Permalink
Makefile: improve golangci-lint installer, clean up
Browse files Browse the repository at this point in the history
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
  • Loading branch information
estroz committed Nov 11, 2020
1 parent fe0fa35 commit ecdff22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# Makefile with some common workflow for dev, build and test
#
export GOPROXY?=https://proxy.golang.org/
CONTROLLER_GEN_BIN_PATH := $(shell which controller-gen)

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

##@ Development

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

.PHONY: lint
lint: golangci-lint ## Run golangci lint checks
@$(GOLANGCI_LINT) run
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run

lint-fix: golangci-lint ## Run golangci lint to automatically perform fixes
@$(GOLANGCI_LINT) run --fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint:
ifeq (, $(shell which golangci-lint))
@{ \
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.29.0 ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.29.0 ;\
}
GOLANGCI_LINT=$(shell go env GOPATH)/bin/golangci-lint
else
GOLANGCI_LINT=$(shell which golangci-lint)
endif

##@ Tests

Expand Down
4 changes: 2 additions & 2 deletions generate_testdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ scaffold_test_project() {
local plugin_flag="${plugin:+--plugins $plugin}"

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

if [ $version == "2" ] || [ $version == "3-alpha" ]; then
if [ $version == "2" ] && [ -n "$plugin_flag" ]; then
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ EOF
function test_project {
local project_dir=$1
local version=$2
rm -f "$(which controller-gen)"
rm -f "$(which kustomize)"
rm -f "$(command -v controller-gen)"
rm -f "$(command -v kustomize)"
header_text "performing tests in dir $project_dir for project version v$version"
cd testdata/$project_dir
make all test
Expand Down

0 comments on commit ecdff22

Please sign in to comment.