-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (57 loc) · 2.06 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
GO ?= go
TEST_PACKAGE = "./..."
haha:
@echo ${OSFLAG}
.PHONY: build
build:
CGO_ENABLED=0 $(GO) build
.PHONY: release
release: export BUILD = release
release: build
.PHONY: test
test: lint gotestsum goverreport prepare-envtest
@echo "running unit test..."
@mkdir -p output
. $(PWD)/bin/testbin/test.env; \
CGO_ENABLED=0 $(GOTESTSUM) --format=pkgname --jsonfile=./output/out.json --packages=$(TEST_PACKAGE) -- -covermode=atomic -coverprofile=output/coverage.out -coverpkg $(TEST_PACKAGE)
$(GOVERREPORT) -coverprofile=./output/coverage.out
.PHONY: prepare-envtest
prepare-envtest: setup-envtest
@# Prepare a k8s testenv
@mkdir -p $(PWD)/bin/testbin
@$(SETUP_ENVTEST) use --bin-dir "$(PWD)/bin/testbin" 1.27.1 -v debug -p env > $(PWD)/bin/testbin/test.env
SETUP_ENVTEST = $(shell pwd)/bin/setup-envtest
setup-envtest:
$(call go_get,$(SETUP_ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,latest)
GOLANGCI_LINT_FLAGS=
ifneq ($(GOMAXPROCS),)
GOLANGCI_LINT_FLAGS+=--concurrency=$(GOMAXPROCS)
endif
.PHONY: lint
lint: golangci_lint
@echo ">> linting code..."
$(GOLANGCI_LINT) $(GOLANGCI_LINT_FLAGS) run
GOTESTSUM = $(shell pwd)/bin/gotestsum
gotestsum:
$(call go_get,$(GOTESTSUM),gotest.tools/gotestsum,v1.10.0)
GOVERREPORT = $(shell pwd)/bin/goverreport
goverreport:
$(call go_get,$(GOVERREPORT),github.com/mcubik/goverreport,v1.0.0)
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci_lint:
$(call go_get,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,v1.52.2)
# go_get will 'go get' any package $2@$3 and install it to $1.
# usage $(call go_get,$BinaryLocalPath,$GoModuleName,$Version)
define go_get
@set -e; \
if [ -f ${1} ]; then \
[ -z ${3} ] && exit 0; \
installed_version=$$(go version -m "${1}" | grep -E '[[:space:]]+mod[[:space:]]+' | awk '{print $$3}') ; \
[ "$${installed_version}" = "${3}" ] && exit 0; \
echo ">> ${1} ${2} $${installed_version}!=${3}, ${3} will be installed."; \
fi; \
module=${2}; \
if ! [ -z ${3} ]; then module=${2}@${3}; fi; \
echo "Downloading $${module}" ;\
GOBIN=$(shell pwd)/bin $(GO) install $${module} ;
endef