-
Notifications
You must be signed in to change notification settings - Fork 19
904 lines (882 loc) · 36 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
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Verify PR Commit
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
on:
pull_request:
branches:
- main
- "*-development" # Feature Branches should suffix with -development
env:
BIN_DIR: target/release
PR_LABEL_METADATA_CHANGED: metadata-changed
PR_LABEL_METADATA_VERSION_NOT_INCREMENTED: metadata-version-not-incremented
jobs:
changes:
name: Determine Changed Files
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
outputs:
rust: ${{steps.filter.outputs.rust}}
build-binary: ${{steps.filter.outputs.build-binary}}
cargo-lock: ${{steps.filter.outputs.cargo-lock}}
run-e2e: ${{steps.filter.outputs.run-e2e}}
ci-docker-image: ${{steps.filter.outputs.ci-docker-image}}
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Check for Changed Files
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a
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/**'
- 'e2e/**/*.{ts,json}'
cargo-lock:
- '**/Cargo.toml'
- '**/Cargo.lock'
run-e2e:
- '**/*.rs'
- '**/Cargo.toml'
- 'e2e/**/*.{ts,json}'
ci-docker-image:
- 'tools/ci/docker/ci-base-image.dockerfile'
clear-metadata-labels:
name: Clear Metadata Labels
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Clear Metadata Changed Label
if: contains(github.event.pull_request.labels.*.name, env.PR_LABEL_METADATA_CHANGED)
uses: RobinJesba/GitHub-Labeler-Action@2f69380bbf2ee60b2f0893ef0f40582c9a34a64d
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS_TO_REMOVE: ${{env.PR_LABEL_METADATA_CHANGED}}
- name: Clear Metadata Version Not Incremented Label
if: contains(github.event.pull_request.labels.*.name, env.PR_LABEL_METADATA_VERSION_NOT_INCREMENTED)
uses: RobinJesba/GitHub-Labeler-Action@2f69380bbf2ee60b2f0893ef0f40582c9a34a64d
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS_TO_REMOVE: ${{env.PR_LABEL_METADATA_VERSION_NOT_INCREMENTED}}
# Workaround to handle skipped required check inside matrix
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks
build-binaries-dummy:
needs: changes
if: needs.changes.outputs.build-binary != 'true'
runs-on: ubuntu-22.04
name: Build ${{matrix.network}} Binary on ${{matrix.branch_alias}} Branch
strategy:
matrix:
# Match this to the real build-binaries job
include:
- network: dev
git_branch: ${{github.head_ref}}
spec: frequency-no-relay
branch_alias: pr
- network: local
git_branch: ${{github.head_ref}}
spec: frequency-local
branch_alias: pr
- network: local
git_branch: main
spec: frequency-local
branch_alias: main
- network: testnet
spec: frequency-testnet
branch_alias: pr
- network: mainnet
spec: frequency
branch_alias: pr
steps:
- run: echo "Just a dummy matrix to satisfy GitHub required checks that were skipped"
build-binaries:
needs: changes
if: needs.changes.outputs.build-binary == 'true'
name: Build ${{matrix.network}} Binary on ${{matrix.branch_alias}} Branch
strategy:
fail-fast: true
matrix:
include:
- network: dev
git_branch: ${{github.head_ref}}
spec: frequency-no-relay
branch_alias: pr
- network: local
git_branch: ${{github.head_ref}}
spec: frequency-local
branch_alias: pr
- network: local
git_branch: main
spec: frequency-local
branch_alias: main
- network: testnet
spec: frequency-testnet
branch_alias: pr
- network: mainnet
spec: frequency
branch_alias: pr
runs-on: [self-hosted, Linux, X64, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
env:
NETWORK: mainnet
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{matrix.git_branch}}
- name: Set Env Vars
run: |
export BUILT_BIN_FILENAME=frequency; echo "BUILT_BIN_FILENAME=$BUILT_BIN_FILENAME" >> $GITHUB_ENV
echo "FINAL_BIN_FILENAME=$BUILT_BIN_FILENAME.${{matrix.network}}.${{matrix.spec}}.${{matrix.branch_alias}}" >> $GITHUB_ENV
# # 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.FINAL_BIN_FILENAME}}
# key: binaries-${{runner.os}}-${{env.NETWORK}}-${{github.head_ref}}
- name: Compile Binary
if: steps.cache-binary.outputs.cache-hit != 'true'
run: |
CARGO_INCREMENTAL=0 RUSTFLAGS="-D warnings" cargo build --locked --release \
--features ${{matrix.spec}}
- name: Run Sanity Checks
if: steps.cache-binary.outputs.cache-hit != 'true'
working-directory: ${{env.BIN_DIR}}
run: |
file ${{env.BUILT_BIN_FILENAME}} && \
./${{env.BUILT_BIN_FILENAME}} --version
- name: Rename Reference Binary
if: steps.cache-binary.outputs.cache-hit != 'true'
working-directory: ${{env.BIN_DIR}}
run: cp ${{env.BUILT_BIN_FILENAME}} ${{env.FINAL_BIN_FILENAME}}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-binary-${{matrix.network}}-${-${{github.run_id}}
path: ${{env.BIN_DIR}}/${{env.FINAL_BIN_FILENAME}}*
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-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set Up Cargo Deny
run: |
cargo install --force --locked cargo-deny
cargo generate-lockfile
- name: Run Cargo Deny
run: cargo deny check --hide-inclusion-graph -c deny.toml
verify-rust-code-format:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Rust Code Format
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Check
run: |
cargo +nightly-2024-03-01 fmt --check
lint-rust-code:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Lint Rust Code
runs-on: [self-hosted, Linux, X64, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Lint
run: |
SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy \
--features runtime-benchmarks,frequency-lint-check \
-- \
-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, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Build Docs
run: |
rustup target add wasm32-unknown-unknown --toolchain nightly-2024-03-01
RUSTDOCFLAGS="--enable-index-page --check -Zunstable-options" cargo +nightly-2024-03-01 doc --no-deps --features frequency
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, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Check
run: SKIP_WASM_BUILD= cargo check --features runtime-benchmarks,frequency-lint-check
run-rust-tests:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Run Rust Tests
runs-on: [self-hosted, Linux, X64, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Init Git
run: |
git config --global --add safe.directory /__w/frequency/frequency
- name: Run Tests
run: cargo test --features runtime-benchmarks,frequency-lint-check --workspace --release
calc-code-coverage:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Calculate Code Coverage
runs-on: [self-hosted, Linux, X64, build, v2]
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Generate and Upload Code Coverage
id: codecov
uses: ./.github/workflows/common/codecov
with:
code-cov-token: ${{ secrets.CODECOV_TOKEN }}
# Workaround to handle skipped required check inside matrix
# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks
verify-build-runtimes-dummy:
needs: changes
if: needs.changes.outputs.rust != 'true'
name: Verify Build Runtime for ${{matrix.network}}
strategy:
matrix:
# Should match `verify-build-runtimes`
network: [dev, rococo, paseo, mainnet]
runs-on: ubuntu-22.04
steps:
- run: echo "Just a dummy matrix to satisfy GitHub required checks that were skipped"
# Could not port this job to container because this creates docker-in-docker
# situation and fails when srtool-ci container is trying to process files in
# the mapped volume which don't exist on the host
verify-build-runtimes:
needs: changes
if: needs.changes.outputs.rust == 'true'
name: Verify Build Runtime for ${{matrix.network}}
strategy:
fail-fast: true
matrix:
# Remember, runtimes are separate for each relay chain
# We do not release frequency-*-local runtimes however
# Also should match `verify-build-runtimes-dummy`
network: [dev, rococo, paseo, mainnet]
include:
- network: dev
build-profile: release
package: frequency-runtime
runtime-dir: runtime/frequency
built-wasm-file-name-prefix: frequency_runtime
features: frequency-no-relay
wasm-core-version: frequency-testnet
- network: rococo
build-profile: release
package: frequency-runtime
runtime-dir: runtime/frequency
built-wasm-file-name-prefix: frequency_runtime
features: frequency-testnet
wasm-core-version: frequency-testnet
- network: paseo
build-profile: release
package: frequency-runtime
runtime-dir: runtime/frequency
built-wasm-file-name-prefix: frequency_runtime
features: frequency-testnet
wasm-core-version: frequency-testnet
- network: mainnet
build-profile: release
package: frequency-runtime
runtime-dir: runtime/frequency
built-wasm-file-name-prefix: frequency_runtime
features: frequency
wasm-core-version: frequency
runs-on: [self-hosted, Linux, X64, build, v2]
steps:
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y wget file build-essential curl
- name: Check Out Repo
uses: actions/checkout@v4
- name: Install Rust Toolchain
# Match installation steps to CI base docker image
run: |
curl https://sh.rustup.rs -sSf | bash -s -- -y
echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
- name: Extract Runtime Spec Version
run: |
echo "RUNTIME_SPEC_VERSION=$(awk '/spec_version:/ {match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit}' \
${{matrix.runtime-dir}}/src/lib.rs)" >> $GITHUB_ENV
- name: Validate Extracted Version
shell: bash
run: |
echo "Runtime Spec Version: ${{env.RUNTIME_SPEC_VERSION}}"
[[ $RUNTIME_SPEC_VERSION == ?(-)+([0-9]) ]] || \
(echo "ERROR: \"${{env.RUNTIME_SPEC_VERSION}}\" is not a valid integer" && exit 1)
- name: Set Env Vars
run: |
echo "WASM_DIR=${{matrix.runtime-dir}}/target/srtool/${{matrix.build-profile}}/wbuild/${{matrix.package}}" >> $GITHUB_ENV
echo "BUILT_WASM_FILENAME=${{matrix.built-wasm-file-name-prefix}}.compact.compressed.wasm" >> $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: runtimes-${{runner.os}}-${{matrix.network}}-${{github.head_ref}}
- name: Install srtool-cli
if: steps.cache-wasm.outputs.cache-hit != 'true'
run: |
rustup show
cargo install --locked --git https://github.com/chevdor/srtool-cli
echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
- name: Test srtool-cli Install
run: |
echo "PATH: $PATH"
which srtool
srtool --version
- name: Build Deterministic WASM
if: steps.cache-wasm.outputs.cache-hit != 'true'
run: |
RUST_LOG=debug SRTOOL_TAG="1.75.0" srtool build \
--build-opts="'--features on-chain-release-build,no-metadata-docs,${{matrix.features}}'" \
--profile=${{matrix.build-profile}} \
--package=${{matrix.package}}
- name: Check Deterministic WASM Build Exists
if: steps.cache-wasm.outputs.cache-hit != 'true'
run: file ${{env.WASM_DIR}}/${{env.BUILT_WASM_FILENAME}}
- name: Install Subwasm
run: |
cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.19.1 --force
subwasm --version
- name: Test WASM file
run: |
subwasm info ${{env.WASM_DIR}}/${{env.BUILT_WASM_FILENAME}}
subwasm info ${{env.WASM_DIR}}/${{env.BUILT_WASM_FILENAME}} | grep "Core version:.*${{matrix.wasm-core-version}}-${{env.RUNTIME_SPEC_VERSION}}" || \
(echo "ERROR: WASM Core version didn't match ${{matrix.wasm-core-version}}-${{env.RUNTIME_SPEC_VERSION}}" && exit 1)
verify-js-api-augment:
needs: build-binaries
name: Verify JS API Augment
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set Env Vars
run: |
echo "BIN_FILENAME=frequency.local.frequency-local.pr" >> $GITHUB_ENV
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 18
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 Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Set Binary Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 ${{env.BIN_FILENAME}}
- name: Output Metadata
run: ${{env.BIN_DIR}}/${{env.BIN_FILENAME}} export-metadata --chain=frequency-paseo-local --tmp ./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
- name: Generate npm tarball
run: npm pack
working-directory: js/api-augment/dist
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-api-augment-${{github.run_id}}
path: js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz
if-no-files-found: error
verify-node-docker-images:
needs: build-binaries
name: Verify Node Docker Images
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set Env Vars
run: |
echo "BUILT_BIN_FILENAME=frequency.mainnet.frequency.pr" >> $GITHUB_ENV
echo "DOCKER_BIN_FILENAME=frequency" >> $GITHUB_ENV
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Rename Binary
working-directory: ${{env.BIN_DIR}}
run: mv ${{env.BUILT_BIN_FILENAME}} ${{env.DOCKER_BIN_FILENAME}}
- name: Set Binary Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 ${{env.DOCKER_BIN_FILENAME}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: "amd64"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build collator image in instant seal mode
env:
IMAGE_NAME: instant-seal-node
uses: docker/build-push-action@v5
with:
context: .
push: false
file: ./docker/${{env.IMAGE_NAME}}.dockerfile
- name: Build collator standalone
env:
IMAGE_NAME: standalone-node
uses: docker/build-push-action@v5
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@v5
with:
context: .
push: false
file: docker/${{env.IMAGE_NAME}}.dockerfile
verify-ci-docker-image:
needs: changes
if: needs.changes.outputs.ci-docker-image == 'true'
name: Verify CI Docker Image
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: "amd64"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build CI image
env:
IMAGE_PATH: tools/ci/docker
IMAGE_NAME: ci-base-image
uses: docker/build-push-action@v5
with:
context: .
push: false
file: ${{env.IMAGE_PATH}}/${{env.IMAGE_NAME}}.dockerfile
execute-binary-checks:
needs: build-binaries
name: Execute Binary Checks
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set Env Vars
run: |
echo "TEST_BIN_FILENAME=frequency.mainnet.frequency.pr" >> $GITHUB_ENV
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Set Binary Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 ${{env.TEST_BIN_FILENAME}}
- name: Output Binary Version
working-directory: ${{env.BIN_DIR}}
run: |
file ./${{env.TEST_BIN_FILENAME}} && ./${{env.TEST_BIN_FILENAME}} --version
check-metadata-and-spec-version:
needs: build-binaries
name: Check Metadata and Spec Version
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Env Vars
run: |
echo "TEST_BIN_FILENAME=frequency.local.frequency-local.pr" >> $GITHUB_ENV
echo "REF_BIN_FILENAME=frequency.local.frequency-local.main" >> $GITHUB_ENV
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Set Binary Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 $TEST_BIN_FILENAME
chmod 755 $REF_BIN_FILENAME
- name: Compare Metadata
id: compare-metadata
working-directory: ${{env.BIN_DIR}}
run: |
set -x
./$REF_BIN_FILENAME export-metadata --chain=frequency-paseo-local --tmp metadata-ref.json
metadata_ref=$(cat metadata-ref.json | jq -r .result)
./$TEST_BIN_FILENAME export-metadata --chain=frequency-paseo-local --tmp metadata.json
metadata=$(cat metadata.json | jq -r .result)
matches=$([ "$metadata" = "$metadata_ref" ] && echo 'true' || echo 'false')
echo "Metadata matches?: $match"
echo "metadata_matches=$matches" >> $GITHUB_OUTPUT
- name: Assign Metadata Changed Label
if: steps.compare-metadata.outputs.metadata_matches != 'true'
uses: RobinJesba/GitHub-Labeler-Action@2f69380bbf2ee60b2f0893ef0f40582c9a34a64d
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS_TO_ADD: ${{env.PR_LABEL_METADATA_CHANGED}}
- name: Check Spec Version
if: steps.compare-metadata.outputs.metadata_matches != 'true'
id: check-spec-version
working-directory: ${{env.BIN_DIR}}
run: |
set -x
spec_version_ref=$(./$REF_BIN_FILENAME export-runtime-version | jq -r .specVersion)
spec_version=$(./$TEST_BIN_FILENAME export-runtime-version | jq -r .specVersion)
incremented=$([ $spec_version -gt $spec_version_ref ] && echo 'true' || echo 'false')
echo "spec_version_ref=$spec_version_ref" >> $GITHUB_OUTPUT
echo "spec_version=$spec_version" >> $GITHUB_OUTPUT
echo "metadata_version_incremented=$incremented" >> $GITHUB_OUTPUT
- name: Assign Metadata Version Not Incremented Label
if: |
(steps.compare-metadata.outputs.metadata_matches != 'true') &&
(steps.check-spec-version.outputs.metadata_version_incremented != 'true')
uses: RobinJesba/GitHub-Labeler-Action@2f69380bbf2ee60b2f0893ef0f40582c9a34a64d
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS_TO_ADD: ${{env.PR_LABEL_METADATA_VERSION_NOT_INCREMENTED}}
- name: Fail CI
if: |
(steps.compare-metadata.outputs.metadata_matches != 'true') &&
(steps.check-spec-version.outputs.metadata_version_incremented != 'true')
working-directory: ${{env.BIN_DIR}}
run: |
spec_version=${{steps.check-spec-version.outputs.spec_version}}
spec_version_ref=${{steps.check-spec-version.outputs.spec_version_ref}}
echo "ERROR: When metadata is updated, the new spec version ($spec_version)\
must be greater than the latest version on main branch ($spec_version_ref)"
exit 1
run-e2e:
if: needs.changes.outputs.run-e2e == 'true'
needs: [build-binaries, verify-js-api-augment]
name: Run E2E Tests
runs-on: [self-hosted, Linux, X64, build, v2]
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Env Vars
run: |
echo "BIN_FILENAME=frequency.dev.frequency-no-relay.pr" >> $GITHUB_ENV
echo "FREQUENCY_PROCESS_NAME=frequency" >> $GITHUB_ENV
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Download api-augment tarball
uses: actions/download-artifact@v4
with:
name: artifacts-api-augment-${{github.run_id}}
path: js/api-augment/dist
- name: Set Binaries Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 $BIN_FILENAME
- name: Start Local Node
working-directory: ${{env.BIN_DIR}}
run: |
./${{env.BIN_FILENAME}} \
-lruntime=debug \
--dev \
--sealing=instant \
--wasm-execution=compiled \
--no-telemetry \
--no-prometheus \
--port $((30333)) \
--rpc-port $((9944)) \
--rpc-external \
--rpc-cors all \
--rpc-methods=Unsafe \
--tmp \
&
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
cache-dependency-path: e2e/package-lock.json
- name: Install Built api-augment
run: npm install ../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz
working-directory: e2e
- name: Install NPM Modules
run: npm ci
working-directory: e2e
- name: Lint
run: npm run lint
working-directory: e2e
- name: Run E2E Tests
working-directory: e2e
env:
CHAIN_ENVIRONMENT: dev
WS_PROVIDER_URL: ws://127.0.0.1:9944
run: npm test
- name: Stop Local Node
if: always()
run: pkill ${{env.FREQUENCY_PROCESS_NAME}}
verify-genesis-state:
needs: build-binaries
name: Verify Genesis State
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
steps:
- name: Set Env Vars
run: |
echo "EXPECTED_GENESIS_STATE_PASEO=0x000000000000000000000000000000000000000000000000000000000000000000d1912c5cd40e89fe2f4e1391801d17f6905cf84d961cbf4abb49139f03c2d85503170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400" >> $GITHUB_ENV
echo "EXPECTED_GENESIS_STATE_ROCOCO=0x000000000000000000000000000000000000000000000000000000000000000000e3495742b019f5ad49dff7de4040bc965b75eaf46769c24db1027d4ff86fc92703170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400" >> $GITHUB_ENV
echo "EXPECTED_GENESIS_STATE_MAINNET=0x000000000000000000000000000000000000000000000000000000000000000000393a2a0f7778716d006206c5a4787cbf2ea3b26a67379b7a38ee54519d7fd4be03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400" >> $GITHUB_ENV
echo "BIN_FILENAME_TESTNET=frequency.testnet.frequency-testnet.pr" >> $GITHUB_ENV
echo "BIN_FILENAME_MAINNET=frequency.mainnet.frequency.pr" >> $GITHUB_ENV
- name: Download Binaries
id: download-binaries
uses: actions/download-artifact@v4
with:
pattern: artifacts-binary-*-${{github.run_id}}
path: ${{env.BIN_DIR}}
merge-multiple: true
- name: List Downloaded Binaries
run: |
download_dir=${{steps.download-binaries.outputs.download-path}}
echo "Download dir: $download_dir"
echo "Downloaded binaries: $(ls -l $download_dir)"
- name: Set Binary Permissions
working-directory: ${{env.BIN_DIR}}
run: |
chmod 755 $BIN_FILENAME_TESTNET
chmod 755 $BIN_FILENAME_MAINNET
- name: Test Frequency Rococo Genesis State
working-directory: ${{env.BIN_DIR}}
run: |
expected_genesis_state=${{env.EXPECTED_GENESIS_STATE_ROCOCO}}
echo "Expected genesis state: $expected_genesis_state"
actual_genesis_state=$(./${{env.BIN_FILENAME_TESTNET}} export-genesis-state --chain=frequency-rococo)
echo "Actual genesis state: $actual_genesis_state"
[ $actual_genesis_state = $expected_genesis_state ] || \
(echo "ERROR: The actual genesis state does not match the expected" && exit 1)
- name: Test Frequency Paseo Genesis State
working-directory: ${{env.BIN_DIR}}
run: |
expected_genesis_state=${{env.EXPECTED_GENESIS_STATE_PASEO}}
echo "Expected genesis state: $expected_genesis_state"
actual_genesis_state=$(./${{env.BIN_FILENAME_TESTNET}} export-genesis-state --chain=frequency-paseo)
echo "Actual genesis state: $actual_genesis_state"
[ $actual_genesis_state = $expected_genesis_state ] || \
(echo "ERROR: The actual genesis state does not match the expected" && exit 1)
- name: Test Frequency Mainnet Genesis State
working-directory: ${{env.BIN_DIR}}
run: |
expected_genesis_state=${{env.EXPECTED_GENESIS_STATE_MAINNET}}
echo "Expected genesis state: $expected_genesis_state"
actual_genesis_state=$(./${{env.BIN_FILENAME_MAINNET}} export-genesis-state)
echo "Actual genesis state: $actual_genesis_state"
[ $actual_genesis_state = $expected_genesis_state ] || \
(echo "ERROR: The actual genesis state does not match the expected" && exit 1)
should-run-benchmarks:
if: github.repository == 'LibertyDSNP/frequency'
name: Run Benchmarks?
runs-on: ubuntu-22.04
container: ghcr.io/libertydsnp/frequency/ci-base-image:latest
outputs:
should_run_benchmarks: ${{steps.run-benchmarks.outputs.run}}
pallets: ${{steps.run-benchmarks.outputs.pallets}}
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- name: Run Benchmarks?
id: run-benchmarks
shell: bash
run: |
git config --global --add safe.directory /__w/frequency/frequency
commit_message=$(git show -s --format=%s)
echo "commit_message: $commit_message"
regex='\[run-benchmarks (.*)\]$'
if [[ $commit_message =~ $regex ]]; then
echo "Yes, need to run benchmarks."
pallets="${BASH_REMATCH[1]}"
echo "Pallets: $pallets"
echo "run=true" >> $GITHUB_OUTPUT
echo "pallets=$pallets" >> $GITHUB_OUTPUT
else
echo "No, do not need to run benchmarks."
echo "run=false" >> $GITHUB_OUTPUT
fi
run-benchmarks:
if: github.repository == 'LibertyDSNP/frequency' &&
needs.should-run-benchmarks.outputs.should_run_benchmarks == 'true'
needs: should-run-benchmarks
name: Run Benchmarks
runs-on: [self-hosted, Linux, X64, benchmark]
steps:
- name: Print Info
run: |
echo "Running benchmarks..."
echo "Pallets: ${{needs.should-run-benchmarks.outputs.pallets}}"
- name: Check Out Repo
uses: actions/checkout@v4
with:
token: ${{secrets.GHA_GIT_COMMIT || github.token}}
ref: ${{github.event.pull_request.head.sha}}
- name: Get Current Job Log URL
id: jobs
uses: Tiryoh/gha-jobid-action@7528cee9716384209bafcbd000d6689e851c5dda
with:
github_token: ${{secrets.GITHUB_TOKEN}}
job_name: "Run Benchmarks"
- name: Set PR Commit Status to Pending
uses: ouzi-dev/commit-status-updater@219d3f932547cad092e384c7a36bf4d963739c35
with:
name: "GithubActions - Run Benchmarks"
status: "pending"
addHoldComment: "true"
pendingComment: >-
:hourglass_flowing_sand: [Running benchmarks](${{steps.jobs.outputs.html_url}})
and calculating weights. DO NOT MERGE! A new commit will be added upon completion...
failComment: "ERROR: Failed to set PR commit to pending status!"
- name: Install Required Packages
run: |
sudo apt-get update
sudo apt install -y protobuf-compiler libclang-dev clang cmake
- name: Install Rust Toolchain
# Match installation steps to CI base docker image
run: |
curl https://sh.rustup.rs -sSf | bash -s -- -y
echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
- name: Update Weights
run: |
rustup show
pallets_str="${{needs.should-run-benchmarks.outputs.pallets}}"
echo "Pallets: $pallets_str"
if [ -z "${pallets_str}" -o $pallets_str = 'all' ]; then
echo "Running benchmarks for all pallets..."
make benchmarks
else
IFS=',' read -r -a pallets <<< "$pallets_str"
echo "Running benchmarks for pallets: ${pallets[*]}..."
make benchmarks-multi PALLETS="${pallets[*]}"
echo "Finished benchmarks for pallets: ${pallets[*]}."
fi
- name: Print Updated Weights
run: |
git status
git diff
- name: Commit Updated Weights
id: commit-updated-weights
uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d
with:
commit_message: "Update weights for PR #${{github.event.pull_request.number}}"
commit_user_name: Frequency CI [bot]
commit_user_email: [email protected]
commit_author: Frequency CI [bot] <[email protected]>
- name: Set PR Commit Status to Success
uses: ouzi-dev/commit-status-updater@219d3f932547cad092e384c7a36bf4d963739c35
with:
name: "GithubActions - Run Benchmarks"
status: "success"
addHoldComment: "true"
successComment: >-
:white_check_mark: [Finished running benchmarks](${{steps.jobs.outputs.html_url}}).
Updated weights have been committed to this PR branch in
commit ${{steps.commit-updated-weights.outputs.commit_hash}}.
failComment: "ERROR: Failed to set PR commit to success status!"