-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
169 lines (125 loc) · 4.82 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
VERSION?=$(shell git describe --tags --dirty | sed 's/^v//')
PKG=github.com/manifoldco/manifold-cli
STRIPE_PKEY=${STRIPE_PUBLISHABLE_KEY}
LD_FLAGS=-w -X $(PKG)/config.Version=$(VERSION)
LD_FLAGS+=$(if $(STRIPE_PUBLISHABLE_KEY),-X $(PKG)/config.StripePublishableKey=$(STRIPE_PUBLISHABLE_KEY),)
LD_FLAGS+=$(if $(MANIFOLD_GITHUB_CLIENT_ID),-X $(PKG)/config.GitHubClientID=$(MANIFOLD_GITHUB_CLIENT_ID),)
GO_BUILD=CGO_ENABLED=0 go build -i --ldflags="$(LD_FLAGS)"
PROMULGATE_VERSION=0.0.8
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
$(filter $(subst *,%,$2),$d))
LINTERS=\
gofmt \
golint \
vet \
misspell \
ineffassign \
deadcode
all: ci
ci: generated-clients $(LINTERS) cover build
.PHONY: all ci
# ################################################
# Bootstrapping for base golang package deps
# ################################################
CMD_PKGS=\
github.com/golang/lint/golint \
github.com/client9/misspell/cmd/misspell \
github.com/gordonklaus/ineffassign \
github.com/tsenart/deadcode \
github.com/alecthomas/gometalinter \
github.com/go-swagger/go-swagger/cmd/swagger
define VENDOR_BIN_TMPL
vendor/bin/$(notdir $(1)): vendor/$(1) | vendor
go build -o $$@ ./vendor/$(1)
VENDOR_BINS += vendor/bin/$(notdir $(1))
vendor/$(1): Gopkg.lock
dep ensure -vendor-only
endef
$(foreach cmd_pkg,$(CMD_PKGS),$(eval $(call VENDOR_BIN_TMPL,$(cmd_pkg))))
$(patsubst %,%-bin,$(filter-out gofmt vet,$(LINTERS))): %-bin: vendor/bin/%
gofmt-bin vet-bin:
bootstrap:
which dep || go get github.com/golang/dep/cmd/dep
vendor: Gopkg.lock
dep ensure
.PHONY: bootstrap $(CMD_PKGS)
# ################################################
# Test and linting
# ###############################################
test: vendor
@CGO_ENABLED=0 go test -v $$(go list ./... | grep -v vendor)
COVER_TEST_PKGS:=$(shell find . -type f -name '*_test.go' | grep -v vendor | grep -v generated | rev | cut -d "/" -f 2- | rev | sort -u)
$(COVER_TEST_PKGS:=-cover): %-cover: all-cover.txt
@CGO_ENABLED=0 go test [email protected] -covermode=atomic ./$*
@if [ -f [email protected] ]; then \
grep -v "mode: atomic" < [email protected] >> all-cover.txt; \
rm [email protected]; \
fi
all-cover.txt:
echo "mode: atomic" > all-cover.txt
cover: vendor all-cover.txt $(COVER_TEST_PKGS:=-cover)
$(LINTERS): %: vendor/bin/gometalinter %-bin vendor
PATH=`pwd`/vendor/bin:$$PATH gometalinter --tests --disable-all --vendor \
--deadline=5m -s data --skip generated --enable $@
.PHONY: cover $(LINTERS) $(COVER_TEST_PKGS:=-cover)
# ################################################
# Building Swagger Clients
# ###############################################
generated/%/client: specs/%.yaml vendor/bin/swagger
vendor/bin/swagger generate client -f $< -t generated/$*
touch generated/$*/client
touch generated/$*/models
APIS=$(patsubst specs/%.yaml,%,$(wildcard specs/*.yaml))
API_CLIENTS=$(APIS:%=generated/%/client)
generated-clients: $(API_CLIENTS)
.PHONY: generated-clients
# ################################################
# Building
# ###############################################$
PREFIX?=
SUFFIX=
ifeq ($(GOOS),windows)
SUFFIX=.exe
endif
build: $(PREFIX)bin/manifold$(SUFFIX)
MANIFOLDCLI_DEPS=\
vendor \
$(wildcard *.go) \
$(call rwildcard,cmd,*.go) \
generated-clients
$(PREFIX)bin/manifold$(SUFFIX): $(MANIFOLDCLI_DEPS)
$(GO_BUILD) -o $(PREFIX)bin/manifold$(SUFFIX) ./cmd
.PHONY: build
#################################################
# Releasing
#################################################
NO_WINDOWS= \
darwin_amd64 \
linux_amd64
OS_ARCH= \
$(NO_WINDOWS) \
windows_amd64
os=$(word 1,$(subst _, ,$1))
arch=$(word 2,$(subst _, ,$1))
os-build/windows_amd64/bin/manifold: os-build/%/bin/manifold:
PREFIX=build/$*/ GOOS=$(call os,$*) GOARCH=$(call arch,$*) make build/$*/bin/manifold.exe
$(NO_WINDOWS:%=os-build/%/bin/manifold): os-build/%/bin/manifold:
PREFIX=build/$*/ GOOS=$(call os,$*) GOARCH=$(call arch,$*) make build/$*/bin/manifold
build/manifold-cli_$(VERSION)_windows_amd64.zip: build/manifold-cli_$(VERSION)_%.zip: os-build/%/bin/manifold
cd build/$*/bin; zip -r ../../manifold-cli_$(VERSION)_$*.zip manifold.exe
$(NO_WINDOWS:%=build/manifold-cli_$(VERSION)_%.tar.gz): build/manifold-cli_$(VERSION)_%.tar.gz: os-build/%/bin/manifold
cd build/$*/bin; tar -czf ../../manifold-cli_$(VERSION)_$*.tar.gz manifold
zips: $(NO_WINDOWS:%=build/manifold-cli_$(VERSION)_%.tar.gz) build/manifold-cli_$(VERSION)_windows_amd64.zip
release: zips
curl -LO https://releases.manifold.co/promulgate/$(PROMULGATE_VERSION)/promulgate_$(PROMULGATE_VERSION)_linux_amd64.tar.gz
tar xvf promulgate_*
./promulgate release v$(VERSION)
.PHONY: release zips $(OS_ARCH:%=os-build/%/bin/manifold)
# ################################################
# Cleaning
# ################################################
clean:
rm -rf bin/manifold
rm -rf bin/manifold.exe
rm -rf build
rm -rf generated