-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
56 lines (42 loc) · 1.94 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
help: ## Display this help screen
@printf "Help doc:\nUsage: make [command]\n"
@printf "[command]\n"
@grep -h -E '^([a-zA-Z_-]|\%)+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: init
init:
@go install golang.org/x/tools/cmd/goimports@latest
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@go install mvdan.cc/sh/v3/cmd/shfmt@latest
@apt install shellcheck
.PHONY: test bench
test: ## Run unittests
@go clean -testcache
@go test -short -race `go list ./...`
bench: ## Run benchmark of all
@go test ./... -v -bench=.
.PHONY: fmt_proto fmt_shell fmt_go
fmt: fmt_shell fmt_go ## file format
fmt_shell: ## format .sh files
@find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 4 -ci -bn
fmt_go: ## format .go files
@find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -s -w
@find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w -local "github.com/danielhookx/eventbus"
.PHONY: checkgofmt linter linter_test
check: checkgofmt linter ## check format and linter
checkgofmt: ## get all go files and run go fmt on them
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s ;\
exit 1; \
fi;
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w ;\
exit 1; \
fi;
linter: ## Use gometalinter check code, ignore some unserious warning
@./golinter.sh "filter"
@find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck
linter_test: ## Use gometalinter check code, for local test
@./golinter.sh "test" "${p}"
@find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck