-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconfig.yml
523 lines (497 loc) · 15.8 KB
/
config.yml
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
version: 2.1
defaults: &linux_defaults
working_directory: /go/src/github.com/line/lbm
docker:
- image: circleci/golang:1.15
environment:
GO111MODULE: 'on'
machine_defaults: &machine_defaults
working_directory: /home/circleci/.go_workspace/src/github.com/line/lbm
machine:
image: circleci/classic:latest
docker_layer_caching: true
environment:
GOPATH: /home/circleci/.go_workspace/
GOOS: linux
GOARCH: amd64
GO_VERSION: "1.15"
jobs:
check-skippable-pr:
docker:
- image: alpine:3.7
resource_class: small
steps:
- run: apk add --no-cache bash curl jq
- run:
shell: /bin/bash
name: Check skippable PR
command: |
required_env_vars=(
"GITHUB_TOKEN"
"CIRCLE_PROJECT_USERNAME"
"CIRCLE_PROJECT_REPONAME"
"CIRCLE_TOKEN"
"CIRCLE_BUILD_NUM"
)
PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST | sed -e 's#.*/pull/##')
for required_env_var in ${required_env_vars[@]}; do
if [[ -z "${!required_env_var}" ]]; then
printf "${required_env_var} not provided, but that doesn't mean we should skip CI.\n"
exit 0
fi
done
# Since we're piggybacking off of an existing OAuth var, tweak the var for our uses
token=$(printf "${GITHUB_TOKEN}" | cut -d':' -f1)
headers="Authorization: token $token"
api_endpoint="https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${PR_NUMBER}"
# Fetch PR metadata from Github's API and parse fields from json
github_res=$(curl --silent --header "${headers}" "${api_endpoint}" | jq '{mergeable_state: .mergeable_state, title: .title}')
mergeable_state=$(printf "${github_res}" | jq '.mergeable_state')
title=$(printf "${github_res}" | jq '.title' | tr '[:upper:]' '[:lower:]')
echo "${title}"
if [[ "${title}" == "null" && "${mergeable_state}" == "null" ]]; then
printf "Couldn't fetch info on PR, but that doesn't mean we should skip CI.\n"
exit 0
fi
cancel_running_jobs=0
if [[ "${mergeable_state}" == "\"draft\"" ]]; then
printf "PR is a draft, skipping CI!\n"
cancel_running_jobs=1
fi
for skip_token in '[skip ci]' '[ci skip]' '[wip]' 'WIP' 'wip' '🚧'; do
if [[ ${title} == *"${skip_token}"* ]]; then
printf "Found \"${skip_token}\" in PR title, skipping CI!\n"
cancel_running_jobs=1
fi
done
if [[ "${cancel_running_jobs}" == 1 ]]; then
printf "Attempting to cancel any running jobs"
CIRCLE_API_BASE_URL="https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"
AUTH_PARAMS="circle-token=${CIRCLE_TOKEN}"
SELF_BUILD_NUM="${CIRCLE_BUILD_NUM}"
all_jobs=$(curl --silent --show-error "${CIRCLE_API_BASE_URL}/tree/${CIRCLE_BRANCH}?${AUTH_PARAMS}")
running_jobs=$(echo "${all_jobs}" | jq "map(if .status == \"running\" or .status == \"not_running\" then .build_num else \"None\" end) - [${SELF_BUILD_NUM}] - [\"None\"] | .[]")
for buildNum in $running_jobs; do
printf "Canceling ${buildNum}"
curl --silent --show-error --request POST "${CIRCLE_API_BASE_URL}/${buildNum}/cancel?${AUTH_PARAMS}" > /dev/null
done
exit 1
else
printf "No reason to skip CI, let's go!"
fi
exit 0
fmt:
<<: *linux_defaults
resource_class: small
steps:
- checkout
- run:
name: check formatting
command: if [[ -n "$(gofmt -l .)" ]]; then gofmt -l .; exit 1; fi
setup_dependencies:
<<: *linux_defaults
resource_class: xlarge
steps:
- run: mkdir -p /tmp/workspace/bin
- run: mkdir -p /tmp/workspace/profiles
- checkout
- restore_cache:
keys:
- dependency-cache-cleveldb-1.20
- run:
name: run setup cleveldb
command: |
set -x
export WITH_CLEVELDB=yes
if [ ! -d /tmp/cleveldb_binary ] ; then
mkdir -p /tmp/cleveldb_binary
cp ./contrib/get_cleveldb.sh /tmp/cleveldb_binary
fi
pushd /tmp/cleveldb_binary
./get_cleveldb.sh ${WITH_CLEVELDB}
popd
- save_cache:
key: dependency-cache-cleveldb-1.20
paths:
- "/tmp/cleveldb_binary"
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: binaries
command: |
export PATH=/tmp/workspace/bin:$PATH
go env -w GOPRIVATE=github.com/line/*
git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
make go-mod-cache
make install WITH_CLEVELDB=yes CGO_ENABLED=1
- save_cache:
key: dependency-cache-mod-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
# TODO ebony
# - run:
# name: tools
# command: |
# make get-tools
lint:
<<: *linux_defaults
resource_class: xlarge
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: lint
command: |
go env -w GOPRIVATE=github.com/line/*
git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
go get github.com/golangci/golangci-lint/cmd/golangci-lint
make lint
unit_test:
<<: *linux_defaults
resource_class: medium
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
# TODO ebony
- run: make test-unit
# - run: make test-unit-cover
# - run: bash <(curl -s https://codecov.io/bash) -f ./coverage.txt -F "unittest" -Z
integration_test:
<<: *linux_defaults
resource_class: xlarge
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: Test cli
command: |
export BUILDDIR=`pwd`/build
make test-integration CGO_ENABLED=1
setup_docker_and_binary:
<<: *machine_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- machine-dependency-cache-cleveldb-1.20
- run:
name: run setup cleveldb
command: |
set -x
export WITH_CLEVELDB=yes
if [ ! -d /tmp/cleveldb_binary ] ; then
mkdir -p /tmp/cleveldb_binary
cp ./contrib/get_cleveldb.sh /tmp/cleveldb_binary
fi
pushd /tmp/cleveldb_binary
./get_cleveldb.sh ${WITH_CLEVELDB}
popd
- save_cache:
key: machine-dependency-cache-cleveldb-1.20
paths:
- "/tmp/cleveldb_binary"
- restore_cache:
keys:
- machine-dependency-cache-mod-{{ checksum "go.sum" }}-1.15
- run:
name: run setup go
command: |
set -x
if [ "$(go version)" != "go version go1.13.4 linux/amd64" ]; then
mkdir -p /tmp/gobinary
pushd /tmp/gobinary
wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz
sudo tar -xvf go$GO_VERSION.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo cp -r go /usr/local
popd
fi
- run:
name: build binaries
command: |
set -x
go env -w GOPRIVATE=github.com/line/*
git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
make build WITH_CLEVELDB=yes
- save_cache:
key: machine-dependency-cache-mod-{{ checksum "go.sum" }}-1.15
paths:
- "/home/circleci/.go_workspace/pkg/mod"
- "/tmp/gobinary"
sim-link-nondeterminism:
<<: *linux_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: test individual module simulations
command: |
make sim-link-nondeterminism
sim-link-simulation-after-import:
<<: *linux_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: test simulation after import
command: |
make get-tools
make sim-link-simulation-after-import
sim-link-multi-seed:
<<: *linux_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: test multi-seed simulation
command: |
make get-tools
make sim-link-multi-seed
sim-link-multi-seed-short:
<<: *linux_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-mod-{{ checksum "go.sum" }}
- run:
name: test multi-seed simulation (short)
command: |
make get-tools
make sim-link-multi-seed-short
integration_multi_node_test:
<<: *machine_defaults
resource_class: xlarge
steps:
- checkout
- restore_cache:
keys:
- machine-dependency-cache-cleveldb-1.20
- run:
name: copy cleveldb binary
command: |
set -x
export WITH_CLEVELDB=yes
pushd /tmp/cleveldb_binary
./get_cleveldb.sh ${WITH_CLEVELDB}
popd
- restore_cache:
keys:
- machine-dependency-cache-mod-{{ checksum "go.sum" }}-1.15
- run:
name: copy go compiler
command: |
set -x
pushd /tmp/gobinary
sudo rm -rf /usr/local/go
sudo mv go /usr/local
popd
- run:
name: build binary
command: |
set -x
go env -w GOPRIVATE=github.com/line/*
git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
make build WITH_CLEVELDB=yes
- run:
name: build docker image
command: |
set -x
make build-docker WITH_CLEVELDB=yes
- run:
name: run integration test for multi node and exit on failure
command: |
set -x
docker network prune -f
make test-integration-multi-node
localnet:
<<: *machine_defaults
resource_class: medium
steps:
- checkout
- restore_cache:
keys:
- machine-dependency-cache-mod-{{ checksum "go.sum" }}-1.15
- run:
name: copy go compiler
command: |
set -x
pushd /tmp/gobinary
sudo rm -rf /usr/local/go
sudo mv go /usr/local
popd
- run:
name: build docker image
command: |
set -x
make build-docker WITH_CLEVELDB=yes
- run:
name: run localnet and exit on failure
command: |
set -x
docker network prune -f
make testnet-start
./networks/local/localnet-blocks-test.sh 40 5 10 localhost
semantic_release:
docker:
- image: circleci/node:10
resource_class: medium
steps:
- checkout
- run: yarn global add --no-progress --non-interactive "semantic-release" "@semantic-release/exec"
- run: $(yarn global bin)/semantic-release
deploy:
docker:
- image: circleci/golang:1.15
resource_class: medium
steps:
- checkout
- run: go env -w GOPRIVATE=github.com/line/*
- run: git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
- run: make build-swagger-docs
- run: curl -sL https://git.io/goreleaser | bash -s -- --skip-validate --rm-dist
# TODO ebony
# contract_test:
# <<: *linux_defaults
# resource_class: medium
# steps:
# - run: rm -rf /tmp/contract_test
# - run: mkdir -p /tmp/contract_test
# - checkout
# - run:
# name: Get Node.js and test REST implementation against swagger documentation
# command: |
# go env -w GOPRIVATE=github.com/line/*
# git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
# go get github.com/snikch/goodman/cmd/goodman
# ./contrib/get_node.sh && make contract-test
workflows:
version: 2.1
build_and_test:
jobs:
- check-skippable-pr
- fmt:
requires:
- check-skippable-pr
- lint:
requires:
- fmt
- setup_dependencies:
requires:
- lint
- unit_test:
requires:
- setup_dependencies
- integration_test:
requires:
- setup_dependencies
#TODO ebony
# - contract_test
- setup_docker_and_binary:
requires:
- lint
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- localnet:
requires:
- setup_docker_and_binary
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- integration_multi_node_test:
requires:
- setup_docker_and_binary
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- sim-link-nondeterminism:
requires:
- setup_dependencies
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- sim-link-simulation-after-import:
requires:
- setup_dependencies
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- sim-link-multi-seed:
requires:
- setup_dependencies
filters:
branches:
only:
- hotfix-sim-link-multi-seed
- sim-link-multi-seed-short:
requires:
- setup_dependencies
filters:
branches:
only:
- master
- develop
- /hotfix-.*/
- /testall-.*/
- semantic_release:
requires:
- unit_test
# TODO ebony
# - contract_test
- integration_test
# - localnet
# - integration_multi_node_test
# - sim-link-nondeterminism
# - sim-link-simulation-after-import
# - sim-link-multi-seed-short
filters:
branches:
only: master
- deploy:
requires:
- semantic_release
filters:
branches:
only: master