-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
76 lines (60 loc) · 1.95 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
N=1
PPROF_NAME=_
PPROF_PORT=_
# updates in 'test-coverage-badge' block
_COVERAGE_RAW=_
_COVERAGE_VAR=_
_TEST_RESULT_PATH=./test/result
_CHECK_ERROR=if [ $$? != 0 ]; then exit 1; fi
_GO_TEST_LIST=\
go list ./... | \
grep -v /examples/ | \
grep -v /cmd/
.PHONY: default clean \
test-run test-coverage test-coverage-view \
git-status git-push
default: test-run
clean:
make -C ./cmd clean
make -C ./examples clean
### TEST
# example run: make test-run N=10
# for i in {1..100}; do echo $i; go test -race -shuffle=on -count=1 ./...; done;
test-run: clean
go vet ./...;
$(_CHECK_ERROR);
d=$$(date +%s); \
for i in {1..$(N)}; do \
echo $$i; \
# recommended to add an option -shuffle=on if [go version >= 1.17]; \
go test -race -cover -count=1 ./...; \
$(_CHECK_ERROR); \
done; \
echo "Build took $$(($$(date +%s)-d)) seconds";
### TEST COVERAGE
test-coverage: clean
make test-coverage -C cmd/hidden_lake/
go test -coverpkg=./... -coverprofile=$(_TEST_RESULT_PATH)/coverage.out -count=1 `$(_GO_TEST_LIST)`
$(_CHECK_ERROR)
test-coverage-view:
make test-coverage-view -C cmd/hidden_lake/
go tool cover -html=$(_TEST_RESULT_PATH)/coverage.out
test-coverage-badge:
make test-coverage-badge -C cmd/hidden_lake/
$(eval _COVERAGE_RAW=go tool cover -func=$(_TEST_RESULT_PATH)/coverage.out | grep total: | grep -Eo '[0-9]+\.[0-9]+')
$(eval _COVERAGE_VAR := $(shell echo "`${_COVERAGE_RAW}`/1" | bc))
if [ $(_COVERAGE_VAR) -lt 60 ]; then \
curl "https://img.shields.io/badge/coverage-$(_COVERAGE_VAR)%25-crimson" > $(_TEST_RESULT_PATH)/badge.svg; \
elif [ $(_COVERAGE_VAR) -gt 80 ]; then \
curl "https://img.shields.io/badge/coverage-$(_COVERAGE_VAR)%25-green" > $(_TEST_RESULT_PATH)/badge.svg; \
else \
curl "https://img.shields.io/badge/coverage-$(_COVERAGE_VAR)%25-darkorange" > $(_TEST_RESULT_PATH)/badge.svg; \
fi
### GIT
git-status: test-coverage test-coverage-badge
go fmt ./...
git add .
git status
git-push:
git commit -m "update"
git push