forked from fidelity/kraan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.mk
131 lines (101 loc) · 3.8 KB
/
makefile.mk
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
# Makes a recipe passed to a single invocation of the shell.
.ONESHELL:
MAKEFILE_PATH:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
GO_SOURCES:=$(wildcard *.go)
GO_TEST_SOURCES:=$(wildcard *test.go)
COVERAGE_DIR:=$(CURDIR)/coverage
COVERAGE_HTML_DIR:=$(COVERAGE_DIR)/html
COVERAGE_ARTIFACT:=${COVERAGE_HTML_DIR}/main.html
INTEGRATION_COVERAGE_DIR:=$(CURDIR)/integration-coverage
INTEGRATION_COVERAGE_HTML_DIR:=$(INTEGRATION_COVERAGE_DIR)/html
INTEGRATION_COVERAGE_ARTIFACT:=${INTEGRATION_COVERAGE_HTML_DIR}/main.html
LINT_ARTIFACT:=._gometalinter
TEST_ARTIFACT:=${COVERAGE_DIR}/coverage.out
INTEGRATION_TEST_ARTIFACT:=${INTEGRATION_COVERAGE_DIR}/integration-coverage.out
YELLOW:=\033[0;33m
GREEN:=\033[0;32m
RED:=\033[0;31m
NC:=\033[0m
NC_DIR:=: $(CURDIR)$(NC)
# Controller Integration test setup
export USE_EXISTING_CLUSTER?=true
export ZAP_LOG_LEVEL?=0
export KRAAN_NAMESPACE?=gotk-system
export KUBECONFIG?=${HOME}/.kube/config
export DATA_PATH?=$(shell mktemp -d -t kraan-XXXXXXXXXX)
export SC_HOST?=localhost:8090
.PHONY: all clean goimports gofmt clean-lint lint clean-test test \
clean-coverage coverage clean-integration integration integration-coverage clean-integration-coverage
# Stop prints each line of the recipe.
.SILENT:
all: lint coverage
clean: clean-lint clean-coverage clean-test
integration: integration-coverage integration-test
clean-integration: clean-integration-test clean-integration-coverage
goimports: ${GO_SOURCES}
echo "${YELLOW}Running goimports${NC_DIR}" && \
goimports -w --local github.com/fidelity/kraan $^
gofmt: ${GO_SOURCES}
echo "${YELLOW}Running gofmt${NC_DIR}" && \
gofmt -w -s $^
clean-test:
rm -rf $(dir ${TEST_ARTIFACT})
test: ${TEST_ARTIFACT}
${TEST_ARTIFACT}: ${GO_SOURCES}
if [ -n "${GO_TEST_SOURCES}" ]; then \
{ echo "${YELLOW}Running go test${NC_DIR}" && \
mkdir -p $(dir ${TEST_ARTIFACT}) && \
go test -coverprofile=$@ -v && \
echo "${GREEN}TEST PASSED${NC}"; } || \
{ $(MAKE) --makefile=$(lastword $(MAKEFILE_LIST)) clean-test && \
echo "${RED}TEST FAILED${NC}" && \
exit 1; } \
fi
clean-coverage:
rm -rf $(dir ${COVERAGE_ARTIFACT})
coverage: ${COVERAGE_ARTIFACT}
${COVERAGE_ARTIFACT}: ${TEST_ARTIFACT}
if [ -e "$<" ]; then \
echo "${YELLOW}Running go tool cover${NC_DIR}" && \
mkdir -p $(dir ${COVERAGE_ARTIFACT}) && \
go tool cover -html=$< -o $@ && \
echo "${GREEN}Generated: file://$@${NC}"; \
fi
clean-integration-test: clean-integration-coverage
rm -rf $(dir ${INTEGRATION_TEST_ARTIFACT})
integration-test: ${INTEGRATION_TEST_ARTIFACT}
${INTEGRATION_TEST_ARTIFACT}: ${GO_SOURCES}
if [ -n "${GO_TEST_SOURCES}" ]; then \
{ echo "${YELLOW}Running integration test${NC_DIR}" && \
mkdir -p $(dir ${INTEGRATION_TEST_ARTIFACT}) && \
go test -coverprofile=$@ --tags=integration && \
echo "${GREEN}TEST PASSED${NC}"; } || \
{ echo "${RED}TEST FAILED${NC}" && \
exit 1; } \
fi
clean-integration-coverage:
rm -rf $(dir ${INTEGRATION_COVERAGE_ARTIFACT})
integration-coverage: ${INTEGRATION_COVERAGE_ARTIFACT}
${INTEGRATION_COVERAGE_ARTIFACT}: ${INTEGRATION_TEST_ARTIFACT}
if [ -e "$<" ]; then \
echo "${YELLOW}Running go tool cover${NC_DIR}" && \
mkdir -p $(dir ${INTEGRATION_COVERAGE_ARTIFACT}) && \
go tool cover -html=$< -o $@ && \
echo "${GREEN}Generated: file://$@${NC}"; \
fi
clean-lint:
rm -f ${LINT_ARTIFACT}
lint: ${LINT_ARTIFACT}
${LINT_ARTIFACT}: ${MAKEFILE_PATH}/.golangci.yml ${GO_SOURCES}
echo "${YELLOW}Running go lint${NC_DIR}" && \
(cd ${MAKEFILE_PATH} && \
procs=$$(expr $$( \
(grep -c ^processor /proc/cpuinfo || \
sysctl -n hw.ncpu || \
echo 1) 2>/dev/null) '*' 2 '-' 1) && \
GOPROXY=https://proxy.golang.org,direct \
golangci-lint run \
--config ${MAKEFILE_PATH}/.golangci.yml \
--concurrency=$${procs} \
"$$(realpath --relative-to ${MAKEFILE_PATH} ${CURDIR})/.") && \
touch $@