|
| 1 | +PROJECT_FULL_NAME := quota-operator |
| 2 | +REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) |
| 3 | +EFFECTIVE_VERSION := $(shell $(REPO_ROOT)/hack/common/get-version.sh) |
| 4 | + |
| 5 | +COMMON_MAKEFILE ?= $(REPO_ROOT)/hack/common/Makefile |
| 6 | +ifneq (,$(wildcard $(COMMON_MAKEFILE))) |
| 7 | +include $(COMMON_MAKEFILE) |
| 8 | +endif |
| 9 | + |
| 10 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 11 | +ifeq (,$(shell go env GOBIN)) |
| 12 | +GOBIN=$(shell go env GOPATH)/bin |
| 13 | +else |
| 14 | +GOBIN=$(shell go env GOBIN) |
| 15 | +endif |
| 16 | + |
| 17 | +# CONTAINER_TOOL defines the container tool to be used for building images. |
| 18 | +# Be aware that the target commands are only tested with Docker which is |
| 19 | +# scaffolded by default. However, you might want to replace it to use other |
| 20 | +# tools. (i.e. podman) |
| 21 | +CONTAINER_TOOL ?= docker |
| 22 | + |
| 23 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 24 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 25 | +SHELL = /usr/bin/env bash -o pipefail |
| 26 | +.SHELLFLAGS = -ec |
| 27 | + |
| 28 | +COMPONENTS ?= quota-operator |
| 29 | +API_CODE_DIRS := $(REPO_ROOT)/api/... |
| 30 | +ROOT_CODE_DIRS := $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/... |
| 31 | + |
| 32 | +##@ General |
| 33 | + |
| 34 | +ifndef HELP_TARGET |
| 35 | +.PHONY: help |
| 36 | +help: ## Display this help. |
| 37 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 38 | +endif |
| 39 | + |
| 40 | +##@ Development |
| 41 | + |
| 42 | +.PHONY: manifests |
| 43 | +manifests: controller-gen ## Generate CustomResourceDefinition objects. |
| 44 | + @echo "> Remove existing CRD manifests" |
| 45 | + @rm -rf api/crds/manifests/ |
| 46 | + @rm -rf config/crd/bases/ |
| 47 | + @echo "> Generating CRD Manifests" |
| 48 | + @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/..." output:crd:artifacts:config=api/crds/manifests |
| 49 | + @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/..." output:crd:artifacts:config=config/crd/bases |
| 50 | + |
| 51 | +.PHONY: generate |
| 52 | +generate: generate-code manifests format ## Generates code (DeepCopy stuff, CRDs), documentation index, and runs formatter. |
| 53 | + |
| 54 | +.PHONY: generate-code |
| 55 | +generate-code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. Also fetches external APIs. |
| 56 | + @echo "> Generating DeepCopy Methods" |
| 57 | + @$(CONTROLLER_GEN) object paths="$(REPO_ROOT)/api/..." |
| 58 | + |
| 59 | +.PHONY: format |
| 60 | +format: goimports ## Formats the imports. |
| 61 | + @FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh $(API_CODE_DIRS) $(ROOT_CODE_DIRS) |
| 62 | + |
| 63 | +.PHONY: verify |
| 64 | +verify: golangci-lint goimports ## Runs linter, 'go vet', and checks if the formatter has been run. |
| 65 | + @( echo "> Verifying api module ..." && \ |
| 66 | + pushd $(REPO_ROOT)/api &>/dev/null && \ |
| 67 | + go vet $(API_CODE_DIRS) && \ |
| 68 | + $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(API_CODE_DIRS) && \ |
| 69 | + popd &>/dev/null ) |
| 70 | + @( echo "> Verifying root module ..." && \ |
| 71 | + pushd $(REPO_ROOT) &>/dev/null && \ |
| 72 | + go vet $(ROOT_CODE_DIRS) && \ |
| 73 | + $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(ROOT_CODE_DIRS) && \ |
| 74 | + popd &>/dev/null ) |
| 75 | + @test "$(SKIP_FORMATTING_CHECK)" = "true" || \ |
| 76 | + ( echo "> Checking for unformatted files ..." && \ |
| 77 | + FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh --verify $(API_CODE_DIRS) $(ROOT_CODE_DIRS) ) |
| 78 | + |
| 79 | +.PHONY: test |
| 80 | +test: ## Run tests. |
| 81 | + go test $(ROOT_CODE_DIRS) -coverprofile cover.out |
| 82 | + go tool cover --html=cover.out -o cover.html |
| 83 | + go tool cover -func cover.out | tail -n 1 |
0 commit comments