|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -# Copyright 2019 The Kubernetes Authors. |
| 3 | +# Copyright 2020 The Kubernetes Authors. |
4 | 4 | #
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | # you may not use this file except in compliance with the License.
|
|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 |
| -# |
18 |
| -# Makefile with some common workflow for dev, build and test |
19 |
| -# |
| 17 | +# If you update this file, please follow |
| 18 | +# https://suva.sh/posts/well-documented-makefiles |
| 19 | + |
| 20 | +## -------------------------------------- |
| 21 | +## General |
| 22 | +## -------------------------------------- |
| 23 | + |
| 24 | +SHELL:=/usr/bin/env bash |
| 25 | +.DEFAULT_GOAL:=help |
20 | 26 |
|
21 |
| -##@ General |
| 27 | +# Use GOPROXY environment variable if set |
| 28 | +GOPROXY := $(shell go env GOPROXY) |
| 29 | +ifeq ($(GOPROXY),) |
| 30 | +GOPROXY := https://proxy.golang.org |
| 31 | +endif |
| 32 | +export GOPROXY |
| 33 | + |
| 34 | +# Active module mode, as we use go modules to manage dependencies |
| 35 | +export GO111MODULE=on |
| 36 | + |
| 37 | +# Tools. |
| 38 | +TOOLS_DIR := hack/tools |
| 39 | +TOOLS_BIN_DIR := $(TOOLS_DIR)/bin |
| 40 | +GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint) |
22 | 41 |
|
23 | 42 | # The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
|
24 | 43 | # The awk commands is responsible to read 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.
|
|
28 | 47 | help: ## Display this help
|
29 | 48 | @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)
|
30 | 49 |
|
31 |
| -##@ Tests |
| 50 | +## -------------------------------------- |
| 51 | +## Testing |
| 52 | +## -------------------------------------- |
32 | 53 |
|
33 | 54 | .PHONY: test
|
34 |
| -test: ## Run the script check-everything.sh which will check all |
35 |
| - GO111MODULE=on TRACE=1 ./hack/check-everything.sh |
| 55 | +test: ## Run the script check-everything.sh which will check all. |
| 56 | + TRACE=1 ./hack/check-everything.sh |
| 57 | + |
| 58 | +## -------------------------------------- |
| 59 | +## Binaries |
| 60 | +## -------------------------------------- |
| 61 | + |
| 62 | +$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder. |
| 63 | + cd $(TOOLS_DIR); go build -tags=tools -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint |
| 64 | + |
| 65 | +## -------------------------------------- |
| 66 | +## Linting |
| 67 | +## -------------------------------------- |
| 68 | + |
| 69 | +.PHONY: lint |
| 70 | +lint: $(GOLANGCI_LINT) ## Lint codebase. |
| 71 | + $(GOLANGCI_LINT) run -v |
| 72 | + |
| 73 | +## -------------------------------------- |
| 74 | +## Generate |
| 75 | +## -------------------------------------- |
| 76 | + |
| 77 | +.PHONY: modules |
| 78 | +modules: ## Runs go mod to ensure modules are up to date. |
| 79 | + go mod tidy |
| 80 | + cd $(TOOLS_DIR); go mod tidy |
| 81 | + |
| 82 | +## -------------------------------------- |
| 83 | +## Cleanup / Verification |
| 84 | +## -------------------------------------- |
| 85 | + |
| 86 | +.PHONY: clean |
| 87 | +clean: ## Cleanup. |
| 88 | + $(MAKE) clean-bin |
| 89 | + |
| 90 | +.PHONY: clean-bin |
| 91 | +clean-bin: ## Remove all generated binaries. |
| 92 | + rm -rf hack/tools/bin |
36 | 93 |
|
| 94 | +.PHONY: verify-modules |
| 95 | +verify-modules: modules |
| 96 | + @if !(git diff --quiet HEAD -- go.sum go.mod); then \ |
| 97 | + echo "go module files are out of date"; exit 1; \ |
| 98 | + fi |
0 commit comments