-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
93 lines (68 loc) · 2.09 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
# NOTE(timonwong): From now on, this Makefile only works on go1.10+
GO := go
REPO_PATH ?= github.com/imperfectgo/common
TESTARGS ?= -v -race
COVERARGS ?= -covermode=atomic
TEST ?= $(shell go list ./... | grep -v '/vendor/')
TESTPKGS ?= $(shell go list ./... | grep -v '/cmd/')
GOFMT_FILES ?= $(shell find . -name '*.go' | grep -v vendor | xargs)
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
DEP := $(FIRST_GOPATH)/bin/dep
OVERALLS := $(FIRST_GOPATH)/bin/overalls
GOIMPORTS := $(FIRST_GOPATH)/bin/goimports
GOMETALINTER := $(FIRST_GOPATH)/bin/gometalinter
export REPO_PATH
_comma := ,
_space :=
_space +=
.PHONY: all
all: format test
$(DEP):
@echo ">> installing golang dep tool"
@$(GO) get -u "github.com/golang/dep/cmd/dep"
$(OVERALLS):
@echo ">> installing overalls tool"
@$(GO) get -u "github.com/go-playground/overalls"
$(GOIMPORTS):
@echo ">> installing goimports tool"
@$(GO) get -u "go get golang.org/x/tools/cmd/goimports"
$(GOMETALINTER):
@echo ">> installing gometalinter"
@$(GO) get -u "github.com/alecthomas/gometalinter"
@$(GOMETALINTER) --install --update
.PHONY: dep
dep: $(DEP)
@dep ensure
.PHONY: test
test:
@echo ">> running tests"
@$(GO) test $(TEST) $(TESTARGS)
.PHONY: cover
cover: $(OVERALLS)
@echo ">> running test coverage"
@rm -f coverage.txt
@$(OVERALLS) -project=$(REPO_PATH) $(COVERARGS) -- $(TESTARGS) && \
mv overalls.coverprofile coverage.txt
.PHONY: lint
lint: $(GOMETALINTER)
@echo ">> linting code"
@$(GOMETALINTER) --vendor --disable-all \
--enable=varcheck \
--enable=gosimple \
--enable=misspell \
--enable=vet \
--enable=vetshadow \
--enable=golint \
--deadline=10m \
./...
.PHONY: fmtcheck
fmtcheck: $(GOMETALINTER)
@echo ">> checking code style"
@$(GOMETALINTER) --vendor --disable-all \
--enable=gofmt \
--enable=goimports \
./...
.PHONY: format
format: $(GOIMPORTS)
@echo ">> formatting code"
@$(GOIMPORTS) -local "$(REPO_PATH)" -w $(GOFMT_FILES)