forked from arangodb-helper/arangodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
263 lines (202 loc) · 7.93 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
PROJECT := arangodb
ifndef SCRIPTDIR
SCRIPTDIR := $(shell pwd)
endif
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION := $(shell cat $(ROOTDIR)/VERSION)
VERSION_MAJOR_MINOR_PATCH := $(shell echo $(VERSION) | cut -f 1 -d '+')
VERSION_MAJOR_MINOR := $(shell echo $(VERSION_MAJOR_MINOR_PATCH) | cut -f 1,2 -d '.')
VERSION_MAJOR := $(shell echo $(VERSION_MAJOR_MINOR) | cut -f 1 -d '.')
COMMIT := $(shell git rev-parse --short HEAD)
MAKEFILE := $(ROOTDIR)/Makefile
DOCKERCLI ?= $(shell which docker)
GOBUILDLINKTARGET := ../../../..
BUILDDIR ?= $(ROOTDIR)
GOBUILDDIR := $(BUILDDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
CACHEVOL := $(PROJECT)-gocache
BINDIR := $(BUILDDIR)/bin
ORGPATH := github.com/arangodb-helper
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := $(PROJECT)
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)
GOPATH := $(GOBUILDDIR)
GOVERSION := 1.13.6
GOIMAGE := golang:$(GOVERSION)
GOOS ?= linux
GOARCH ?= amd64
ifeq ("$(GOOS)", "windows")
GOEXE := .exe
endif
ARANGODB ?= arangodb/arangodb:latest
DOCKERNAMESPACE ?= arangodb
ifdef TRAVIS
IP := $(shell hostname -I | cut -d ' ' -f 1)
endif
TEST_TIMEOUT := 1h
BINNAME := arangodb$(GOEXE)
TESTNAME := test$(GOEXE)
BIN := $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME)
TESTBIN := $(BINDIR)/$(GOOS)/$(GOARCH)/$(TESTNAME)
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release
GO_IGNORED:=vendor .gobuild
GO_SOURCES_QUERY := find $(SRCDIR) -name '*.go' -type f $(foreach IGNORED,$(GO_IGNORED),-not -path '$(SRCDIR)/$(IGNORED)/*' )
GO_SOURCES := $(shell $(GO_SOURCES_QUERY) | sort | uniq)
GO_SOURCES_PACKAGES := $(shell $(GO_SOURCES_QUERY) -exec dirname {} \; | sort | uniq)
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
TEST_SOURCES := $(shell find $(SRCDIR)/test -name '*.go')
DOCKER_IMAGE := $(GOIMAGE)
ifeq ($(DOCKERCLI),)
BUILD_BIN := $(BIN)
TEST_BIN := $(TESTBIN)
RELEASE_BIN := $(RELEASE)
GHRELEASE_BIN := $(GHRELEASE)
DOCKER_CMD :=
pre:
@if ! go version | grep -q "go1.13"; then echo "GO in Version 1.13 required"; exit 1; fi
deps: pre
build: pre
%: export CGO_ENABLED := 0
%: export GOARCH := $(GOARCH)
%: export GOOS := $(GOOS)
%: export GOPATH := $(GOPATH)
%: export GOCACHE := $(GOPATH)/.cache
%: export GO111MODULE := off
else
BUILD_BIN := /usr/code/bin/$(GOOS)/$(GOARCH)/$(BINNAME)
TEST_BIN := /usr/code/bin/$(GOOS)/$(GOARCH)/$(TESTNAME)
RELEASE_BIN := /usr/code/.gobuild/bin/release
GHRELEASE_BIN := /usr/code/.gobuild/bin/github-release
DOCKER_CMD = $(DOCKERCLI) run \
--rm \
-v $(SRCDIR):/usr/code \
-u "$(shell id -u):$(shell id -g)" \
-e GOCACHE=/usr/code/.gobuild/.cache \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=$(GOOS) \
-e GOARCH=$(GOARCH) \
-e CGO_ENABLED=0 \
$(DOCKER_PARAMS) \
-w /usr/code/ \
$(DOCKER_IMAGE)
endif
.PHONY: all clean deps docker build build-local
all: build
clean:
rm -Rf $(BIN) $(BINDIR) $(ROOTDIR)/arangodb
local:
ifneq ("$(DOCKERCLI)", "")
@${MAKE} -f $(MAKEFILE) -B GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) build-local
else
@${MAKE} -f $(MAKEFILE) deps
GOPATH=$(GOBUILDDIR) go build -o $(BUILDDIR)/arangodb $(REPOPATH)
endif
build-local: build
@ln -sf "$(BIN)" "$(ROOTDIR)/arangodb"
build: vendor $(BIN)
build-test: vendor $(TESTBIN)
binaries: $(GHRELEASE)
@${MAKE} -f $(MAKEFILE) -B GOOS=linux GOARCH=amd64 build
@${MAKE} -f $(MAKEFILE) -B GOOS=linux GOARCH=arm64 build
@${MAKE} -f $(MAKEFILE) -B GOOS=darwin GOARCH=amd64 build
@${MAKE} -f $(MAKEFILE) -B GOOS=windows GOARCH=amd64 build
binaries-test: $(GHRELEASE)
@${MAKE} -f $(MAKEFILE) -B GOOS=linux GOARCH=amd64 build-test
@${MAKE} -f $(MAKEFILE) -B GOOS=linux GOARCH=arm64 build-test
@${MAKE} -f $(MAKEFILE) -B GOOS=darwin GOARCH=amd64 build-test
@${MAKE} -f $(MAKEFILE) -B GOOS=windows GOARCH=amd64 build-test
$(BIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
$(DOCKER_CMD) go build -installsuffix netgo -tags netgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o "$(BUILD_BIN)" .
$(TESTBIN): $(GOBUILDDIR) $(TEST_SOURCES) $(BIN)
@mkdir -p $(BINDIR)
$(DOCKER_CMD) go test -c -o "$(TEST_BIN)" ./test
docker: build
$(DOCKERCLI) build -t arangodb/arangodb-starter .
docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag arangodb/arangodb-starter $(DOCKERNAMESPACE)/arangodb-starter
endif
docker push $(DOCKERNAMESPACE)/arangodb-starter
docker-push-version: docker
docker tag arangodb/arangodb-starter arangodb/arangodb-starter:$(VERSION)
docker tag arangodb/arangodb-starter arangodb/arangodb-starter:$(VERSION_MAJOR_MINOR)
docker tag arangodb/arangodb-starter arangodb/arangodb-starter:$(VERSION_MAJOR)
docker tag arangodb/arangodb-starter arangodb/arangodb-starter:latest
docker push arangodb/arangodb-starter:$(VERSION)
docker push arangodb/arangodb-starter:$(VERSION_MAJOR_MINOR)
docker push arangodb/arangodb-starter:$(VERSION_MAJOR)
docker push arangodb/arangodb-starter:latest
$(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
$(DOCKER_CMD) go build -o "$(RELEASE_BIN)" $(REPOPATH)/tools/release
$(GHRELEASE): $(GOBUILDDIR)
$(DOCKER_CMD) go build -o "$(GHRELEASE_BIN)" github.com/aktau/github-release
release-patch: $(RELEASE)
$(RELEASE) -type=patch
release-minor: $(RELEASE)
$(RELEASE) -type=minor
release-major: $(RELEASE)
$(RELEASE) -type=major
TESTCONTAINER := arangodb-starter-test
# Run all integration tests
run-tests: run-tests-local-process run-tests-docker
run-tests-local-process: build-test build run-tests-local-process-run
run-tests-local-process-run: export TEST_MODES=localprocess
run-tests-local-process-run: export DOCKER_IMAGE=$(ARANGODB)
run-tests-local-process-run: export DOCKER_PARAMS:=-e "TEST_MODES=$(TEST_MODES)" -e "STARTER_MODES=$(STARTER_MODES)" -e "STARTER=/usr/code/bin/linux/amd64/arangodb" -e "ENTERPRISE=$(ENTERPRISE)"
run-tests-local-process-run:
@-$(DOCKERCLI) rm -f -v $(TESTCONTAINER) &> /dev/null
$(DOCKER_CMD) /usr/code/bin/linux/amd64/test -test.timeout $(TEST_TIMEOUT) -test.v $(TESTOPTIONS)
_run-tests: build-test build
@TEST_MODES=$(TEST_MODES) STARTER_MODES=$(STARTER_MODES) STARTER=$(BIN) ENTERPRISE=$(ENTERPRISE) IP=$(IP) ARANGODB=$(ARANGODB) $(TESTBIN) -test.timeout $(TEST_TIMEOUT) -test.v $(TESTOPTIONS)
ifdef TRAVIS
run-tests-docker-pre: docker
@$(DOCKERCLI) pull $(ARANGODB)
run-tests-docker: run-tests-docker-pre
endif
run-tests-docker: TEST_MODES=docker
run-tests-docker: docker _run-tests
# Run all integration tests on the local system
run-tests-local: export TEST_MODES=localprocess
run-tests-local: _run-tests
$(GOBUILDDIR):
@mkdir -p "$(GOBUILDDIR)"
## LINT
GOLANGCI_ENABLED=deadcode gocyclo golint varcheck structcheck maligned errcheck \
ineffassign interfacer unconvert goconst \
megacheck
.PHONY: tools
tools:
@echo ">> Fetching goimports"
@go get -u golang.org/x/tools/cmd/goimports
@echo ">> Fetching license check"
@go get -u github.com/google/addlicense
@echo ">> Fetching github release"
@go get -u github.com/aktau/github-release
.PHONY: license
license:
@echo ">> Verify license of files"
@go run github.com/google/addlicense -f "./LICENSE.BOILERPLATE" $(GO_SOURCES)
.PHONY: license-verify
license-verify:
@echo ">> Ensuring license of files"
@go run github.com/google/addlicense -f "./LICENSE.BOILERPLATE" -check $(GO_SOURCES)
.PHONY: fmt
fmt:
@echo ">> Ensuring style of files"
@goimports -w $(GO_SOURCES)
.PHONY: fmt-verify
fmt-verify: license-verify
@echo ">> Verify files style"
@if [ X"$$(go goimports -l $(GO_SOURCES) | wc -l)" != X"0" ]; then echo ">> Style errors"; go goimports -l $(GO_SOURCES); exit 1; fi
.PHONY: linter
linter: fmt
@golangci-lint run --no-config --issues-exit-code=1 --deadline=30m --disable-all \
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE) ) \
--exclude-use-default=false \
$(GO_SOURCES_PACKAGES)
.PHONY: vendor
vendor:
@go mod vendor