-
Notifications
You must be signed in to change notification settings - Fork 20
478 lines (465 loc) · 15.2 KB
/
verify-pr-commit.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
name: Verify PR Commit
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
on:
pull_request:
branches:
- main
env:
BUILD_PROFILE: release
RUST_TOOLCHAIN: nightly-2022-09-22 # Update this when updating the Rust toolchain
jobs:
changes:
name: Determine Changed Files
runs-on: ubuntu-20.04
outputs:
rust: ${{steps.filter.outputs.rust}}
build-binary: ${{steps.filter.outputs.build-binary}}
cargo-lock: ${{steps.filter.outputs.cargo-lock}}
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Check for Changed Files
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
rust:
- '**/*.rs'
- '**/*.hbs'
- '.rustfmt.toml'
- '**/Cargo.toml'
- '**/Cargo.lock'
build-binary:
- '**/*.rs'
- '**/*.hbs'
- '.rustfmt.toml'
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'js/api-augment/**'
cargo-lock:
- '**/Cargo.toml'
- '**/Cargo.lock'
build-binary:
needs: changes
if: needs.changes.outputs.build-binary == 'true'
name: Compile Frequency Project
runs-on: [self-hosted, Linux, X64]
env:
NETWORK: mainnet
steps:
- name: Set Env Vars
run: |
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
echo "BUILT_BIN_FILENAME=frequency" >> $GITHUB_ENV
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Check Out Repo
uses: actions/checkout@v3
# # XXX Keep this step as it lets us skip full binary builds during development/testing
# - name: Cache Binary for Testing
# id: cache-binary
# uses: actions/cache@v3
# with:
# path: ${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}
# key: ${{runner.os}}-${{env.NETWORK}}-${{github.ref_name}}
- name: Install Rust Toolchain
if: steps.cache-binary.outputs.cache-hit != 'true'
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
target: wasm32-unknown-unknown
toolchain: stable
- name: Cache Rust Dependencies
if: steps.cache-binary.outputs.cache-hit != 'true'
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{env.RUST_TOOLCHAIN}}
- name: Compile Binary
if: steps.cache-binary.outputs.cache-hit != 'true'
run: |
CARGO_INCREMENTAL=0 RUSTFLAGS="-D warnings" cargo build --locked --release \
--features frequency
- name: Run Sanity Checks
working-directory: ${{env.BIN_DIR}}
run: |
ls -la
file ${{env.BUILT_BIN_FILENAME}} && \
./${{env.BUILT_BIN_FILENAME}} --version
- name: Archive Artifact
run: |
tar -cvf frequency-binary-${{env.NETWORK}}-${{github.sha}}.amd64.tar \
${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: artifacts-${{github.run_id}}
path: frequency-binary-${{env.NETWORK}}-${{github.sha}}.amd64.tar
if-no-files-found: error
check-for-vulnerable-crates:
needs: changes
if: needs.changes.outputs.cargo-lock == 'true'
name: Check for Vulnerable Crates
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Set Up Cargo Deny
run: |
cargo install --force cargo-deny
cargo generate-lockfile
- name: Run Cargo Deny
run: cargo deny check --hide-inclusion-graph -c .cargo-deny.toml
verify-rust-code-format:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Rust Code Format
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
components: rustfmt
toolchain: stable
- name: Check
run: cargo fmt --check
lint-rust-code:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Lint Rust Code
runs-on: [self-hosted, Linux, X64]
steps:
- name: Set Env Vars
run: |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
components: clippy
toolchain: stable
- name: Lint
run: |
SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy \
--features all-frequency-features \
-- \
-D warnings
verify-rust-developer-docs:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Rust Developer Docs
runs-on: [self-hosted, Linux, X64]
steps:
- name: Set Env Vars
run: |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
profile: minimal
target: wasm32-unknown-unknown
- name: Cache Rust Dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{env.RUST_TOOLCHAIN}}
- name: Build Rust Docs
run: RUSTDOCFLAGS="--enable-index-page --check -Zunstable-options" cargo doc --no-deps --all-features
verify-rust-packages-and-deps:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Rust Packages and Dependencies
runs-on: [self-hosted, Linux, X64]
steps:
- name: Set Env Vars
run: |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
toolchain: stable
- name: Check
run: SKIP_WASM_BUILD= cargo check --all-features
run-rust-tests:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Run Rust Tests
runs-on: [self-hosted, Linux, X64]
steps:
- name: Set Env Vars
run: |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
target: wasm32-unknown-unknown
toolchain: stable
- name: Restore Dependencies from Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{env.RUST_TOOLCHAIN}}
- name: Run Tests
run: cargo test --all-features --workspace --release
calc-code-coverage:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Calculate Code Coverage
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
target: wasm32-unknown-unknown
toolchain: stable
- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
with:
version: "0.22.0"
# Tarpaulin Docs https://github.com/xd009642/tarpaulin
# -e for exclude
args: |
-v --no-fail-fast --workspace
-e frequency frequency-cli frequency-runtime frequency-service
--exclude-files **/mock.rs **/weights.rs **/weights/* **/benchmarking.rs
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)
verify-build-runtimes:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Build Runtime for ${{matrix.network}}
strategy:
matrix:
network: [rococo, mainnet]
include:
- network: rococo
build-profile: production
package: frequency-runtime
runtime-dir: runtime/frequency
features: frequency-rococo-testnet
- network: mainnet
build-profile: production
package: frequency-runtime
runtime-dir: runtime/frequency
features: frequency
runs-on: [self-hosted, Linux, X64]
steps:
- name: Set Ubuntu Env Vars
run: |
echo "HOME=/home/ubuntu" >> $GITHUB_ENV
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
toolchain: stable
- name: Install Docker
run: |
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
- name: Prune Docker Resources
run: |
set -ex
docker system prune -a --volumes -f
docker container prune -f
docker image prune -a -f
docker container ls
docker image ls
- name: Extract Runtime Spec Version
run: |
echo "RUNTIME_SPEC_VERSION=$(sed -nr 's/spec_version:\s*([0-9]+),/\1/p' \
${{matrix.runtime-dir}}/src/lib.rs | tr -d '[:space:]')" >> $GITHUB_ENV
- name: Validate Extracted Version
run: |
echo "Runtime Spec Version:|${{env.RUNTIME_SPEC_VERSION}}|"
echo "Runtime Spec Version:||$RUNTIME_SPEC_VERSION||"
[[ $RUNTIME_SPEC_VERSION == ?(-)+([0-9]) ]] || \
(echo "ERROR: \"${{env.RUNTIME_SPEC_VERSION}}\" is not a valid integer" && exit 10)
- name: Set Env Vars
run: |
echo "WASM_DIR=${{matrix.runtime-dir}}/target/srtool/${{matrix.build-profile}}/wbuild/${{matrix.package}}" >> $GITHUB_ENV
# # XXX Keep this step as it lets us skip WASM builds during development/testing
# - name: Cache WASM for Testing
# id: cache-wasm
# uses: actions/cache@v3
# with:
# path: ${{env.WASM_DIR}}/${{env.BUILT_WASM_FILENAME}}
# key: ${{runner.os}}-${{matrix.network}}-${{env.NEW_RELEASE_VERSION}}
- name: Install srtool-cli
run: |
cargo install --git https://github.com/chevdor/srtool-cli
srtool --version
- name: Build Deterministic WASM
run: |
set -ex
srtool build \
--default-features="on-chain-release-build,no-metadata-docs,${{matrix.features}}" \
--profile=${{matrix.build-profile}} \
--package=${{matrix.package}} \
--root
verify-js-api-augment:
needs:
- build-binary
name: Verify JS API Augment
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Set up NodeJs
uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
cache-dependency-path: js/api-augment/package-lock.json
- name: Install Latest Versions
run: npm install # DO NOT use `npm ci` as we want the latest polkadot/api possible
working-directory: js/api-augment
- name: Lint
run: npm run lint
working-directory: js/api-augment
- name: Download Binary Artifacts
id: download
uses: actions/download-artifact@v3
with:
name: artifacts-${{github.run_id}}
path: .
- name: Extract Binary
run: |
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
- name: Output Metadata
run: target/${{env.BUILD_PROFILE}}/frequency export-metadata ./js/api-augment/metadata.json
- name: Build
run: npm run build
working-directory: js/api-augment
- name: Test
run: npm test
working-directory: js/api-augment
- name: Build & Publish Dry Run
run: npm publish --dry-run
working-directory: js/api-augment/dist
verify-docker-images:
needs: build-binary
name: Verify Docker Images
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
toolchain: stable
- name: Restore Dependencies from Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{env.RUST_TOOLCHAIN}}
- name: Download Binary Artifacts
id: download
uses: actions/download-artifact@v3
with:
name: artifacts-${{github.run_id}}
path: .
- name: Extract Binary
run: |
ls -la
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: "amd64"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build collator image in instant seal mode
env:
IMAGE_NAME: instant-seal-node
uses: docker/build-push-action@v3
with:
context: .
push: false
file: ./docker/${{env.IMAGE_NAME}}.dockerfile
- name: Build collator image for local relay chain
env:
IMAGE_NAME: collator-node-local
uses: docker/build-push-action@v3
with:
context: .
push: false
file: docker/${{env.IMAGE_NAME}}.dockerfile
execute-binary-checks:
needs: build-binary
name: Execute Binary Checks
runs-on: ubuntu-20.04
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
default: true
profile: minimal
toolchain: stable
- name: Download Binary Artifacts
id: download
uses: actions/download-artifact@v3
with:
name: artifacts-${{github.run_id}}
path: .
- name: Extract Binary
run: |
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
- name: Output Binary Version
run: |
file ./target/${{env.BUILD_PROFILE}}/frequency && \
./target/${{env.BUILD_PROFILE}}/frequency --version