forked from acronis/perfkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (84 loc) · 3.6 KB
/
Makefile
File metadata and controls
102 lines (84 loc) · 3.6 KB
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
# Directory containing the Makefile.
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export PATH := $(GOBIN):$(PATH)
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
# Directories containing independent Go modules.
MODULE_DIRS = benchmark acronis-db-bench acronis-restrelay-bench
GO_INSTALLABLE_DIRS = acronis-db-bench
# Directories that we want to test and track coverage for.
TEST_DIRS = benchmark acronis-restrelay-bench acronis-db-bench logger
include acronis-restrelay-bench/restrelay-bench.Makefile
.PHONY: all
all: lint cover
.PHONY: lint
lint: golangci-lint
.PHONY: golangci-lint
golangci-lint:
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] golangci-lint: $(mod)" && \
golangci-lint run --path-prefix $(mod)) &&) true
.PHONY: tidy
tidy:
@$(foreach dir,$(MODULE_DIRS), \
(cd $(dir) && go mod tidy) &&) true
.PHONY: test
test:
@$(foreach dir,$(TEST_DIRS),(cd $(dir) && go test -race ./...) &&) true
.PHONY: cover
cover:
@mkdir -p coverage
@echo "Running coverage tests..."
@$(foreach dir,$(TEST_DIRS), ( \
cd $(dir) && \
go test -race -coverprofile=../coverage/$(dir).out -coverpkg=./... ./... && \
go tool cover -html=../coverage/$(dir).out -o ../coverage/$(dir).html) &&) true
@echo "Generating total coverage..."
@echo "mode: atomic" > coverage/total.out
@$(foreach dir,$(TEST_DIRS), \
tail -n +2 coverage/$(dir).out >> coverage/total.out &&) true
@go tool cover -html=coverage/total.out -o coverage/total.html
@echo "Generating coverage summary table..."
@echo "+-------------------------+----------+------------------------------------------+"
@echo "| Directory | Coverage | HTML Report |"
@echo "+-------------------------+----------+------------------------------------------+"
@$(foreach dir,$(TEST_DIRS), \
printf "| %-23s | %-8s | %-40s |\n" "$(dir)" "$$(go tool cover -func=coverage/$(dir).out | grep 'total:' | awk '{print $$3}')" "coverage/$(dir).html" &&) true
@echo "+-------------------------+----------+------------------------------------------+"
@printf "| %-23s | %-8s | %-40s |\n" "Total" "$$(go tool cover -func=coverage/total.out | grep 'total:' | awk '{print $$3}')" "coverage/total.html"
@echo "+-------------------------+----------+------------------------------------------+"
.PHONY: install
install: go-install sign-binaries
.PHONY: go-install
go-install:
@$(foreach dir,$(GO_INSTALLABLE_DIRS), ( \
cd $(dir) && \
go install -v -ldflags "-X main.Version=`cat VERSION`" ./... \
&& echo `go list -f '{{.Module.Path}}'`-v`cat VERSION` has been installed to `go list -f '{{.Target}}'`) &&) true
# Sign binaries on MacOS to prevent them from being killed by Gatekeeper
.PHONY: sign-binaries
sign-binaries:
@if [ "$$(uname)" = "Darwin" ]; then \
echo "Signing binaries for MacOS..."; \
$(foreach dir,$(GO_INSTALLABLE_DIRS), \
binary_path=$$(cd $(dir) && go list -f '{{.Target}}'); \
if [ -f "$$binary_path" ]; then \
echo "Signing $$binary_path"; \
codesign --force --sign - "$$binary_path" || echo "Warning: Failed to sign $$binary_path"; \
fi;) \
else \
echo "Not on MacOS, skipping binary signing"; \
fi
.PHONY: install-acronis-db-bench
install-acronis-db-bench:
@$(MAKE) GO_INSTALLABLE_DIRS=acronis-db-bench install
.PHONY: build-acronis-restrelay-bench
build-acronis-restrelay-bench: build-restrelay-bench
.PHONY: up-version
up-version:
@$(foreach dir,$(MODULE_DIRS), ( \
cd $(dir) ; \
echo "Up version for `basename $(dir)` to `cat VERSION`" ; \
git tag "`basename $(dir)`/v`cat VERSION`" ; \
git push origin "`basename $(dir)`/v`cat VERSION`") ; \
) true