-
Notifications
You must be signed in to change notification settings - Fork 67
/
Makefile
294 lines (250 loc) · 10.4 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
PKGS = $(shell glide novendor | grep -v "workspace/...")
PKG_FILES = benchmarks codegen examples runtime test
PWD = $(shell pwd)
COVER_PKGS = $(shell glide novendor | grep -v "test/..." | \
grep -v "main/..." | grep -v "benchmarks/..." | \
grep -v "workspace/..." | awk -vORS=, '{ print $1 }' | sed 's/,$$/\n/')
GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' -o -path './workspace' ')' -prune -o -name '*.go' -print | cut -b3-)
FILTER_LINT := grep -v -e "vendor/" -e "third_party/" -e "gen-code/" -e "config/" -e "codegen/templates/" -e "codegen/template_bundle/"
ENV_CONFIG := $(shell find ./config -name 'production.json' -o -name 'production.yaml')
TEST_ENV_CONFIG := $(shell find ./config -name 'test.json' -o -name 'test.yaml')
# list all executables
PROGS = benchmarks/benchserver/benchserver \
benchmarks/runner/runner
EXAMPLE_BASE_DIR = examples/example-gateway/
EXAMPLE_SERVICES_DIR = $(EXAMPLE_BASE_DIR)build/services/
EXAMPLE_SERVICES = $(sort $(dir $(wildcard $(EXAMPLE_SERVICES_DIR)*/)))
GOIMPORTS = "$(PWD)/vendor/golang.org/x/tools/cmd/goimports"
GOBINDATA = "$(PWD)/vendor/github.com/jteeuwen/go-bindata/go-bindata"
GOMOCK = "$(PWD)/vendor/github.com/golang/mock/mockgen"
GOGOSLICK = "$(PWD)/vendor/github.com/gogo/protobuf/protoc-gen-gogoslick"
YARPCGO = "$(PWD)/vendor/go.uber.org/yarpc/encoding/protobuf/protoc-gen-yarpc-go"
.PHONY: install
install:
@echo "Mounting git pre-push hook"
cp .git-pre-push-hook .git/hooks/pre-push
@echo "Installing Glide and locked dependencies..."
pip install --user yq
glide --version || go get -u -f github.com/Masterminds/glide
glide install
go build -o $(GOIMPORTS)/goimports ./vendor/golang.org/x/tools/cmd/goimports/
go build -o $(GOBINDATA)/go-bindata ./vendor/github.com/jteeuwen/go-bindata/go-bindata/
go build -o $(GOMOCK)/mockgen ./vendor/github.com/golang/mock/mockgen/
go build -o $(GOGOSLICK)/protoc-gen-gogoslick ./vendor/github.com/gogo/protobuf/protoc-gen-gogoslick/
go build -o $(YARPCGO)/protoc-gen-yarpc-go ./vendor/go.uber.org/yarpc/encoding/protobuf/protoc-gen-yarpc-go/
.PHONY: check-licence
check-licence:
@echo "Checking uber-licence..."
@ls ./node_modules/.bin/uber-licence >/dev/null 2>&1 || npm i uber-licence
@./node_modules/.bin/uber-licence --dry --file '*.go' --dir '!workspace' --dir '!vendor' --dir '!examples' --dir '!.tmp_gen' --dir '!template_bundle'
.PHONY: fix-licence
fix-licence:
@ls ./node_modules/.bin/uber-licence >/dev/null 2>&1 || npm i uber-licence
./node_modules/.bin/uber-licence --file '*.go' --dir '!vendor' --dir '!workspace' --dir '!examples' --dir '!.tmp_gen' --dir '!template_bundle'
.PHONY: eclint-check
eclint-check:
@echo "Checking eclint..."
@ls ./node_modules/.bin/eclint >/dev/null 2>&1 || npm i [email protected]
@./node_modules/.bin/eclint check "./{codegen,examples}/**/*.{json,tmpl}"
.PHONY: eclint-fix
eclint-fix:
@ls ./node_modules/.bin/eclint >/dev/null 2>&1 || npm i [email protected]
./node_modules/.bin/eclint fix "./{codegen,examples}/**/*.{json,tmpl}"
.PHONY: spell-check
spell-check:
@go get github.com/client9/misspell/cmd/misspell
@misspell $(PKG_FILES)
.PHONY: spell-fix
spell-fix:
@go get github.com/client9/misspell/cmd/misspell
@misspell -w $(PKG_FILES)
.PHONY: cyclo-check
cyclo-check:
@go get github.com/fzipp/gocyclo
@gocyclo -over 15 $(filter-out examples ,$(PKG_FILES))
.PHONY: lint
lint: check-licence eclint-check
@rm -f lint.log
@echo "Checking formatting..."
@$(GOIMPORTS)/goimports -d $(PKG_FILES) 2>&1 | $(FILTER_LINT) | tee -a lint.log
@echo "Installing test dependencies for vet..."
@go test -i $(PKGS)
@echo "Checking printf statements..."
@git grep -E 'Fprintf\(os.Std(err|out)' | $(FILTER_LINT) | tee -a lint.log
@echo "Checking vet..."
@$(foreach dir,$(PKG_FILES),go vet $(VET_RULES) ./$(dir)/... 2>&1 | $(FILTER_LINT) | tee -a lint.log;)
@echo "Checking lint..."
@go get golang.org/x/lint/golint
@$(foreach dir,$(PKGS),golint $(dir) 2>&1 | $(FILTER_LINT) | tee -a lint.log;)
@echo "Checking errcheck..."
@go run vendor/github.com/kisielk/errcheck/main.go $(PKGS) 2>&1 | $(FILTER_LINT) | tee -a lint.log
@echo "Checking staticcheck..."
@go build -o vendor/honnef.co/go/tools/cmd/staticcheck/staticcheck vendor/honnef.co/go/tools/cmd/staticcheck/staticcheck.go
@./vendor/honnef.co/go/tools/cmd/staticcheck/staticcheck $(PKGS) 2>&1 | $(FILTER_LINT) | tee -a lint.log
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e vendor -e Makefile | $(FILTER_LINT) | tee -a lint.log
@[ ! -s lint.log ]
# .PHONY: verify_deps
# verify_deps:
# @rm -f deps.log
# @echo "Verifying dependency conflicts"
# @glide -q update 2>&1 | tee -a deps.log
# @[ ! -s deps.log ]
.PHONY: generate
generate:
@ls ./node_modules/.bin/uber-licence >/dev/null 2>&1 || npm i uber-licence
@chmod 644 ./codegen/templates/*.tmpl
@chmod 644 $(ENV_CONFIG)
@$(GOBINDATA)/go-bindata -pkg config -nocompress -modtime 1 -prefix config -o config/production.gen.go $(ENV_CONFIG)
@./node_modules/.bin/uber-licence --file "production.gen.go" --dir "config" > /dev/null
@$(GOBINDATA)/go-bindata -pkg templates -nocompress -modtime 1 -prefix codegen/templates -o codegen/template_bundle/template_files.go codegen/templates/...
@$(GOIMPORTS)/goimports -w -e "codegen/template_bundle/template_files.go"
@PATH=$(GOGOSLICK):$(YARPCGO):$(GOIMPORTS):$(GOMOCK):$(PATH) bash ./scripts/generate.sh
.PHONY: check-generate
check-generate:
@rm -f git-status.log
rm -rf ./examples/example-gateway/build
rm -rf ./examples/selective-gateway/build
make generate
# TODO: @rpatali enable after migrating to Github Actions
# coden-gen currently generates slightly different on Github vs. Mac
# mock-client imports have `zanzibar` alias on local where as `runtime` alias on GH
# so the git-status is not clean.
#git status --porcelain > git-status.log
#@[ ! -s git-status.log ] || ( cat git-status.log ; git --no-pager diff ; [ ! -s git-status.log ] );
.PHONY: test-all
test-all:
$(MAKE) jenkins
$(MAKE) install
$(MAKE) cover
$(MAKE) fast-bench
$(MAKE) bins
$(MAKE) install-wrk
$(MAKE) test-benchmark-runner
.PHONY: test-benchmark-runner
test-benchmark-runner:
PATH=$$PATH:$$PWD/vendor/wrk ./benchmarks/runner/runner -loadtest
.PHONY: install-wrk
install-wrk:
ls ./vendor/wrk/wrk 2>/dev/null || git clone \
https://github.com/wg/wrk.git ./vendor/wrk
cd ./vendor/wrk ; (ls ./wrk 2>/dev/null || make >install_wrk.log)
.PHONY: test
test: generate lint
@make test-only
.PHONY: test-only
test-only:
@rm -f ./test/.cached_binary_test_info.json
@echo "Running all tests..."
@ZANZIBAR_CACHE=1 go test ./test/health_test.go # preload the binary cache
@PATH=$(PATH):$(GOIMPORTS) ZANZIBAR_CACHE=1 go test -race ./codegen/... ./runtime/... | grep -v '\[no test files\]'
@PATH=$(PATH):$(GOIMPORTS) ZANZIBAR_CACHE=1 go test -race $$(go list ./examples/example-gateway/... | grep -v build) | \
grep -v '\[no test files\]'
@PATH=$(PATH):$(GOIMPORTS) ZANZIBAR_CACHE=1 go test -race $$(go list ./examples/selective-gateway/... | grep -v build) | \
grep -v '\[no test files\]'
@PATH=$(PATH):$(GOIMPORTS) ZANZIBAR_CACHE=1 go test ./test/... ./examples/example-gateway/build/... ./examples/selective-gateway/build/... | \
grep -v '\[no test files\]'
@rm -f ./test/.cached_binary_test_info.json
@echo "<coverage />" > ./coverage/cobertura-coverage.xml
.PHONY: fast-bench
fast-bench:
@rm -f bench.log bench-fail.log
time -p sh -c "go test -run _NONE_ -bench . -benchmem -benchtime 1s -cpu 1 ./test/... | grep -v '^ok ' | grep -v '\[no test files\]' | grep -v '^PASS' | tee -a bench.log"
@cat bench.log | grep "FAIL" | tee -a bench-fail.log
@[ ! -s bench-fail.log ]
.PHONY: bench
bench:
time -p sh -c "go test -run _NONE_ -bench . -benchmem -benchtime 7s -cpu 2 ./test/... | grep -v '^ok ' | grep -v '\[no test files\]' | grep -v '^PASS'"
$(PROGS): $(GO_FILES)
@echo Building $@
go build -o $@ $(dir ./$@)
# These dirs are generated by `make generate`, if `make generate` is ran after any $(GO_FILES) is modified,
# these dirs will have a later timestamp than the modified $(GO_FILES), therefore make believes they are up to date.
# These needs to be phony despite they are actual files, as the target is not generating them but the binaries instead.
.PHONY: $(EXAMPLE_SERVICES)
$(EXAMPLE_SERVICES): $(GO_FILES)
@echo Building $@
go build -o "$@../../../bin/$(shell basename $@)" ./$@main
run-%: $(EXAMPLE_SERVICES_DIR)%/
cd "$(EXAMPLE_BASE_DIR)"; \
UBER_ENVIRONMENT=production \
CONFIG_DIR=./config \
./bin/$* --config=$(TEST_ENV_CONFIG)
.PHONY: bins
bins: generate $(PROGS) $(EXAMPLE_SERVICES)
.PHONY: run
run: run-example-gateway
.PHONY: go-docs
go-docs:
godoc -http=:6060
.PHONY: clean-easyjson
clean-easyjson:
find . -name "*.bak" -delete
find . -name "easyjson-bootstrap*.go" -delete
.PHONY: kill-dead-benchmarks
kill-dead-benchmarks:
ps aux | grep gocode | awk '{ print $$2 }' | xargs kill
.PHONY: clean-cover
clean-cover:
@rm -f ./coverage/cover.out
@rm -f ./coverage/cover-*.out
@rm -f ./coverage/index.html
.PHONY: cover
cover: clean-cover
@PATH=$(PATH):$(GOIMPORTS) bash ./scripts/cover.sh
.PHONY: generate-istanbul-json
generate-istanbul-json:
@go get github.com/axw/gocov/gocov
@gocov convert ./coverage/cover.out > coverage/gocov.json
@node ./scripts/gocov-to-istanbul-coverage.js ./coverage/gocov.json \
> coverage/istanbul.json
.PHONY: view-istanbul
view-istanbul: generate-istanbul-json
./node_modules/.bin/istanbul report --root ./coverage \
--include "**/istanbul.json" html
@if [ $$(which xdg-open) ]; then \
xdg-open coverage/index.html; \
else \
open coverage/index.html; \
fi
.PHONY: view-gocov
view-gocov:
@go get github.com/axw/gocov/gocov
@go get -u gopkg.in/matm/v1/gocov-html
@gocov convert ./coverage/cover.out > coverage/gocov.json
@cat coverage/gocov.json | gocov-html > ./coverage/index.html
@if [ $$(which xdg-open) ]; then \
xdg-open coverage/index.html; \
else \
open coverage/index.html; \
fi
.PHONY: view-cover
view-cover:
go tool cover -html=./coverage/cover.out
.PHONY: clean-vendor
clean-vendor:
rm -rf ./vendor
.PHONY: clean
clean: clean-easyjson clean-cover clean-vendor
go clean
rm -f $(PROGS)
.PHONY: tag-build
tag-build:
date +%Y-%m-%d-%H-%M-%S >VERSION
git add VERSION
cat VERSION | xargs -I{} git commit -m "build: {}"
cat VERSION | xargs -I{} git tag -m "build: {}" "build-{}"
.PHONY: jenkins-install
jenkins-install:
@rm -rf ./vendor/
make install
.PHONY: jenkins-test
jenkins-test:
make check-generate
make lint
make test-only
.PHONY: jenkins
jenkins:
$(MAKE) jenkins-install
$(MAKE) jenkins-test