forked from spacemeshos/go-spacemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
285 lines (210 loc) · 7.3 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
BINARY := go-spacemesh
VERSION := 0.0.1
COMMIT = $(shell git rev-parse HEAD)
SHA = $(shell git rev-parse --short HEAD)
CURR_DIR = $(shell pwd)
CURR_DIR_WIN = $(shell cd)
BIN_DIR = $(CURR_DIR)/build
BIN_DIR_WIN = $(CUR_DIR_WIN)/build
export GO111MODULE = on
BRANCH := $(shell bash -c 'if [ "$$TRAVIS_PULL_REQUEST" == "false" ]; then echo $$TRAVIS_BRANCH; else echo $$TRAVIS_PULL_REQUEST_BRANCH; fi')
# Set BRANCH when running make manually
ifeq ($(BRANCH),)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
endif
# Setup the -ldflags option to pass vars defined here to app vars
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"
PKGS = $(shell go list ./...)
PLATFORMS := windows linux darwin
os = $(word 1, $@)
ifeq ($(BRANCH),develop)
DOCKER_IMAGE_REPO := go-spacemesh
else
DOCKER_IMAGE_REPO := go-spacemesh-dev
endif
all: install build
.PHONY: all
install:
ifeq ($(OS),Windows_NT)
setup_env.bat
else
./setup_env.sh
endif
.PHONY: install
genproto:
ifeq ($(OS),Windows_NT)
scripts\win\genproto.bat
else
./scripts/genproto.sh
endif
.PHONY: genproto
build: genproto
ifeq ($(OS),Windows_NT)
go build ${LDFLAGS} -o $(BIN_DIR_WIN)/$(BINARY).exe
else
go build ${LDFLAGS} -o $(BIN_DIR)/$(BINARY)
endif
.PHONY: build
hare:
ifeq ($(OS),Windows_NT)
cd cmd/hare ; go build -o $(BIN_DIR_WIN)/go-hare.exe; cd ..
else
cd cmd/hare ; go build -o $(BIN_DIR)/go-hare; cd ..
endif
.PHONY: hare
p2p:
ifeq ($(OS),WINDOWS_NT)
cd cmd/p2p ; go build -o $(BIN_DIR_WIN)/go-p2p.exe; cd ..
else
cd cmd/p2p ; go build -o $(BIN_DIR)/go-p2p; cd ..
endif
.PHONY: p2p
sync:
ifeq ($(OS),WINDOWS_NT)
cd cmd/sync ; go build -o $(BIN_DIR_WIN)/go-sync.exe; cd ..
else
cd cmd/sync ; go build -o $(BIN_DIR)/go-sync; cd ..
endif
.PHONY: sync
harness:
ifeq ($(OS),WINDOWS_NT)
cd cmd/integration ; go build -o $(BIN_DIR_WIN)/go-harness.exe; cd ..
else
cd cmd/integration ; go build -o $(BIN_DIR)/go-harness; cd ..
endif
.PHONY: harness
tidy:
go mod tidy
.PHONY: tidy
$(PLATFORMS): genproto
ifeq ($(OS),Windows_NT)
set GOOS=$(os)&&set GOARCH=amd64&&go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY)
else
GOOS=$(os) GOARCH=amd64 go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY)
endif
.PHONY: $(PLATFORMS)
arm6: genproto
GOOS=linux GOARCH=arm GOARM=6 go build ${LDFLAGS} -o $(CURR_DIR)/$(BINARY)
.PHONY: pi
test: genproto
ulimit -n 500; go test -timeout 0 -p 1 ./...
.PHONY: test
test-tidy:
# Working directory must be clean, or this test would be destructive
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && exit 1)
# We expect `go mod tidy` not to change anything, the test should fail otherwise
make tidy
git diff --exit-code || (git checkout . && exit 1)
.PHONY: test-tidy
test-fmt:
git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && exit 1)
# We expect `go fmt` not to change anything, the test should fail otherwise
go fmt ./...
git diff --exit-code || (git checkout . && exit 1)
.PHONY: test-fmt
lint:
./scripts/validate-lint.sh
.PHONY: lint
cover:
@echo "mode: count" > cover-all.out
@$(foreach pkg,$(PKGS),\
go test -coverprofile=cover.out -covermode=count $(pkg);\
tail -n +2 cover.out >> cover-all.out;)
go tool cover -html=cover-all.out
.PHONY: cover
dockerbuild-go:
docker build -t $(DOCKER_IMAGE_REPO):$(BRANCH) .
.PHONY: dockerbuild-go
dockerbuild-test:
docker build -f DockerFileTests --build-arg GCLOUD_KEY="$(GCLOUD_KEY)" \
--build-arg PROJECT_NAME="$(PROJECT_NAME)" \
--build-arg CLUSTER_NAME="$(CLUSTER_NAME)" \
--build-arg CLUSTER_ZONE="$(CLUSTER_ZONE)" \
-t go-spacemesh-python:$(BRANCH) .
.PHONY: dockerbuild-test
dockerpush: dockerbuild-go
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker tag $(DOCKER_IMAGE_REPO):$(BRANCH) spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)
docker push spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)
ifeq ($(BRANCH),develop)
docker tag $(DOCKER_IMAGE_REPO):$(BRANCH) spacemeshos/$(DOCKER_IMAGE_REPO):$(SHA)
docker push spacemeshos/$(DOCKER_IMAGE_REPO):$(SHA)
endif
.PHONY: dockerpush
ifdef TEST
DELIM=::
endif
dockerrun-p2p:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v p2p/test_p2p.py --tc-file=p2p/config.yaml --tc-format=yaml
.PHONY: dockerrun-p2p
dockertest-p2p: dockerbuild-test dockerrun-p2p
.PHONY: dockertest-p2p
dockerrun-mining:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v test_bs.py --tc-file=config.yaml --tc-format=yaml
.PHONY: dockerrun-mining
dockertest-mining: dockerbuild-test dockerrun-mining
.PHONY: dockertest-mining
dockerrun-hare:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v hare/test_hare.py::test_hare_sanity --tc-file=hare/config.yaml --tc-format=yaml
.PHONY: dockerrun-hare
dockertest-hare: dockerbuild-test dockerrun-hare
.PHONY: dockertest-hare
dockerrun-sync:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v sync/test_sync.py --tc-file=sync/config.yaml --tc-format=yaml
.PHONY: dockerrun-sync
dockertest-sync: dockerbuild-test dockerrun-sync
.PHONY: dockertest-sync
dockertest-harness: dockerbuild-test dockerrun-harness
.PHONY: dockertest-harness
# command for late nodes
dockerrun-late-nodes:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v late_nodes/test_delayed.py --tc-file=late_nodes/delayed_config.yaml --tc-format=yaml
.PHONY: dockerrun-late-nodes
dockertest-late-nodes: dockerbuild-test dockerrun-late-nodes
.PHONY: dockertest-late-nodes
dockerrun-genesis-voting:
ifndef ES_PASSWD
$(error ES_PASSWD is not set)
endif
docker run --rm -e ES_PASSWD="$(ES_PASSWD)" \
-e GOOGLE_APPLICATION_CREDENTIALS=./spacemesh.json \
-e CLIENT_DOCKER_IMAGE="spacemeshos/$(DOCKER_IMAGE_REPO):$(BRANCH)" \
-it go-spacemesh-python:$(BRANCH) pytest -s -v sync/genesis/test_genesis_voting.py --tc-file=sync/genesis/config.yaml --tc-format=yaml
.PHONY: dockerrun-genesis-voting
dockertest-genesis-voting: dockerbuild-test dockerrun-genesis-voting
.PHONY: dockertest-genesis-voting
# The following is used to run tests one after the other locally
dockerrun-test: dockerbuild-test dockerrun-p2p dockerrun-mining dockerrun-hare dockerrun-sync dockerrun-late-nodes # dockerrun-genesis-voting
.PHONY: dockerrun-test
dockerrun-all: dockerpush dockerrun-test
.PHONY: dockerrun-all