-
Notifications
You must be signed in to change notification settings - Fork 18
379 lines (329 loc) · 11.1 KB
/
Copy pathparachain-ci.yml
File metadata and controls
379 lines (329 loc) · 11.1 KB
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
name: Parachain CI
on:
push:
branches:
- dev
paths-ignore:
- "**/dependabot.yml"
- "**/README.md"
pull_request:
branches:
- dev
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
DOCKER_BUILDKIT: 1
# the branch or tag on which this workflow is triggered
# `head_ref` will only be set if the triggering event is `pull_request`
REF_VERSION: ${{ github.head_ref || github.ref_name }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-file-change:
runs-on: ubuntu-latest
# see https://github.com/orgs/community/discussions/25722
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
outputs:
src: ${{ steps.filter.outputs.src }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# Checks to see if any files in the PR/commit match one of the listed file types.
# We can use this filter to decide whether or not to build docker images
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
src:
- 'node/**'
- 'pallets/**'
- 'primitives/**'
- 'runtime/**'
- 'mock-tee-primitives/**'
- 'docker/Dockerfile'
- '**/Cargo.lock'
- '**/Cargo.toml'
- '**/rust-toolchain.toml'
check-cargo-fmt:
runs-on: ubuntu-latest
# so that the if condition on `check-file-change` propagates here
needs: check-file-change
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
target: wasm32-unknown-unknown
default: true
- name: Run cargo fmt check
run: make fmtcheck
- name: Install pre-built taplo
run: |
mkdir -p $HOME/.local/bin
wget -q https://github.com/tamasfe/taplo/releases/latest/download/taplo-linux-x86_64.gz
gzip -d taplo-linux-x86_64.gz
cp taplo-linux-x86_64 $HOME/.local/bin/taplo
chmod a+x $HOME/.local/bin/taplo
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Run taplo fmt check
run: make taplocheck
check-cargo-clippy:
runs-on: ubuntu-latest
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
target: wasm32-unknown-unknown
default: true
- name: Install dependencies
run: |
sudo apt-get update && \
sudo apt-get install -yq openssl clang libclang-dev cmake protobuf-compiler
- name: Run cargo clippy check
run: make clippy
- name: Fail-fast; cancel other jobs
if: failure()
uses: andymckay/cancel-action@0.2
build-docker:
# run the docker build on our self-hosted runner, which takes
# - 25min without cache, or
# - 15 min with cache
# on a standard github runner it takes 1 hour+
# see also https://github.com/litentry/litentry-parachain/issues/259
runs-on: self-hosted
needs: [check-cargo-fmt, check-file-change]
steps:
- name: Checkout codes
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build docker image
timeout-minutes: 60
if: needs.check-file-change.outputs.src == 'true'
run: |
./scripts/build-docker.sh release
echo "============================="
docker images
- name: Pull docker image optinally
if: needs.check-file-change.outputs.src == 'false'
run: |
docker pull litentry/litentry-parachain:latest
- name: Save docker image
run: |
docker save litentry/litentry-parachain:latest -o litentry-parachain.tar
- name: Upload docker image
uses: actions/upload-artifact@v3
with:
name: docker-artifact
path: litentry-parachain.tar
- name: Remove dangling docker images if any
run: |
[ -z "$(docker images --filter=dangling=true -q)" ] || docker rmi -f $(docker images --filter=dangling=true -q)
- name: Fail-fast; cancel other jobs
if: failure()
uses: andymckay/cancel-action@0.2
run-ts-tests:
runs-on: ubuntu-latest
needs: build-docker
strategy:
matrix:
chain:
- litmus
- litentry
- rococo
steps:
- name: Checkout codes
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: docker-artifact
- name: Load docker image
run: |
docker load -i litentry-parachain.tar
- name: Run ts tests for ${{ matrix.chain }}
timeout-minutes: 20
run: |
make test-ts-docker-${{ matrix.chain }}
- name: Archive logs if test fails
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: ${{ matrix.chain }}-ts-tests-artifacts
path: /tmp/parachain_dev/
retention-days: 3
- name: Clean up for ${{ matrix.chain }}
if: ${{ always() }}
run: |
make clean-docker-${{ matrix.chain }}
run-cargo-unit-tests:
runs-on: ubuntu-latest
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: wasm32-unknown-unknown
default: true
- name: Run unittests
run: cargo test --locked --release -p pallet-* --lib
- name: Fail-fast; cancel other jobs
if: failure()
uses: andymckay/cancel-action@0.2
run-cargo-benchmarks:
runs-on: ubuntu-latest
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: wasm32-unknown-unknown
default: true
- name: Run benchmarks
run: cargo test --locked --release -p pallet-* --lib --features runtime-benchmarks
- name: Fail-fast; cancel other jobs
if: failure()
uses: andymckay/cancel-action@0.2
# The reason why not to put the if-check on the job level is to make sure the
# *matrix* job is run, although it can be skipped in the end.
#
# This is required when setting github merge rules to protected branch,
# where you can only select one of `run-cargo-runtime-tests` and `run-cargo-runtime-tests(litmus)`.
# If you put if-check on the job level, it can't fit every possible case.
#
# Tried https://github.com/Swatinem/rust-cache too but it didn't work so well
run-cargo-runtime-tests:
runs-on: ubuntu-latest
needs: [check-cargo-fmt, check-file-change]
env:
RUSTC_WRAPPER: sccache
SCCACHE_CACHE_SIZE: 10G
SCCACHE_DIR: /home/runner/.cache/sccache
strategy:
fail-fast: true
matrix:
chain:
- litmus
- litentry
- rococo
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install toolchain
if: needs.check-file-change.outputs.src == 'true'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: wasm32-unknown-unknown
default: true
# use sccache to accelerate binary compilation
# see https://www.infinyon.com/blog/2021/04/github-actions-best-practices/
- name: Install sccache
env:
LINK: https://github.com/mozilla/sccache/releases/download
SCCACHE_VERSION: v0.3.0
run: |
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
mkdir -p $HOME/.local/bin
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
chmod +x $HOME/.local/bin/sccache
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
sudo apt-get update && \
sudo apt-get install -yq openssl clang libclang-dev cmake protobuf-compiler
- name: Cache cargo registry
if: needs.check-file-change.outputs.src == 'true'
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-${{ env.REF_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-${{ env.REF_VERSION }}-
cargo-
- name: Cache sccache
if: needs.check-file-change.outputs.src == 'true'
uses: actions/cache@v3
continue-on-error: false
with:
path: /home/runner/.cache/sccache
key: sccache-${{ env.REF_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
sccache-${{ env.REF_VERSION }}-
sccache-
- name: Run runtime integration tests
if: needs.check-file-change.outputs.src == 'true'
run: cargo test --locked --release -p ${{ matrix.chain }}-parachain-runtime --lib
- name: Print sccache stats
if: needs.check-file-change.outputs.src == 'true'
run: sccache --show-stats
- name: Fail-fast; cancel other jobs
if: failure()
uses: andymckay/cancel-action@0.2
# Secrets are not passed to the runner when a workflow is triggered from a forked repository,
# see https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
# Only push docker image when tests are passed on dev branch
push-docker-image:
runs-on: ubuntu-latest
needs:
[
"check-cargo-clippy",
"run-cargo-unit-tests",
"run-cargo-benchmarks",
"run-cargo-runtime-tests",
"run-ts-tests",
]
if: ${{ success() && (github.event_name == 'push') && (github.ref == 'refs/heads/dev') }}
steps:
- uses: actions/download-artifact@v3
with:
name: docker-artifact
- name: Load docker image
run: |
docker load -i litentry-parachain.tar
- name: Dockerhub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push docker image
run: docker push litentry/litentry-parachain:latest