sigs.k8s.io/kubebuilder/v3@v3.14.0/Makefile (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2023 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # 18 # Makefile with some common workflow for dev, build and test 19 # 20 export GOPROXY?=https://proxy.golang.org/ 21 22 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 23 ifeq (,$(shell go env GOBIN)) 24 GOBIN=$(shell go env GOPATH)/bin 25 else 26 GOBIN=$(shell go env GOBIN) 27 endif 28 29 ##@ General 30 31 # The help target prints out all targets with their descriptions organized 32 # beneath their categories. The categories are represented by '##@' and the 33 # target descriptions by '##'. The awk command is responsible for reading the 34 # entire set of makefiles included in this invocation, looking for lines of the 35 # file as xyz: ## something, and then pretty-format the target and help. Then, 36 # if there's a line with ##@ something, that gets pretty-printed as a category. 37 # More info on the usage of ANSI control characters for terminal formatting: 38 # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters 39 # More info on the awk command: 40 # http://linuxcommand.org/lc3_adv_awk.php 41 42 .PHONY: help 43 help: ## Display this help 44 @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) 45 46 ##@ Build 47 48 LD_FLAGS=-ldflags " \ 49 -X main.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \ 50 -X main.goos=$(shell go env GOOS) \ 51 -X main.goarch=$(shell go env GOARCH) \ 52 -X main.gitCommit=$(shell git rev-parse HEAD) \ 53 -X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \ 54 " 55 .PHONY: build 56 build: ## Build the project locally 57 go build $(LD_FLAGS) -o bin/kubebuilder ./cmd 58 59 .PHONY: install 60 install: build ## Build and install the binary with the current source code. Use it to test your changes locally. 61 rm -f $(GOBIN)/kubebuilder 62 cp ./bin/kubebuilder $(GOBIN)/kubebuilder 63 64 ##@ Development 65 66 .PHONY: generate 67 generate: generate-testdata generate-docs ## Update/generate all mock data. You should run this commands to update the mock data after your changes. 68 go mod tidy 69 70 .PHONY: generate-testdata 71 generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder 72 chmod -R +w testdata/ 73 rm -rf testdata/ 74 ./test/testdata/generate.sh 75 76 .PHONY: generate-docs 77 generate-docs: ## Update/generate the docs in $GOPATH/src/sigs.k8s.io/kubebuilder 78 ./hack/docs/generate.sh 79 80 .PHONY: check-docs 81 check-docs: ## Run the script to ensure that the docs are updated 82 ./hack/docs/check.sh 83 84 .PHONY: lint 85 lint: golangci-lint yamllint ## Run golangci-lint linter & yamllint 86 $(GOLANGCI_LINT) run 87 88 .PHONY: lint-fix 89 lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes 90 $(GOLANGCI_LINT) run --fix 91 92 .PHONY: yamllint 93 yamllint: 94 @files=$$(find testdata -name '*.yaml' ! -path 'testdata/*/dist/install.yaml'); \ 95 docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest $$files -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings 96 97 GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint 98 golangci-lint: 99 @[ -f $(GOLANGCI_LINT) ] || { \ 100 set -e ;\ 101 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.54.2 ;\ 102 } 103 104 .PHONY: apidiff 105 apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master 106 $(GOBIN)/go-apidiff master --compare-imports --print-compatible --repo-path=. 107 108 .PHONY: go-apidiff 109 go-apidiff: 110 go install github.com/joelanford/go-apidiff@v0.6.1 111 112 ##@ Tests 113 114 .PHONY: test 115 test: test-unit test-integration test-testdata test-book test-license ## Run the unit and integration tests (used in the CI) 116 117 .PHONY: test-unit 118 TEST_PKGS := ./pkg/... ./test/e2e/utils/... 119 test-unit: ## Run the unit tests 120 go test -race $(TEST_PKGS) 121 122 .PHONY: test-coverage 123 test-coverage: ## Run unit tests creating the output to report coverage 124 - rm -rf *.out # Remove all coverage files if exists 125 go test -race -failfast -tags=integration -coverprofile=coverage-all.out -coverpkg="./pkg/cli/...,./pkg/config/...,./pkg/internal/...,./pkg/machinery/...,./pkg/model/...,./pkg/plugin/...,./pkg/plugins/golang" $(TEST_PKGS) 126 127 .PHONY: test-integration 128 test-integration: ## Run the integration tests 129 ./test/integration.sh 130 131 .PHONY: check-testdata 132 check-testdata: ## Run the script to ensure that the testdata is updated 133 ./test/testdata/check.sh 134 135 .PHONY: test-testdata 136 test-testdata: ## Run the tests of the testdata directory 137 ./test/testdata/test.sh 138 139 #todo(remove the test-legacy whne the go/v2 be removed from kubebuilder) 140 141 .PHONY: test-legacy 142 test-legacy: ## Run the legacy tests (go/v2) of the testdata directory 143 ./test/testdata/test_legacy.sh 144 145 .PHONY: test-e2e-local 146 test-e2e-local: ## Run the end-to-end tests locally 147 ## To keep the same kind cluster between test runs, use `SKIP_KIND_CLEANUP=1 make test-e2e-local` 148 ./test/e2e/local.sh 149 150 .PHONY: test-e2e-ci 151 test-e2e-ci: ## Run the end-to-end tests (used in the CI)` 152 ./test/e2e/ci.sh 153 154 .PHONY: test-book 155 test-book: ## Run the cronjob tutorial's unit tests to make sure we don't break it 156 cd ./docs/book/src/cronjob-tutorial/testdata/project && make test 157 cd ./docs/book/src/component-config-tutorial/testdata/project && make test 158 cd ./docs/book/src/multiversion-tutorial/testdata/project && make test 159 160 .PHONY: test-license 161 test-license: ## Run the license check 162 ./test/check-license.sh