From 815be5ffd73a6d5e8d9a509db0b51de8a03883d9 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Fri, 28 Jun 2024 10:39:12 +0200 Subject: [PATCH] makefile enhancements --- Makefile | 63 +++++++++++++++++----------------------- make/tools/ginkgo.mk | 10 +++++++ make/tools/kind.mk | 7 +++++ make/tools/kustomize.mk | 6 ++++ make/{ => tools}/lint.mk | 7 ++--- 5 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 make/tools/ginkgo.mk create mode 100644 make/tools/kind.mk create mode 100644 make/tools/kustomize.mk rename make/{ => tools}/lint.mk (69%) diff --git a/Makefile b/Makefile index 0ca189f..7cd65cb 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,32 @@ SHELL := /bin/bash -MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MKFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) GO ?= go all: help -.PHONY : help -help: Makefile - @sed -n 's/^##//p' $< - -# Ginkgo tool -GINKGO = $(PROJECT_PATH)/bin/ginkgo -$(GINKGO): - # In order to make sure the version of the ginkgo cli installed - # is the same as the version of go.mod, - # instead of calling go-install-tool, - # running go install from the current module will pick version from current go.mod file. - GOBIN=$(PROJECT_PATH)/bin go install github.com/onsi/ginkgo/v2/ginkgo - -.PHONY: ginkgo -ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. - -KIND = $(PROJECT_PATH)/bin/kind -KIND_VERSION = v0.22.0 -$(KIND): - $(call go-install-tool,$(KIND),sigs.k8s.io/kind@$(KIND_VERSION)) +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk commands is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php -.PHONY: kind -kind: $(KIND) ## Download kind locally if necessary. +.PHONY : help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -KUSTOMIZE = $(PROJECT_PATH)/bin/kustomize -$(KUSTOMIZE): - $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5) +include ./make/tools/*.mk -.PHONY: kustomize -kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. +##@ Development -## test: Run unit tests .PHONY : test -test: clean-cov fmt vet $(GINKGO) +test: clean-cov fmt vet $(GINKGO) ## Run unit tests mkdir -p $(PROJECT_PATH)/coverage # Shuffle both the order in which specs within a suite run, and the order in which different suites run # You can always rerun a given ordering later by passing the --seed flag a matching seed. @@ -51,9 +38,9 @@ test: clean-cov fmt vet $(GINKGO) --coverprofile cover.out \ ./pkg/... ./cmd/... -## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) + .PHONY : install -install: fmt vet +install: fmt vet ## Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) @set -e; \ GIT_SHA=$$(git rev-parse --short=7 HEAD 2>/dev/null) || { \ GIT_HASH=$${GITHUB_SHA:-NO_SHA}; \ @@ -79,28 +66,30 @@ prepare-local-cluster: $(KIND) ## Deploy locally kuadrant operator from the curr env-setup: $(MAKE) gateway-api-install -## local-setup: Sets up Kind cluster with GatewayAPI manifests and istio GW, nothing Kuadrant. Build and install kuadrantctl binary .PHONY: local-setup -local-setup: +local-setup: ## Sets up Kind cluster with GatewayAPI manifests $(MAKE) prepare-local-cluster $(MAKE) env-setup -## local-cleanup: Delete local cluster .PHONY: local-cleanup local-cleanup: ## Delete local cluster $(MAKE) kind-delete-cluster .PHONY : fmt -fmt: +fmt: ## Run go fmt ./... $(GO) fmt ./... .PHONY : vet -vet: +vet: ## Run go vet ./... $(GO) vet ./... .PHONY: clean-cov clean-cov: ## Remove coverage reports rm -rf $(PROJECT_PATH)/coverage +.PHONY: run-lint +run-lint: $(GOLANGCI-LINT) ## Run linter tool (golangci-lint) + $(GOLANGCI-LINT) run --timeout 2m + # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk diff --git a/make/tools/ginkgo.mk b/make/tools/ginkgo.mk new file mode 100644 index 0000000..4a1e0ef --- /dev/null +++ b/make/tools/ginkgo.mk @@ -0,0 +1,10 @@ +GINKGO = $(PROJECT_PATH)/bin/ginkgo +$(GINKGO): + # In order to make sure the version of the ginkgo cli installed + # is the same as the version of go.mod, + # instead of calling go-install-tool, + # running go install from the current module will pick version from current go.mod file. + GOBIN=$(PROJECT_PATH)/bin go install github.com/onsi/ginkgo/v2/ginkgo + +.PHONY: ginkgo +ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. diff --git a/make/tools/kind.mk b/make/tools/kind.mk new file mode 100644 index 0000000..625ad87 --- /dev/null +++ b/make/tools/kind.mk @@ -0,0 +1,7 @@ +KIND = $(PROJECT_PATH)/bin/kind +KIND_VERSION = v0.22.0 +$(KIND): + $(call go-install-tool,$(KIND),sigs.k8s.io/kind@$(KIND_VERSION)) + +.PHONY: kind +kind: $(KIND) ## Download kind locally if necessary. diff --git a/make/tools/kustomize.mk b/make/tools/kustomize.mk new file mode 100644 index 0000000..5d7f965 --- /dev/null +++ b/make/tools/kustomize.mk @@ -0,0 +1,6 @@ +KUSTOMIZE = $(PROJECT_PATH)/bin/kustomize +$(KUSTOMIZE): + $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5) + +.PHONY: kustomize +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. diff --git a/make/lint.mk b/make/tools/lint.mk similarity index 69% rename from make/lint.mk rename to make/tools/lint.mk index c190494..9bb1bf9 100644 --- a/make/lint.mk +++ b/make/tools/lint.mk @@ -1,11 +1,8 @@ + GOLANGCI-LINT=$(PROJECT_PATH)/bin/golangci-lint $(GOLANGCI-LINT): mkdir -p $(PROJECT_PATH)/bin curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.55.2 .PHONY: golangci-lint -golangci-lint: $(GOLANGCI-LINT) - -.PHONY: run-lint -run-lint: $(GOLANGCI-LINT) - $(GOLANGCI-LINT) run --timeout 2m +golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint