This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitlab-ci.yml
297 lines (255 loc) · 13 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
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
# .gitlab-ci.yml
#
# ink-waterfall
#
# pipelines can be triggered manually in the web
stages:
- declare-vars
- test
- compare-build
variables:
GIT_STRATEGY: fetch
GIT_DEPTH: "100"
RUST_LIB_BACKTRACE: "0"
RUST_LOG: "info"
CI_IMAGE: "paritytech/ci-unified:bullseye-1.69.0-2023-03-21"
INK_EXAMPLES_PATH: "./ink/integration-tests"
DELEGATOR_SUBCONTRACTS: "accumulator adder subber"
UI_URL: "https://polkadotjs-apps.web.app/"
.default-refs: &default-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME == "tags"
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
.basic-env: &basic-env
image: "${CI_IMAGE}"
before_script:
- cargo -vV
- rustc -vV
- rustup show
- bash --version
- substrate-contracts-node --version
- cargo-contract --version
- git show
<<: *default-refs
interruptible: true
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
.docker-env: &docker-env
<<: *basic-env
tags:
- linux-docker-vm-c2
.kubernetes-env: &kubernetes-env
<<: *basic-env
before_script: []
tags:
- kubernetes-parity-build
.if-trigger-ref-valid: &if-trigger-ref-valid
before_script:
- if [ "$TRGR_REF" == "master" ] || [ -z "$TRGR_REF" ]; then
echo "It makes no sense to compare $REDIS_SIZES_KEY to $REDIS_SIZES_KEY_MASTER.";
echo "Exiting gracefully.";
exit 0;
fi
.clone-repo: &clone-repo
- echo ${UPSTREAM_BRANCH} ${UPSTREAM_REPO}
- git clone --verbose --depth 1 --branch ${UPSTREAM_BRANCH} ${UPSTREAM_REPO}
.clone-repo-past-month: &clone-repo-past-month
- PAST_MONTH=$(date -d "-1 month" +%Y-%m-%d)
- git clone --shallow-since=${PAST_MONTH} --branch ${UPSTREAM_BRANCH} ${UPSTREAM_REPO}
.choose-ink-waterfall-repo: &choose-ink-waterfall-repo
- echo "choosing repo"
- echo ${UPSTREAM_BRANCH} ${UPSTREAM_REPO}
- if [ "$UPSTREAM_BRANCH" = "features/storage-rework" ]; then
echo "explicitly cloning external branch for storage pr";
git clone --verbose --depth 1 --branch feature/refactored-storage https://github.com/Supercolony-net/ink-waterfall && cd ./ink-waterfall/ && pwd && git show;
fi
.start-substrate-contracts-node: &start-substrate-contracts-node
- substrate-contracts-node -lruntime::contracts=debug > /tmp/substrate-contracts-node.log 2>&1 &
.start-substrate-contracts-node-rand-extension: &start-substrate-contracts-node-rand-extension
- substrate-contracts-node-rand-extension -lruntime::contracts=debug > /tmp/substrate-contracts-node-rand-extension.log 2>&1 &
.shutdown-substrate-contracts-node: &shutdown-substrate-contracts-node
- pkill -f "substrate-contracts-node"
.shutdown-substrate-contracts-node-rand-extension: &shutdown-substrate-contracts-node-rand-extension
- pkill -f "substrate-contracts-node-rand-extension"
# Needed vars have to be "exported" in an earlier stage
parent-vars:
stage: declare-vars
<<: *kubernetes-env
variables:
CI_IMAGE: "paritytech/tools"
script:
- |
# default values
UPSTREAM_BRANCH="master"
UPSTREAM_BRANCH_REDIS_KEY="master"
UPSTREAM_REPO="https://github.com/paritytech/ink.git"
UPSTREAM_REPO_NAME="ink"
echo ${TRGR_REF}
if [ -n "$TRGR_REF" ] && [ "$TRGR_REF" != "master" ]; then
PR_JSON=`curl -s https://api.github.com/repos/paritytech/ink/pulls/${TRGR_REF}`;
UPSTREAM_BRANCH=`echo "${PR_JSON}" | jq -r .head.ref`;
# Since we write the branch name to a file we need to remove any forward slashes
# which may exist in the name
UPSTREAM_BRANCH_REDIS_KEY=`echo "${UPSTREAM_BRANCH}" | sed 's/\//-/g'`;
# We need to use https, the unauthenticated git protocol is no longer supported by GitHub.
UPSTREAM_REPO=`echo "${PR_JSON}" | jq -r .head.repo.git_url | sed 's/git:/https:/'`;
UPSTREAM_REPO_NAME=`echo "${PR_JSON}" | jq -r .head.repo.name`;
fi
- echo "UPSTREAM_BRANCH=${UPSTREAM_BRANCH}" | tee -a parent-vars.env
- echo "UPSTREAM_BRANCH_REDIS_KEY=${UPSTREAM_BRANCH_REDIS_KEY}" | tee -a parent-vars.env
- echo "UPSTREAM_REPO=${UPSTREAM_REPO}" | tee -a parent-vars.env
- echo "UPSTREAM_REPO_NAME=${UPSTREAM_REPO_NAME}" | tee -a parent-vars.env
# REDIS_SIZES_KEY (e.g. ink-waterfall::ink::foo-add-feature::sizes)
# defines a Redis key name where contract sizes will be stored from an upstream above.
- echo "REDIS_SIZES_KEY=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::${UPSTREAM_BRANCH_REDIS_KEY}::sizes" | tee -a parent-vars.env
- echo "REDIS_SIZES_RAND_EXT_KEY=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::${UPSTREAM_BRANCH_REDIS_KEY}::sizes_rand_ext" | tee -a parent-vars.env
- echo "REDIS_GAS_USAGE_KEY=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::${UPSTREAM_BRANCH_REDIS_KEY}::gas_usage" | tee -a parent-vars.env
- echo "REDIS_GAS_USAGE_RAND_EXT_KEY=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::${UPSTREAM_BRANCH_REDIS_KEY}::gas_usage_rand_ext" | tee -a parent-vars.env
# REDIS_SIZES_KEY_MASTER (e.g. ink-waterfall::ink::master::sizes)
# defines a Redis key name for an upstream's master reference branch.
# contract sizes stored there will be used for a comparison with contract sizes stored in REDIS_SIZES_KEY.
- echo "REDIS_SIZES_KEY_MASTER=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::master::sizes" | tee -a parent-vars.env
- echo "REDIS_SIZES_RAND_EXT_KEY_MASTER=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::master::sizes_rand_ext" | tee -a parent-vars.env
- echo "REDIS_GAS_USAGE_KEY_MASTER=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::master::gas_usage" | tee -a parent-vars.env
- echo "REDIS_GAS_USAGE_RAND_EXT_KEY_MASTER=${CI_PROJECT_NAME}::${UPSTREAM_REPO_NAME}::master::gas_usage_rand_ext" | tee -a parent-vars.env
artifacts:
reports:
dotenv: parent-vars.env
.build-ink-example-contracts: &build-ink-example-contracts
- set -o pipefail
- redis-cli -u $GITLAB_REDIS_URI del $REDIS_SIZES_KEY
- echo "Data will be written to $REDIS_SIZES_KEY"
- for example in ${INK_EXAMPLES_PATH}/*/; do
if [ "$example" == "./ink/integration-tests/lang-err-integration-tests/" ]; then continue; fi;
echo "set -o pipefail; ./scripts/ci/build-contract.sh ${example} |
redis-cli -u ${GITLAB_REDIS_URI} -x rpush ${REDIS_SIZES_KEY}" >> /tmp/cmds;
done
- for contract in ${DELEGATOR_SUBCONTRACTS}; do
echo "./scripts/ci/build-contract.sh ${INK_EXAMPLES_PATH}/delegator/${contract} |
redis-cli -u ${GITLAB_REDIS_URI} -x rpush ${REDIS_SIZES_KEY}" >> /tmp/cmds;
done
# Exit when the first job fails. Kill running jobs
- parallel --halt-on-error now,fail=1 -j 2 -a /tmp/cmds --joblog /tmp/joblog
- cat /tmp/joblog
# all ci/cd keys need to have ttl
- redis-cli -u $GITLAB_REDIS_URI expire $REDIS_SIZES_KEY $GITLAB_REDIS_TTL
.build-rand-extension-contract: &build-rand-extension-contract
- set -o pipefail
# delete old list items if the key has existed previously
- redis-cli -u $GITLAB_REDIS_URI del $REDIS_SIZES_RAND_EXT_KEY
- echo "Data will be written to $REDIS_SIZES_RAND_EXT_KEY"
- ./scripts/ci/build-contract.sh ./ink/integration-tests/rand-extension/ |
redis-cli -u ${GITLAB_REDIS_URI} -x rpush ${REDIS_SIZES_RAND_EXT_KEY}
# all ci/cd keys need to have ttl
- redis-cli -u $GITLAB_REDIS_URI expire $REDIS_SIZES_RAND_EXT_KEY $GITLAB_REDIS_TTL
.store-ink-examples-gas-usage-to-redis: &store-ink-examples-gas-usage-to-redis
- set -o pipefail
# delete old list items if the key has existed previously
- redis-cli -u $GITLAB_REDIS_URI del $REDIS_GAS_USAGE_KEY
- echo "Data will be written to $REDIS_GAS_USAGE_KEY"
- for example in ${INK_EXAMPLES_PATH}/*/; do
if [ "$example" == "./ink/integration-tests/rand-extension/" ]; then continue; fi;
if [ "$example" == "./ink/integration-tests/lang-err-integration-tests/" ]; then continue; fi;
echo $example;
./scripts/ci/extract-gas-usage.sh ${example};
done
- for example in ${INK_EXAMPLES_PATH}/*/; do
if [ "$example" == "./ink/integration-tests/rand-extension/" ]; then continue; fi;
if [ "$example" == "./ink/integration-tests/lang-err-integration-tests/" ]; then continue; fi;
./scripts/ci/extract-gas-usage.sh ${example} |
redis-cli -u ${GITLAB_REDIS_URI} -x rpush ${REDIS_GAS_USAGE_KEY};
done
# all ci/cd keys need to have ttl
- redis-cli -u $GITLAB_REDIS_URI expire $REDIS_GAS_USAGE_KEY $GITLAB_REDIS_TTL
.store-rand-ext-gas-usage-to-redis: &store-rand-ext-gas-usage-to-redis
- set -o pipefail
# delete old list items if the key has existed previously
- redis-cli -u $GITLAB_REDIS_URI del $REDIS_GAS_USAGE_RAND_EXT_KEY
- echo "Data will be written to $REDIS_GAS_USAGE_RAND_EXT_KEY"
- ./scripts/ci/extract-gas-usage.sh "rand-extension"
- ./scripts/ci/extract-gas-usage.sh "rand-extension" | redis-cli -u ${GITLAB_REDIS_URI} -x rpush ${REDIS_GAS_USAGE_RAND_EXT_KEY}
# all ci/cd keys need to have ttl
- redis-cli -u $GITLAB_REDIS_URI expire $REDIS_GAS_USAGE_RAND_EXT_KEY $GITLAB_REDIS_TTL
polkadot-js-ui-ink-examples: &polkadot-js-ui-ink-examples
stage: test
<<: *docker-env
script:
- *choose-ink-waterfall-repo
- *clone-repo
- *start-substrate-contracts-node
- *build-ink-example-contracts
- WATERFALL_SKIP_CONTRACT_BUILD=true cargo test --jobs 1 --features headless,polkadot-js-ui 2>&1 |
tee /tmp/waterfall.log
- *store-ink-examples-gas-usage-to-redis
after_script:
- *shutdown-substrate-contracts-node
dependencies:
- parent-vars
# fixme: diagnose and fix the rand-extension test
.polkadot-js-ui-rand-extension:
stage: test
<<: *docker-env
script:
- *choose-ink-waterfall-repo
- *clone-repo
- *start-substrate-contracts-node-rand-extension
- *build-rand-extension-contract
- WATERFALL_SKIP_CONTRACT_BUILD=true cargo test --features headless,polkadot-js-ui -- --ignored rand_extension 2>&1 |
tee /tmp/waterfall.log
- *store-rand-ext-gas-usage-to-redis
after_script:
- *shutdown-substrate-contracts-node-rand-extension
dependencies:
- parent-vars
evaluate-ink-examples-changes:
stage: compare-build
<<: *kubernetes-env
# Comparison is made only if a parent (trigger) was created by a PR.
# Otherwise we would be comparing `master` with `master`.
<<: *if-trigger-ref-valid
script:
- *choose-ink-waterfall-repo
- *clone-repo-past-month
# Deserialize comparison data
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_SIZES_KEY 0 -1 | sort | tee $REDIS_SIZES_KEY.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_SIZES_RAND_EXT_KEY 0 -1 | sort | tee --append $REDIS_SIZES_KEY.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_SIZES_KEY_MASTER 0 -1 | sort | tee $REDIS_SIZES_KEY_MASTER.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_SIZES_RAND_EXT_KEY_MASTER 0 -1 | sort | tee --append $REDIS_SIZES_KEY_MASTER.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_GAS_USAGE_KEY 0 -1 | sort | tee $REDIS_GAS_USAGE_KEY.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_GAS_USAGE_RAND_EXT_KEY 0 -1 | sort | tee --append $REDIS_GAS_USAGE_KEY.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_GAS_USAGE_KEY_MASTER 0 -1 | sort | tee $REDIS_GAS_USAGE_KEY_MASTER.csv
- redis-cli -u $GITLAB_REDIS_URI --raw lrange $REDIS_GAS_USAGE_RAND_EXT_KEY_MASTER 0 -1 | sort | tee --append $REDIS_GAS_USAGE_KEY_MASTER.csv
- PR_COMMENTS_URL=https://api.github.com/repos/paritytech/ink/issues/${TRGR_REF}/comments
- ./scripts/ci/evaluate-examples-changes.sh $PR_COMMENTS_URL
$REDIS_SIZES_KEY_MASTER.csv $REDIS_SIZES_KEY.csv
$REDIS_GAS_USAGE_KEY_MASTER.csv $REDIS_GAS_USAGE_KEY.csv
dependencies:
- parent-vars
build_badge:
stage: compare-build
rules:
only:
refs:
- branches
- master
- tags
<<: *docker-env
before_script:
- chmod +x ./scripts/ci/get-updated-badge-info.sh
script:
- echo "building badge"
after_script:
- ./scripts/ci/get-updated-badge-info.sh
artifacts:
paths:
- badge.json
when: always
expire_in: 4 weeks