-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (81 loc) · 3.34 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
# Init vars.
MAKEFILE := $(lastword $(MAKEFILE_LIST))
BASENAME := $(shell basename "$(PWD)")
.PHONY: help
all: help
help: Makefile
@echo
@echo " Commands:"
@echo
@sed -n 's/^##//p' $< | sed -e 's/^/ /' | sort
@echo
## test Run gofmt, golint, staticcheck, go vet and go test.
test:
$(eval FMT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs gofmt -l | wc -l | tr -d ' '))
@if [ "$(FMT)" != "0" ]; then \
echo "some files are not formatted, run 'make fmt'"; \
exit 1; \
fi
$(eval LINT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs golint | wc -l | tr -d ' '))
@if [ "$(LINT)" != "0" ]; then \
echo "some files have linting errors, run 'make lint'"; \
exit 1; \
fi
$(eval STATICCHECK=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs staticcheck | wc -l | tr -d ' '))
@if [ "$(STATICCHECK)" != "0" ]; then \
echo "some files have staticcheck errors, run 'make staticcheck'"; \
exit 1; \
fi
$(eval GOVET=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor' | xargs -L1 dirname | sort | uniq | xargs go vet 2>&1 | wc -l | tr -d ' '))
@if [ "$(GOVET)" != "0" ]; then \
echo "some files have vetting errors, run 'make vet'"; \
exit 1; \
fi
@$(MAKE) -f $(MAKEFILE) test-go
## test-go Run go test
test-go:
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs go test -v -race
## test-benchmarks Run go benchmarks
test-benchmarks:
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs go test -benchmem -bench
## test-ui Launch test UI
test-ui:
$(eval GOCONVEY_PATH=$(shell which goconvey))
@if [ -z "$(GOCONVEY_PATH)" ]; then \
GO111MODULE=off go get github.com/smartystreets/goconvey; \
fi
goconvey -port 8088 -excludedDirs vendor,node_modules,assets
## test-clean Clean test cache
test-clean:
@go clean -testcache
## test-tools Install test tools
test-tools:
@# golint is deprecated and frozen.
$(eval GOLINT_PATH=$(shell which golint))
@if [ -z "$(GOLINT_PATH)" ]; then \
GO111MODULE=off go get golang.org/x/lint/golint; \
fi
$(eval STATICCHECK_PATH=$(shell which staticcheck))
@if [ -z "$(STATICCHECK_PATH)" ]; then \
go install honnef.co/go/tools/cmd/[email protected]; \
fi
## fmt Run formating
fmt:
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs gofmt -l
## lint Run linting
lint:
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs golint
## staticcheck Run staticcheck
staticcheck:
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs staticcheck
## vet Run vetting
vet:
@find . -type f -name '*.go' | grep -v -E '^./vendor' | xargs -L1 dirname | sort | uniq | xargs go vet 2>&1
## release Release a version
release:
@if [ "$(shell echo \$${GIT_TAG:0:1})" != "v" ]; then \
echo "invalid GIT_TAG (${GIT_TAG}). Try something like 'make release GIT_TAG=v1.0.0'"; \
exit 1; \
fi
git tag -a $(GIT_TAG) -m "$(GIT_TAG)"
git push --follow-tags