diff --git a/Makefile b/Makefile index bb766c7c9..31981217e 100644 --- a/Makefile +++ b/Makefile @@ -160,20 +160,35 @@ GOBIN=$$(pwd)/.go/bin PROTOC_GEN_GO_VERSION := $(shell go list -m -f '{{.Version}}' google.golang.org/protobuf) GOIMPORTS_VERSION := $(shell go list -m -f '{{.Version}}' golang.org/x/tools) +# ============================================================================== +# ================================ COMMANDS ==================================== +# ============================================================================== + +# ================================== +# Help +# ================================== +# To document a new target, add "## " at the end of the target line. +# Example: new-target: ## Description of the new target + +.PHONY: help +help: ## Display this help message + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_%-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) + + # If you want to build all binaries, see the 'all-build' rule. # If you want to build all containers, see the 'all-containers' rule. -all: +all: ## Build the default velero binary @$(MAKE) build -build-%: +build-%: ## Build specific binary @$(MAKE) --no-print-directory ARCH=$* build -all-build: $(addprefix build-, $(CLI_PLATFORMS)) +all-build: $(addprefix build-, $(CLI_PLATFORMS)) ## Build for all CLI platforms -all-containers: +all-containers: ## Build all containers @$(MAKE) --no-print-directory container -local: build-dirs +local: build-dirs ## Build locally # Add DEBUG=1 to enable debug locally GOOS=$(GOOS) \ GOARCH=$(GOARCH) \ @@ -187,7 +202,7 @@ local: build-dirs OUTPUT_DIR=$$(pwd)/_output/bin/$(GOOS)/$(GOARCH) \ ./hack/build.sh -build: _output/bin/$(GOOS)/$(GOARCH)/$(BIN) +build: _output/bin/$(GOOS)/$(GOARCH)/$(BIN) ## Build the velero binary (use build-- for specific targets) _output/bin/$(GOOS)/$(GOARCH)/$(BIN): build-dirs @echo "building: $@" @@ -207,7 +222,7 @@ _output/bin/$(GOOS)/$(GOARCH)/$(BIN): build-dirs TTY := $(shell tty -s && echo "-t") # Example: make shell CMD="date > datefile" -shell: build-dirs build-env +shell: build-dirs build-env ## Run a shell in the build container @# bind-mount the Velero root dir in at /github.com/vmware-tanzu/velero @# because the Kubernetes code-generator tools require the project to @# exist in a directory hierarchy ending like this (but *NOT* necessarily @@ -230,7 +245,7 @@ shell: build-dirs build-env $(BUILDER_IMAGE) \ /bin/sh $(CMD) -container: +container: ## Build the docker container (use container-- for specific targets) ifneq ($(CONTAINER_TOOL),docker) $(error $(DOCKER_ONLY_ERROR)) endif @@ -312,7 +327,7 @@ endif @echo "built container: $(IMAGE):$(VERSION)-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)" -push-manifest: +push-manifest: ## Push multi-arch manifest ifneq ($(CONTAINER_TOOL),docker) $(error $(DOCKER_ONLY_ERROR)) endif @@ -335,36 +350,36 @@ endif @docker manifest inspect --insecure=$(INSECURE_REGISTRY) $(IMAGE_TAG) SKIP_TESTS ?= -test: build-dirs +test: build-dirs ## Run unit tests ifneq ($(SKIP_TESTS), 1) @$(MAKE) shell CMD="-c 'hack/test.sh $(WHAT)'" endif -test-local: build-dirs +test-local: build-dirs ## Run unit tests locally ifneq ($(SKIP_TESTS), 1) hack/test.sh $(WHAT) endif -verify: +verify: ## Run all verify scripts ifneq ($(SKIP_TESTS), 1) @$(MAKE) shell CMD="-c 'hack/verify-all.sh'" endif -lint: +lint: ## Run linter ifneq ($(SKIP_TESTS), 1) @$(MAKE) shell CMD="-c 'hack/lint.sh'" endif -local-lint: +local-lint: ## Run linter locally ifneq ($(SKIP_TESTS), 1) @hack/lint.sh endif -update: +update: ## Run all update scripts @$(MAKE) shell CMD="-c 'hack/update-all.sh'" # update-crd is for development purpose only, it is faster than update, so is a shortcut when you want to generate CRD changes only -update-crd: +update-crd: ## Update generated CRD code @$(MAKE) shell CMD="-c 'hack/update-3generated-crd-code.sh'" build-dirs: @@ -392,7 +407,7 @@ else $(CONTAINER_TOOL) pull -q $(BUILDER_IMAGE) || $(MAKE) build-image endif -build-image: +build-image: ## Build the builder image @# When we build a new image we just untag the old one. @# This makes sure we don't leave the orphaned image behind. $(eval old_id=$(shell $(CONTAINER_TOOL) image inspect --format '{{ .ID }}' ${BUILDER_IMAGE} 2>/dev/null)) @@ -409,7 +424,7 @@ endif $(CONTAINER_TOOL) rmi -f $$id || true; \ fi -push-build-image: +push-build-image: ## Push the builder image ifneq ($(CONTAINER_TOOL),docker) $(error $(DOCKER_ONLY_ERROR)) endif @@ -423,10 +438,10 @@ else docker push $(BUILDER_IMAGE) endif -build-image-hugo: +build-image-hugo: ## Build the hugo image for docs cd site && $(CONTAINER_TOOL) build --pull -t $(HUGO_IMAGE) . -clean: +clean: ## Clean up build artifacts and modcache # if we have a cached image then use it to run go clean --modcache # this test checks if we there is an image id in the BUILDER_IMAGE_CACHED variable. ifneq ($(strip $(BUILDER_IMAGE_CACHED)),) @@ -438,21 +453,21 @@ endif .PHONY: modules -modules: +modules: ## Tidy go modules go mod tidy .PHONY: verify-modules -verify-modules: modules +verify-modules: modules ## Verify go modules are up to date @if !(git diff --quiet HEAD -- go.sum go.mod); then \ echo "go module files are out of date, please commit the changes to go.mod and go.sum"; exit 1; \ fi -ci: verify-modules verify all test +ci: verify-modules verify all test ## Run CI checks -changelog: +changelog: ## Generate changelog hack/release-tools/changelog.sh # release builds a GitHub release using goreleaser within the build container. @@ -470,7 +485,7 @@ changelog: # RELEASE_NOTES_FILE=changelogs/CHANGELOG-1.2.md \ # PUBLISH=true \ # make release -release: +release: ## Build a GitHub release using goreleaser $(MAKE) shell CMD="-c '\ GITHUB_TOKEN=$(GITHUB_TOKEN) \ RELEASE_NOTES_FILE=$(RELEASE_NOTES_FILE) \ @@ -478,7 +493,7 @@ release: REGISTRY=$(REGISTRY) \ ./hack/release-tools/goreleaser.sh'" -serve-docs: build-image-hugo +serve-docs: build-image-hugo ## Serve the documentation site locally $(CONTAINER_TOOL) run \ --rm \ -v "$$(pwd)/site:/project" \ @@ -487,18 +502,18 @@ serve-docs: build-image-hugo server --bind=0.0.0.0 --enableGitInfo=false # gen-docs generates a new versioned docs directory under site/content/docs. # Please read the documentation in the script for instructions on how to use it. -gen-docs: +gen-docs: ## Generate a new versioned docs directory @hack/release-tools/gen-docs.sh .PHONY: test-e2e -test-e2e: local +test-e2e: local ## Run end-to-end tests $(MAKE) -e VERSION=$(VERSION) -C test/ run-e2e .PHONY: test-perf -test-perf: local +test-perf: local ## Run performance tests $(MAKE) -e VERSION=$(VERSION) -C test/ run-perf -go-generate: +go-generate: ## Run go generate go generate ./pkg/... # requires an authenticated gh cli @@ -510,11 +525,11 @@ go-generate: new-changelog: GH_LOGIN ?= $(shell gh pr view --json author --jq .author.login 2> /dev/null) new-changelog: GH_PR_NUMBER ?= $(shell gh pr view --json number --jq .number 2> /dev/null) new-changelog: CHANGELOG_BODY ?= '$(shell gh pr view --json title --jq .title)' -new-changelog: +new-changelog: ## Create a new changelog file for a PR @if [ "$(GH_LOGIN)" = "" ]; then \ echo "branch does not have PR or cli not logged in, try 'gh auth login' or 'gh pr create'"; \ exit 1; \ fi @mkdir -p ./changelogs/unreleased/ && \ echo $(CHANGELOG_BODY) > ./changelogs/unreleased/$(GH_PR_NUMBER)-$(GH_LOGIN) && \ - echo \"$(CHANGELOG_BODY)\" added to "./changelogs/unreleased/$(GH_PR_NUMBER)-$(GH_LOGIN)" \ No newline at end of file + echo \"$(CHANGELOG_BODY)\" added to "./changelogs/unreleased/$(GH_PR_NUMBER)-$(GH_LOGIN)"