-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
155 lines (128 loc) · 4.01 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#-------------------
# Variables
#-------------------
PROGRAM_NAME=slipway
PROTOC_TARGET_DIR=/usr/local
PROTOC_VERSION=3.5.1
TRAVIS_BUILD_NUMBER ?= 999999
CLI_FEATURE_VERSION ?= 1.0
CLI_VERSION ?= ${CLI_FEATURE_VERSION}.${TRAVIS_BUILD_NUMBER}
# if not set, then we're doing local development
# as this will be set by the travis matrix for realz
TARGET_PLATFORM ?= darwin
TARGET_ARCH ?= amd64
BINARY_NAME := ${PROGRAM_NAME}-${TARGET_PLATFORM}-${TARGET_ARCH}-${CLI_VERSION}
TAR_NAME = ${BINARY_NAME}.tar.gz
SHELL := /bin/bash
BINDIR := bin
PKG := github.com/getnelson/${PROGRAM_NAME}
GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GODIRS = $(shell go list -f '{{.Dir}}' ./... \
| grep -vFf <(go list -f '{{.Dir}}' ./vendor/...))
.PHONY: release
release: format test package
.PHONY: package
package: test build
mkdir -p target && \
mv bin/${BINARY_NAME} ./${PROGRAM_NAME} && \
tar -zcvf ${TAR_NAME} ${PROGRAM_NAME} && \
rm ${PROGRAM_NAME} && \
sha1sum ${TAR_NAME} > ${TAR_NAME}.sha1 && \
shasum -c ${TAR_NAME}.sha1 && \
mv ${TAR_NAME} target/${TAR_NAME} && \
mv ${TAR_NAME}.sha1 target/${TAR_NAME}.sha1
.PHONY: build
build: vendor
@echo "--> building"
GOOS=${TARGET_PLATFORM} \
GOARCH=${TARGET_ARCH} \
CGO_ENABLED=0 \
GOBIN=$(BINDIR) \
go build \
-v \
-ldflags "-X main.globalBuildVersion=${CLI_VERSION}" \
-o ${BINDIR}/${BINARY_NAME} \
./cmd
.PHONY: watch
watch:
@echo "--> watching for changed files"
@fswatch
.PHONY: clean
clean:
@echo "--> cleaning compiled objects and binaries"
@rm -rf $(BINDIR)/*
.PHONY: test
test: vendor
@echo "--> running unit tests"
@go test ./cmd/...
.PHONY: format
format: tools.goimports
@echo "--> formatting code with 'goimports' tool"
@goimports -local $(PKG) -w -l $(GOFILES)
.PHONY: lint
lint: tools.golint
@echo "--> checking code style with 'golint' tool"
@echo $(GODIRS) | xargs -n 1 golint
#-------------------
#-- code generaion
#-------------------
generate: $(BINDIR)/gogofast $(BINDIR)/validate
@echo "--> generating pb.go files"
$(SHELL) scripts/generate-protos
#------------------
#-- dependencies
#------------------
.PHONY: deps.update deps.install
deps.update: tools.glide
@echo "--> updating dependencies from glide.yaml"
@glide update
deps.install: tools.glide
@echo "--> installing dependencies from glide.lock "
@glide install
vendor:
@echo "--> installing dependencies from glide.lock "
@glide install
#-------------------
#-- tools
#-------------------
tools: tools.protoc tools.glide tools.golint tools.fswatch tools.goimports
tools.fswatch:
@command -v fswatch >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing fswatch"; \
go get -u github.com/codeskyblue/fswatch; \
fi
tools.golint:
@command -v golint >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing golint"; \
go get -u golang.org/x/lint/golint; \
fi
tools.glide:
@command -v glide >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing glide"; \
curl https://glide.sh/get | sh; \
fi
tools.goimports:
@command -v goimports >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing goimports"; \
go get golang.org/x/tools/cmd/goimports; \
fi
tools.protoc:
@command -v protoc >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing protoc"; \
if [ `uname -s` = "Linux" ]; then \
curl -sSOL "https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip" && \
unzip "protoc-$(PROTOC_VERSION)-linux-x86_64.zip" -d protoc3 && \
sudo mv protoc3/bin/* ${PROTOC_TARGET_DIR}/bin && \
sudo chmod -R 775 ${PROTOC_TARGET_DIR}/bin && \
sudo mv protoc3/include/* ${PROTOC_TARGET_DIR}/include && \
sudo chmod -R 755 ${PROTOC_TARGET_DIR}/include && \
rm "protoc-$(PROTOC_VERSION)-linux-x86_64.zip" && \
rm -rf protoc3; \
fi; \
fi
$(BINDIR)/gogofast: vendor
@echo "--> building $@"
@go build -o $@ vendor/github.com/gogo/protobuf/protoc-gen-gogofast/main.go
$(BINDIR)/validate: vendor
@echo "--> building $@"
@go build -o $@ vendor/github.com/lyft/protoc-gen-validate/main.go