forked from AccumulateNetwork/accumulate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
266 lines (238 loc) · 7.68 KB
/
.gitlab-ci.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
stages:
- test
- build
- deploy
- validate
variables:
BOLD_RED: '\e[1;31m'
NO_COLOR: '\e[0m'
SECTION: '\e[0K'
.go:
image: golang:1.17
cache:
key: go-mod-cache
paths:
- .go-mod-cache
variables:
GOMODCACHE: ${CI_PROJECT_DIR}/.go-mod-cache
before_script:
- |
function build-daemon {
export GOOS=$1
export GOARCH=$2
BIN=accumulated
[ -z "$GOOS" ] || BIN=${BIN}-${GOOS}
[ -z "$GOARCH" ] || BIN=${BIN}-${GOARCH}
[[ $GOOS == windows ]] && BIN=${BIN}.exe
export BUILDFLAGS="-o ${BIN}"
echo -e "${SECTION}section_start:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}Build accumulated for $GOOS $GOARCH"
make GIT_COMMIT=${CI_COMMIT_SHA} GIT_DESCRIBE=${GIT_DESCRIBE}
echo -e "${SECTION}section_end:`date +%s`:build_${GOOS}_${GOARCH}\r${SECTION}";
}
.test:
stage: test
extends: .go
needs: []
tags: [docker, linux]
artifacts:
when: always
reports:
junit: report.xml
script:
- go build -v ./...
- go run gotest.tools/gotestsum --junitfile report.xml --format testname -- -cpu 4 ./...
test 1/2:
extends: .test
image: golang:1.16
test 2/2:
extends: .test
image: golang:1.17
git describe:
stage: build
needs: []
script:
- git fetch --unshallow
- echo "GIT_DESCRIBE=$(git describe --dirty)" >> git.env
artifacts:
reports:
dotenv: git.env
build images:
stage: build
needs: []
tags: [docker, linux]
image: docker
services: ['docker:dind']
script:
- docker build -t ${CI_REGISTRY_IMAGE}/accumulated:${CI_COMMIT_REF_SLUG} .
- docker build -t ${CI_REGISTRY_IMAGE}/cli:${CI_COMMIT_REF_SLUG} -f Dockerfile.cli .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push ${CI_REGISTRY_IMAGE}/accumulated:${CI_COMMIT_REF_SLUG}
- docker push ${CI_REGISTRY_IMAGE}/cli:${CI_COMMIT_REF_SLUG}
lint:
stage: build
extends: .go
needs: []
script:
- function die { echo -e "${BOLD_RED}${1}${NO_COLOR}"; false; }
- echo -e "${SECTION}section_start:`date +%s`:vet\r${SECTION}Vet"
- go vet ./...
- echo -e "${SECTION}section_end:`date +%s`:vet\r${SECTION}"
- echo -e "${SECTION}section_start:`date +%s`:tidy\r${SECTION}Verify go.mod is tidy"
- go mod tidy
- git diff --quiet go.mod go.sum || die "Go mod files are not tidy. Please run \`go mod tidy\`."
- echo -e "${SECTION}section_end:`date +%s`:tidy\r${SECTION}"
- echo -e "${SECTION}section_start:`date +%s`:generate\r${SECTION}Verify generated files are up to date"
- go generate -x ./...
- git diff --quiet || die "Generated files are not up to date. Please run \`go generate ./...\`."
- echo -e "${SECTION}section_end:`date +%s`:generate\r${SECTION}"
- echo -e "${SECTION}section_start:`date +%s`:imports\r${SECTION}Verify code is correctly formatted"
- go run github.com/rinchsan/gosimports/cmd/gosimports -l */ | tee fmt.log
- test -s fmt.log && die "Code is incorrectly formatted. Please run \`gosimports -w .\` (or \`./scripts/imports.sh\`)."
- echo -e "${SECTION}section_end:`date +%s`:imports\r${SECTION}"
build:
stage: build
extends: .go
needs: [git describe]
tags: [docker, linux]
script:
- build-daemon linux amd64
- build-daemon linux arm64
- build-daemon windows amd64
- build-daemon windows arm64
- build-daemon darwin amd64
- build-daemon darwin arm64
artifacts:
paths:
- accumulated-*
configure:
stage: build
extends: .go
needs: [git describe]
tags: [docker, linux]
script:
- |
function init {
./accumulated init -w config-$1 "${@:2}" -n $1
(cd config-$1 && tar czf ../config-$1.tar.gz *)
}
- build-daemon
- build-daemon linux arm64
- init DevNet.Directory --no-empty-blocks --no-website
- init DevNet.Zion --no-empty-blocks
- init DevNet.Yellowstone --no-empty-blocks
artifacts:
paths:
- config-*.tar.gz
- accumulated-*
.deploy:
stage: deploy
only: [develop] # only run on the main branch
needs: [configure, test 1/2, test 2/2]
tags:
- linux
- docker
- accumulate
image: ubuntu
script:
- apt-get -y update && apt-get -y install ssh
- mkdir ~/.ssh
- cp ${SSH_KNOWN_HOSTS} ~/.ssh/known_hosts
- cp ${SSH_PRIV_KEY} ~/.ssh/id_rsa
- cp ${SSH_PUB_KEY} ~/.ssh/id_rsa.pub
- chmod -R 600 ~/.ssh
- ./scripts/ci/devnet-deploy.sh
deploy 1/4:
extends: .deploy
variables: { HOST: 172.31.4.106, NETWORK: Zion, NODE: 0, DN_NODE: 0, BIN: accumulated-linux-arm64 }
environment: { url: 'http://172.31.4.106:8080', name: Zion/0 }
deploy 2/4:
extends: .deploy
variables: { HOST: 172.31.11.185, NETWORK: Zion, NODE: 1, DN_NODE: 1, BIN: accumulated-linux-arm64 }
environment: { url: 'http://172.31.11.185:8080', name: Zion/1 }
deploy 3/4:
extends: .deploy
variables: { HOST: 172.31.11.104, NETWORK: Yellowstone, NODE: 0, DN_NODE: 2, BIN: accumulated-linux-arm64 }
environment: { url: 'http://172.31.11.104:8080', name: Yellowstone/0 }
deploy 4/4:
extends: .deploy
variables: { HOST: 172.31.13.8, NETWORK: Yellowstone, NODE: 1, DN_NODE: 3, BIN: accumulated-linux-arm64 }
environment: { url: 'http://172.31.13.8:8080', name: Yellowstone/1 }
.validate:
stage: validate
extends: .go
only: [develop] # only run on the main branch
needs: [deploy 1/4, deploy 2/4, deploy 3/4, deploy 4/4]
tags: [docker, linux]
variables:
ACC_API: https://devnet.accumulatenetwork.io/v1
# set mnemonic for predictable addresses
MNEMONIC: yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow
validate docker:
stage: validate
needs: ['build images']
tags: [docker, linux]
image: docker
services: ['docker:dind']
variables:
# set mnemonic for predictable addresses
MNEMONIC: yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker run --rm -v ${PWD}/nodes:/nodes ${CI_REGISTRY_IMAGE}/cli:${CI_COMMIT_REF_SLUG} accumulated init devnet -w /nodes --docker --compose -b 3 -v 3
- cd nodes
- apk add --no-cache docker-compose
- docker-compose up -d
- docker-compose run -e MNEMONIC="${MNEMONIC}" --rm tools /scripts/ci/validate.sh
- docker-compose down
validate:
extends: .validate
script:
- apt-get -y update && apt-get -y install jq
- ./scripts/ci/validate.sh
validate matrix 1/6:
extends: .validate
script:
- ./scripts/matrix/test_case_1.1.sh
validate matrix 2/6:
extends: .validate
script:
- ./scripts/matrix/test_case_2.1.sh
- ./scripts/matrix/test_case_2.2.sh
- ./scripts/matrix/test_case_2.3.sh
- ./scripts/matrix/test_case_2.4.sh
- ./scripts/matrix/test_case_2.5.sh
- ./scripts/matrix/test_case_2.6.sh
- ./scripts/matrix/test_case_2.7.sh
validate matrix 3/6:
extends: .validate
script:
- ./scripts/matrix/test_case_3.1.sh
- ./scripts/matrix/test_case_3.2.sh
- ./scripts/matrix/test_case_3.3.sh
- ./scripts/matrix/test_case_3.4.sh
validate matrix 4/6:
extends: .validate
script:
- ./scripts/matrix/test_case_4.1.sh
- ./scripts/matrix/test_case_4.2.sh
- ./scripts/matrix/test_case_4.3.sh
- ./scripts/matrix/test_case_4.4.sh
- ./scripts/matrix/test_case_4.5.sh
- ./scripts/matrix/test_case_4.6.sh
- ./scripts/matrix/test_case_4.7.sh
- ./scripts/matrix/test_case_4.8.sh
validate matrix 5/6:
extends: .validate
script:
- ./scripts/matrix/test_case_5.1.sh
- ./scripts/matrix/test_case_5.2.sh
validate matrix 6/6:
extends: .validate
script:
- ./scripts/matrix/test_case_6.1.sh
- ./scripts/matrix/test_case_6.2.sh
- ./scripts/matrix/test_case_6.3.sh
- ./scripts/matrix/test_case_6.4.sh
- ./scripts/matrix/test_case_6.5.sh
- ./scripts/matrix/test_case_6.6.sh
- ./scripts/matrix/test_case_6.7.sh