-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
90 lines (73 loc) · 2.08 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
NAME := deotry
PKG_LIST := $(shell go list ./... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
GREEN := \033[0;32m
NC := \033[0;m
all: clean dep fmt lint vet goreport setup build test race coverage
build:
@echo "${GREEN}Deotry build...${NC}"
@mkdir -p build
@go build -o build/${NAME}
# Run gofmt
fmt:
@echo "${GREEN}Fix by golang format${NC}"
@gofmt -l -w ${GO_FILES}
# Check gofmt
fmtcheck:
@echo "${GREEN}Check gofmt${NC}"
@gofmt -l -s ${GO_FILES} | read; \
if [ $$? == 0 ]; \
then echo "gofmt check failed for:"; \
gofmt -l -s ${GO_FILES}; \
exit 1; \
fi
# Lint check
lint:
@echo "${GREEN}Start golint${NC}"
@golint -set_exit_status ${PKG_LIST}
vet:
@go vet ./...
# Check goreportcard-cli
# (require) 1. https://github.com/alecthomas/gometalinter
# @curl -L https://git.io/vp6lP | sh # Linux
# @brew tap alecthomas/homebrew-tap & brew install gometalinter # MacOS
# 2. https://github.com/gojp/goreportcard
# @go get -u github.com/gojp/goreportcard/cmd/goreportcard-cli
goreport:
@echo "${GREEN}Run goreportcard-cli${NC}"
@goreportcard-cli
# Infra init
setup:
@echo "${GREEN}Run infrastructure${NC}"
@docker-compose up -d
@printf "${GREEN}Mysql running"
@bash ./tools/mysql_check.sh go_mysql root imdeo
# Run unittests
test:
@echo "${GREEN}Start test${NC}"
@go test -short ${PKG_LIST}
# Run data race detector
race:
@echo "${GREEN}Run data race detector${NC}"
@go test -race -short ${PKG_LIST}
# Make code coverage report
# (require) https://github.com/axw/gocov
# @go get -u github.com/axw/gocov
coverage:
@echo "${GREEN}Check code coverage${NC}"
@gocov test ${PKG_LIST} | gocov report
coverage-report:
@echo "${GREEN}Make code coverage report${NC}"
@mkdir -p coverage
@gocov test ${PKG_LIST} | gocov-html > coverage/report.html
# Dependency installation
dep:
@echo "${GREEN}Install dependency${NC}"
@dep ensure
clean:
@echo "${GREEN}Clean project${NC}"
@docker-compose down
@rm -rf vendor
@rm -rf build
@go clean
.PHONY: all fmt fmtcheck lint vet goreport setup build test race coverage dep clean