-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
114 lines (88 loc) · 2.73 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
# Small make tasks for go
.PHONY: test
include .env
export
# More tools:
# https://github.com/kisielk/godepgraph
USER=geolffreym
PACKAGE=aggregator
VERSION=0.1.0
BINARY=main
BINARY_WIN=${BINARY}-win
BINARY_OSX=${BINARY}-darwin
BINARY_LINUX=${BINARY}-linux
ARCH_64=amd64
ARCH_32=386
LINUX_64=${BINARY_LINUX}-${ARCH_64}
LINUX_32=${BINARY_LINUX}-${ARCH_32}
WIN_64=${BINARY_WIN}-${ARCH_64}
WIN_32=${BINARY_WIN}-${ARCH_32}
OSX_64=${BINARY_LINUX}-${ARCH_64}
# -count 1 idiomatic no cached testing
# -race test race condition for routines
# @ = dont echo the output
test:
@go test -v ./... -count 1 -race -covermode=atomic
@echo "[OK] test finished"
# Could be compared using
# make benchmark > a.old
# make benchmark > b.new
# benchcmp a.old b.new
benchmark:
@go test ./... -bench=. -benchtime 100000x -count 5
@echo "[OK] benchmark finished"
# View standard output profiling:
# go tool pprof -top cpu.prof
# For memory profiling type use:
# inuse_space Display in-use memory size
# inuse_objects Display in-use object counts
# alloc_space Display allocated memory size
# alloc_objects Display allocated object counts
# eg. go tool pprof --alloc_space -top prof.mem
# For fancy visualization:
# Could use Graphviz (https://graphviz.org/download/)
# eg. go tool pprof -web bin/main-linux-amd64 cpu.prof
profiling:
@go test -bench=. -benchtime 100000x -run=^$ -cpuprofile=cpu.prof -memprofile=prof.mem
@echo "[OK] profiling finished"
coverage:
@go test -v ./... -race -covermode=atomic -coverprofile coverage ./...
@echo "[OK] coverage finished"
coverage-export: coverage
@go tool cover -html=coverage
@echo "[OK] code test coverage finished"
build:
@go build -v ./...
code-fmt:
@go fmt ./...
@echo "[OK] code format finished"
code-check:
@go vet -v ./...
@echo "[OK] code check finished"
clean:
@go clean --cache ./...
@rm -f mem.prof
@rm -f prof.mem
@rm -rf bin
@echo "[OK] cleaned"
compile-win:
@GOOS=windows GOARCH=amd64 go build -o bin/${WIN_64} ${INPUT}
@GOOS=windows GOARCH=386 go build -o bin/${WIN_32} ${INPUT}
#Go1.15 deprecates 32-bit macOS builds
# go build -x to show compilation details
#GOOS=darwin GOARCH=386 go build -o bin/main-mac-386 main.go
compile-mac:
@GOOS=darwin GOARCH=amd64 go build -o bin/${OSX_64} ${INPUT}
compile-linux:
@GOOS=linux GOARCH=amd64 go build -o bin/${LINUX_64} ${INPUT}
@GOOS=linux GOARCH=386 go build -o bin/${LINUX_32} ${INPUT}
compile: compile-linux compile-win compile-mac
@echo "[OK] Compiling for every OS and Platform"
run:
@go run main.go $(filter-out $@,$(MAKECMDGOALS))
load-test:
@k6 run scripts/load.js
update-pkg-cache:
GOPROXY=https://proxy.golang.org GO111MODULE=on \
go get github.com/${USER}/${PACKAGE}@v${VERSION}
all: build test check-test-coverage code-check compile