forked from shunfei/godruid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
114 lines (86 loc) · 2.58 KB
/
Makefile.common
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
105
106
107
108
109
110
111
112
113
114
# http://stackoverflow.com/questions/322936/common-gnu-makefile-directory-path#comment11704496_324782
TOP := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
GOFMT=gofmt -w -s
GOIMPORTS=goimports -w
GOSRCDIR=$(GOPATH)/src/$(PACKAGE)
GOPATHS=$(shell glide novendor | grep -v /main/)
GOFILES=$(shell git ls-files | grep '\.go$$')
MAINGO=$(wildcard main/*.go)
MAIN=$(patsubst main/%.go,%,$(MAINGO))
ifeq ($(GOTEST_TIMEOUT),)
GOTEST_TIMEOUT=60s
endif
ifeq ($(GOMETALINTER_OPTS),)
GOMETALINTER_OPTS=--enable-all --tests
endif
CODE_VERSION=$(TRAVIS_COMMIT)
ifeq ($(CODE_VERSION),)
CODE_VERSION=$(shell git rev-parse --short HEAD)-dev
endif
CODE_BUILD=$(TRAVIS_REPO_SLUG)\#$(TRAVIS_JOB_NUMBER)
ifeq ($(CODE_BUILD),\#)
CODE_BUILD=$(PACKAGE)\#$(shell whoami)
endif
LDIMPORT=$(PACKAGE)/vendor/github.com/remerge/go-service
LDFLAGS=-X $(LDIMPORT).CodeVersion=$(CODE_VERSION) -X $(LDIMPORT).CodeBuild=$(CODE_BUILD)@$(shell date -u +%FT%TZ)
.PHONY: build run clean lint lint-all test bench fmt dep init up gen proto-dep proto release deploy
all: build
build: fmt
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go test -v -i
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go build -v -i -ldflags "$(LDFLAGS)" $(GOPATHS)
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go build -v -i -ldflags "$(LDFLAGS)" $(MAINGO)
run: build
./$(MAIN)
clean:
cd $(GOSRCDIR) && \
go clean -i -x
rm -f $(MAIN)
lint: build
cd $(GOSRCDIR) && \
gometalinter --deadline=$(GOTEST_TIMEOUT) --fast $(GOMETALINTER_OPTS) $(GOPATHS)
lint-all: build
cd $(GOSRCDIR) && \
gometalinter --deadline=600s $(GOMETALINTER_OPTS) $(GOPATHS)
test: lint
cd $(GOSRCDIR) && \
go test -timeout $(GOTEST_TIMEOUT) -v $(GOPATHS)
bench: build
cd $(GOSRCDIR) && \
go test -bench=. -cpu 4 $(GOPATHS)
fmt:
$(GOFMT) $(GOFILES)
$(GOIMPORTS) $(GOFILES)
dep:
go get -u github.com/Masterminds/glide
go get -u github.com/alecthomas/gometalinter
gometalinter --install --update
cd $(GOSRCDIR) && glide install
init:
cd $(GOSRCDIR) && \
glide init
up:
cd $(GOSRCDIR) && \
glide update
gen:
cd $(GOSRCDIR) && \
go generate $(GOPATHS)
$(GOFMT) $(GOFILES)
$(GOIMPORTS) $(GOFILES)
PROTOS=$(wildcard *.proto */*.proto)
PBGOS=$(patsubst %.proto,%.pb.go,$(PROTOS))
proto-dep:
go get -u github.com/gogo/protobuf/protoc-gen-gogofaster
proto: proto-dep $(PBGOS)
$(PBGOS): %.pb.go: %.proto
protoc --gogofaster_out=. -I=.:$(TOP)/vendor:$(GOPATH)/src $<
release:
git push origin master master:production
deploy:
/bin/bash -c 'cd ../chef.new && knife ssh roles:$(PROJECT) sudo chef-client'
/bin/bash -c 'cd ../chef && knife sudo -Q roles:$(PROJECT) chef-client'