-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
88 lines (65 loc) · 2.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
SHELL := /bin/bash
GO := GO111MODULE=on GO15VENDOREXPERIMENT=1 go
GO_NOMOD := GO111MODULE=off go
GOTEST := $(GO) test
PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/)
GO_DEPENDENCIES := $(shell find . -type f -name '*.go')
.PHONY: build
build:
$(GO) build ./...
.PHONY: linux
linux: build
test: build
$(GOTEST) -coverprofile=coverage.out ./...
test1: ## Runs single test specified by test name and optional package, eg 'make test1 TEST=TestGitCLI'
$(GOTEST) -v ./pkg/log -run $(TEST)
get-fmt-deps: ## Install test dependencies
$(GO_NOMOD) install golang.org/x/tools/cmd/goimports
fmt: importfmt ## Format the code
@FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)`
@([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)
.PHONY: lint
lint: ## Lint the code
./hack/linter.sh
.PHONY: modtidy
modtidy:
$(GO) mod tidy
.PHONY: coverage
coverage:
$(GO) tool cover -html=coverage.out
.PHONY: cover
cover:
$(GO) tool cover -func coverage.out | grep total
.PHONY: code-generate
code-generate:
./hack/generate.sh
.PHONY: docs gen-schema
docs: generate-refdocs
.PHONY: gen-schema
gen-schema:
mkdir -p schema
go run cmd/schemagen/main.go
# Recommended CRD option for v1: https://github.com/kubernetes-sigs/kubebuilder/blob/acdede50a58a1b9ac7fa66fc335bc810fe9ef6f6/docs/book/src/reference/generating-crd.md?plain=1#L167
CRD_OPTIONS ?= "crd"
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
include Makefile.codegen
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef