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
.PHONY: build realize dep spec protobuf critic test test.rbac qa qa.test qa.vet codegen
PKG = "github.com/$(shell cat .project)"
GO = go
GOGET = $(GO) get -u
BASEPKGS = rbac auth crm sam
########################################################################################################################
# Tool bins
DEP = $(GOPATH)/bin/dep
SPEC = $(GOPATH)/bin/spec
PROTOC = $(GOPATH)/bin/protoc-gen-go
REALIZE = ${GOPATH}/bin/realize
GOTEST = ${GOPATH}/bin/gotest
GOCRITIC = ${GOPATH}/bin/gocritic
MOCKGEN = ${GOPATH}/bin/mockgen
build:
docker build --no-cache --rm -t $(shell cat .project) .
########################################################################################################################
# Development
realize: $(REALIZE)
$(REALIZE) start
dep.update: $(DEP)
$(DEP) ensure -update -v
dep: $(DEP)
$(DEP) ensure -v
codegen: $(SPEC)
@PATH=${PATH}:${GOPATH}/bin ./codegen.sh
protobuf: $(PROTOC)
# @todo this needs work (it hangs and outputs nothing)
$(PROTOC) --go_out=plugins=grpc:. -I. sam/chat/*.proto
########################################################################################################################
# QA
critic: $(GOCRITIC)
PATH=${PATH}:${GOPATH}/bin $(GOCRITIC) check-project .
test: $(GOTEST)
$(GOTEST) -covermode count -coverprofile .cover.out -v ./...
$(GO) tool cover -func=.cover.out
test.sam: $(GOTEST)
$(GOTEST) -covermode count -coverprofile .cover.out -v ./sam/repository/...
$(GO) tool cover -func=.cover.out | grep --color "^\|[^0-9]0.0%"
test.crm: $(GOTEST)
$(GOTEST) -covermode count -coverprofile .cover.out -v ./crm/repository/...
$(GO) tool cover -func=.cover.out | grep --color "^\|[^0-9]0.0%"
test.rbac: $(GOTEST)
$(GOTEST) -covermode count -coverprofile .cover.out -v ./rbac/...
$(GO) tool cover -func=.cover.out | grep --color "^\|[^0-9]0.0%"
vet:
$(GO) vet `cd ${GOPATH}/src/; find $(PKG) -type f -name '*.go' -and -not -path '*vendor*'|xargs -n1 dirname|uniq`
qa: vet critic test
mocks: $(GOMOCK)
# See https://github.com/golang/mock for details
$(MOCKGEN) -source sam/service/service_test.go -destination sam/service/service_mock_test.go -package service
########################################################################################################################
# Toolset
$(GOTEST):
$(GOGET) github.com/rakyll/gotest
$(REALIZE):
$(GOGET) github.com/tockins/realize
$(SPEC):
$(GOGET) github.com/titpetric/spec/cmd/spec
$(PROTOC):
$(GOGET) github.com/golang/protobuf/protoc-gen-go
$(GOCRITIC):
$(GOGET) github.com/go-critic/go-critic/...
$(DEP):
$(GOGET) github.com/tools/godep
$(MOCKGEN):
$(GOGET) github.com/golang/mock/gomock
$(GOGET) github.com/golang/mock/mockgen
clean:
rm -f $(SPEC) $(PROTOC) $(REALIZE) $(GOCRITIC) $(GOTEST)