forked from kudobuilder/kuttl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (110 loc) · 4.22 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
SHELL=/bin/bash -o pipefail
CLI := kubectl-kuttl
GIT_VERSION_PATH := github.com/kudobuilder/kuttl/pkg/version.gitVersion
GIT_VERSION := $(shell git describe --abbrev=0 --tags | cut -b 2-)
GIT_COMMIT_PATH := github.com/kudobuilder/kuttl/pkg/version.gitCommit
GIT_COMMIT := $(shell git rev-parse HEAD | cut -b -8)
SOURCE_DATE_EPOCH := $(shell git show -s --format=format:%ct HEAD)
BUILD_DATE_PATH := github.com/kudobuilder/kuttl/pkg/version.buildDate
DATE_FMT := "%Y-%m-%dT%H:%M:%SZ"
BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}
GOLANGCI_LINT_VER = "1.38.0"
export GO111MODULE=on
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##############################
# Development #
##############################
##@ Development
.PHONY: lint
lint: ## Run golangci-lint
ifneq (${GOLANGCI_LINT_VER}, "$(shell ./bin/golangci-lint version --format short 2>&1)")
@echo "golangci-lint missing or not version '${GOLANGCI_LINT_VER}', downloading..."
curl -sSfL "https://raw.githubusercontent.com/golangci/golangci-lint/v${GOLANGCI_LINT_VER}/install.sh" | sh -s -- -b ./bin "v${GOLANGCI_LINT_VER}"
endif
./bin/golangci-lint --timeout 3m run --build-tags integration
.PHONY: download
download: ## Downloads go dependencies
go mod download
.PHONY: generate-clean
generate-clean:
rm -rf hack/code-gen
.PHONY: cli
# Build CLI
cli: ## Builds CLI
go build -ldflags "${LDFLAGS}" -o bin/${CLI} ./cmd/kubectl-kuttl
.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}
.PHONY: clean
clean: cli-clean ## Cleans CLI and kind logs
rm -rf kind-logs-*
.PHONY: docker
# build a local docker image (specific to the local platform only)
docker: ## Builds docker image for architecture of the local env
docker build . -t kuttl
.PHONY: docker-release
# build and push a multi-arch docker image
docker-release: ## Build and push multi-arch docker images
./hack/docker-release.sh
# Install CLI
cli-install: ## Installs kubectl-kuttl to GOBIN
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kuttl
##############################
# Generate Artifacts #
##############################
##@ Generate
.PHONY: generate
# Generate code
generate: ## Generates code
ifneq ($(shell go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools), $(shell controller-gen --version 2>/dev/null | cut -b 10-))
@echo "(Re-)installing controller-gen. Current version: $(controller-gen --version 2>/dev/null | cut -b 10-). Need $(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)"
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)
endif
controller-gen crd paths=./pkg/apis/... output:crd:dir=config/crds output:stdout
./hack/update_codegen.sh
##############################
# Reports #
##############################
##@ Reports
.PHONY: todo
# Show to-do items per file.
todo: ## Shows todos from code
@grep \
--exclude-dir=hack \
--exclude=Makefile \
--exclude-dir=.git \
--exclude-dir=bin \
--text \
--color \
-nRo -E " *[^\.]TODO.*|SkipNow" .
##############################
# Tests #
##############################
##@ Tests
.PHONY: all
all: lint test integration-test ## Runs lint, unit and integration tests
# Run unit tests
.PHONY: test
test: ## Runs unit tests
ifdef _INTELLIJ_FORCE_SET_GOFLAGS
# Run tests from a Goland terminal. Goland already set '-mod=readonly'
go test ./pkg/... -v -coverprofile cover.out
else
go test ./pkg/... -v -mod=readonly -coverprofile cover.out
endif
.PHONY: integration-test
# Run integration tests
integration-test: ## Runs integration tests
./hack/run-integration-tests.sh
# Run e2e tests
.PHONY: e2e-test
e2e-test: cli
./hack/run-e2e-tests.sh