-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
180 lines (137 loc) · 3.71 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
GO ?= go
module := $(shell $(GO) list -m)
PROJECT ?= $(notdir $(module))
DOCKER_IMAGE ?= go-ve/adan-bot
goFiles := $(shell find . -iname "*.go" -type f | grep -v "/_" | grep -v "^\./vendor")
goFilesSrc := $(shell $(GO) list -f '{{ range .GoFiles }}{{ $$.Dir }}/{{ . }} {{ end }}' ./...)
goFilesTest := $(shell $(GO) list -f "{{ range .TestGoFiles }}{{ $$.Dir }}/{{ . }} {{ end }}{{ range .XTestGoFiles }}{{ $$.Dir }}/{{ . }} {{ end }}" ./...)
.PHONY: all
all: build
.PHONY: build
build:
$(GO) build -ldflags="-s -w" -trimpath -o ./dist/ ./...
.PHONY: build-docker
build-docker:
docker build -t $(DOCKER_IMAGE) .
.PHONY: clean
clean:
rm -rf dist/
# Development
BENCHMARK_COUNT ?= 1
BENCHMARK_FILE ?= benchmarks-dev.txt
COVERAGE_FILE ?= coverage-dev.txt
CPUPROFILE ?= cpu.prof
ENV_FILE ?= .env
MEMPROFILE ?= mem.prof
TARGET_FUNC ?= .
TARGET_PKG ?= ./...
UID ?= $(shell id -u)
WATCH_TARGET ?= run
benchmarkWebFile := $(shell mktemp -u)-$(PROJECT).html
ifneq "$(notdir $(TARGET_PKG))" "..."
profileFlags := -cpuprofile "$(CPUPROFILE)" -memprofile "$(MEMPROFILE)"
endif
.PHONY: benchmark
benchmark:
$(GO) test -v -run none \
-bench "$(TARGET_FUNC)" -benchmem -count $(BENCHMARK_COUNT) \
$(profileFlags) \
"$(TARGET_PKG)" | tee "$(BENCHMARK_FILE)"
.PHONY: benchmark-check
benchmark-check: benchmarks.txt $(BENCHMARK_FILE)
benchstat "$<" "$(BENCHMARK_FILE)"
.PHONY: benchmark-web
benchmark-web: benchmarks.txt $(BENCHMARK_FILE)
benchstat -html "$<" "$(BENCHMARK_FILE)" > "$(benchmarkWebFile)"
xdg-open "$(benchmarkWebFile)"
define benchmarks_file
BENCHMARK_FILE="$(1)" $(MAKE) -s benchmark
endef
benchmarks.txt:
$(call benchmarks_file,$@)
benchmarks-%.txt:
$(call benchmarks_file,$@)
.PHONY: build-docker-debug
build-docker-debug:
docker build --target debug -t $(DOCKER_IMAGE):debug .
.PHONY: build-docker-dev
build-docker-dev:
docker build -f dev.Dockerfile -t $(DOCKER_IMAGE):dev .
.PHONY: ca
ca:
golangci-lint run
.PHONY: ca-fast
ca-fast:
golangci-lint run --fast
.PHONY: ci
ci: build test lint ca
.PHONY: ci-race
ci-race: build test-race lint ca
.PHONY: clean-dev
clean-dev: clean
rm -rf "$(CPUPROFILE)" "$(MEMPROFILE)" benchmarks-*.txt coverage-*.txt *.test
.PHONY: coverage
coverage: $(COVERAGE_FILE)
$(GO) tool cover -func "$(COVERAGE_FILE)"
.PHONY: coverage-check
coverage-check: coverage.txt $(COVERAGE_FILE)
#coverstat "$<" "$(COVERAGE_FILE)"
.PHONY: coverage-web
coverage-web: $(COVERAGE_FILE)
$(GO) tool cover -html "$(COVERAGE_FILE)"
define coverage_file
COVERAGE_FILE="$(1)" $(MAKE) -s test
endef
coverage.txt:
$(call coverage_file,$@)
coverage-%.txt:
$(call coverage_file,$@)
GODOC_PORT ?= 6060
.PHONY: doc
doc:
@echo "Go to http://localhost:$(GODOC_PORT)/pkg/$(module)/"
godoc -http ":$(GODOC_PORT)" -play
#GOPROXY=$(shell go env GOPROXY) pkgsite -http ":$(GODOC_PORT)" -cache -proxy
.PHONY: docker
docker:
docker run --rm -it --network host -u "$(UID)" --env-file "$(ENV_FILE)" \
-v "$$HOME/.cache:/.cache" -v "$$HOME/go/pkg:/go/pkg" -v .:/src \
$(DOCKER_IMAGE):dev
.PHONY: format
format:
gofmt -s -w -l $(goFiles)
.PHONY: fuzz
fuzz:
$(GO) test -v -run none -fuzz "$(TARGET_FUNC)" "$(TARGET_PKG)"
.PHONY: lint
lint:
gofmt -d -e -s $(goFiles)
.PHONY: run
run:
go run ./cmd/adan-bot/...
.PHONY: run-race
run-race:
go run -race ./cmd/adan-bot/...
.PHONY: test
test:
$(GO) test -v \
-run "$(TARGET_FUNC)" \
-coverprofile "$(COVERAGE_FILE)" \
$(profileFlags) \
"$(TARGET_PKG)"
.PHONY: test-race
test-race:
$(GO) test -v -race \
-run "$(TARGET_FUNC)" \
-coverprofile "$(COVERAGE_FILE)" \
$(profileFlags) \
"$(TARGET_PKG)"
.PHONY: watch
watch:
reflex -d "none" -r '\.go$$' -s -- $(MAKE) -s $(WATCH_TARGET)
.PHONY: air-init
air-init:
$(GOPATH)/bin/air init
.PHONY: air
air:
$(GOPATH)/bin/air