-
Notifications
You must be signed in to change notification settings - Fork 337
934 lines (885 loc) · 37.1 KB
/
build.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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
name: Build
# Using a single file workflow is the preferred solution for our CI over workflow_runs.
# 1. It generates only 1 action item in the list making it more readable
# 2. It includes the PR/Commit text in the action item
# 3. Artifacts are not available between workflows.
on:
pull_request:
push:
branches:
- master
- perm-*
workflow_dispatch:
inputs:
pull_request:
description: set to pull_request number to execute on external pr
required: false
env:
NODE_OPTIONS: "--max-old-space-size=12288 --no-deprecation"
CARGO_TERM_COLOR: always
jobs:
####### Check files and formatting #######
set-tags:
runs-on: ubuntu-latest
outputs:
git_branch: ${{ steps.check-git-ref.outputs.git_branch }}
git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
test_s3_dir: ${{ steps.check-git-ref.outputs.test_s3_dir }}
image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
sha: ${{ steps.get-sha.outputs.sha }}
sha8: ${{ steps.get-sha.outputs.sha8 }}
polkadot_repo: ${{ steps.get-sha.outputs.polkadot_repo }}
polkadot_commit: ${{ steps.get-sha.outputs.polkadot_commit }}
polkadot_ver: ${{ steps.get-sha.outputs.polkadot_ver}}
latest_rt: ${{ steps.get-sha.outputs.latest_rt }}
latest_rt_sha8: ${{ steps.get-sha.outputs.latest_rt_sha8 }}
steps:
- name: Check git ref
id: check-git-ref
# if PR
# else if manual PR
# else (push)
run: |
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
echo "git_ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
echo "test_s3_dir=test-pulls/${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
elif [[ -n "${{ github.event.inputs.pull_request }}" ]]; then
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
echo "test_s3_dir=test-pulls/${{ github.event.inputs.pull_request }}" >> $GITHUB_OUTPUT
echo "git_ref=refs/pull/${{ github.event.inputs.pull_request }}/head" >> $GITHUB_OUTPUT
else
echo "test_s3_dir=test-branches/master" >> $GITHUB_OUTPUT
echo "git_branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
echo "git_ref=$GITHUB_REF" >> $GITHUB_OUTPUT
fi
echo "repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}"
echo "github.repository: ${{ github.repository }}"
- uses: actions/checkout@v4
with:
ref: ${{ steps.check-git-ref.outputs.git_ref }}
- name: Get Latest RT Release
id: get-latest-rt
run: |
LATEST_RUNTIME_RELEASE=$(curl -s https://api.github.com/repos/moonbeam-foundation/moonbeam/releases | jq -r '.[] | select(.name | test("runtime";"i")) | .tag_name' | sort -rs | head -n 1 | tr -d '[:blank:]') && [[ ! -z "${LATEST_RUNTIME_RELEASE}" ]]
echo $LATEST_RUNTIME_RELEASE
echo "latest_rt=$LATEST_RUNTIME_RELEASE" >> $GITHUB_OUTPUT
- name: Get Sha
id: get-sha
run: |
echo "sha=$(git log -1 --format='%H')" >> $GITHUB_OUTPUT
echo "sha8=$(git log -1 --format='%H' | cut -c1-8)" >> $GITHUB_OUTPUT
echo "polkadot_repo=$(egrep -o 'https.*/polkadot' Cargo.lock | head -1)" >> $GITHUB_OUTPUT
echo "polkadot_commit=$(egrep -o '/polkadot.*#([^\"]*)' Cargo.lock | \
head -1 | sed 's/.*#//' | cut -c1-8)" >> $GITHUB_OUTPUT
echo "polkadot_ver=$(grep 'frame-system' Cargo.toml | sed -nE 's/.*moonbeam-polkadot-v([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' | head -1)" >> $GITHUB_OUTPUT
ENDPOINT="https://api.github.com/repos/moonbeam-foundation/moonbeam/git/refs/tags/${{ steps.get-latest-rt.outputs.latest_rt }}"
RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $ENDPOINT)
TYPE=$(echo $RESPONSE | jq -r '.object.type')
if [[ $TYPE == "commit" ]]
then
LATEST_RT_SHA8=$(echo $RESPONSE | jq -r '.object.sha' | cut -c -8)
elif [[ $TYPE == "tag" ]]
then
URL=$(echo $RESPONSE | jq -r '.object.url')
TAG_RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $URL)
TAG_RESPONSE_CLEAN=$(echo $TAG_RESPONSE | tr -d '\000-\037')
LATEST_RT_SHA8=$(echo $TAG_RESPONSE_CLEAN | jq -r '.object.sha' | cut -c -8)
fi
echo $LATEST_RT_SHA8
echo "latest_rt_sha8=$LATEST_RT_SHA8" >> $GITHUB_OUTPUT
- name: Check existing docker image
id: check-docker-image
run: |
TAG=sha-${{ steps.get-sha.outputs.sha8 }}
echo "image_exists=$(docker image inspect moonbeamfoundation/moonbeam:$TAG > /dev/null && echo "true" || echo "false")" >> $GITHUB_OUTPUT
- name: Display variables
run: |
echo git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
echo sha: ${{ steps.get-sha.outputs.sha }}
echo sha8: ${{ steps.get-sha.outputs.sha8 }}
echo image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
echo latest_rt: ${{ steps.get-latest-rt.outputs.latest_rt }}
echo latest_rt_sha8: ${{ steps.get-sha.outputs.latest_rt_sha8 }}
echo polkadot_repo: ${{ steps.get-sha.outputs.polkadot_repo }}
echo polkadot_commit: ${{ steps.get-sha.outputs.polkadot_commit }}
echo polkadot_ver: ${{ steps.get-sha.outputs.polkadot_ver }}
check-copyright:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Find un-copyrighted files
run: |
find . \! -name '*.expanded.rs' -name '*.rs' -exec grep -H -E -o -c Copyright {} \; | grep ':0' || true
FILECOUNT=$(find . \! -name '*.expanded.rs' -name '*.rs' -exec grep -H -E -o -c Copyright {} \; | grep -c ':0' || true)
if [[ $FILECOUNT -eq 0 ]]; then
true
else
false
fi
check-links:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: "yes"
max-depth: 4
check-editorconfig:
name: "Check editorconfig"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Setup editorconfig checker
run: |
ls /tmp/bin/ec-linux-amd64 || \
cd /tmp && \
wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.7.0/ec-linux-amd64.tar.gz && \
tar xvf ec-linux-amd64.tar.gz && \
chmod +x bin/ec-linux-amd64
- name: Check files
# Prettier and editorconfig-checker have different ideas about indentation
run: /tmp/bin/ec-linux-amd64 --exclude "(typescript-api\/)|(test\/contracts\/lib\/.*)" -disable-indent-size
check-prettier:
name: "Check with Prettier"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Check with Prettier
run: |
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
|| (git diff --quiet \
|| (echo 'Unable to show a diff because there are unstaged changes'; false) \
&& (bun x prettier@2 --ignore-path \
.prettierignore '**/*.(yml|js|ts|json)' -w --loglevel silent \
&& git --no-pager diff; git restore .) && false)
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
check-eslint:
name: "Check with EsLint"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Use pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- name: Run Eslint check
run: |
cd test
pnpm i
pnpm lint
check-cargo-toml-format:
name: "Check Cargo.toml files format"
runs-on:
labels: bare-metal
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: |
rustup override unset
rustup show
- name: Check Cargo.toml files format with toml_sort
run: ./scripts/check-cargo-toml-files-format.sh
check-forbid-evm-reentrancy:
name: "Check 'forbid-evm-reentrancy'"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Setup Rust toolchain
run: |
rustup override unset
rustup show
- name: Verifies all 'pallet-evm/ethereum' use 'forbid-evm-reentrancy' feature
run: ./scripts/check-forbid-evm-reentrancy.sh
check-rust-fmt:
name: "Check with rustfmt"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: |
rustup override unset
rustup show
- name: Format code with rustfmt
run: cargo fmt -- --check
####### Building and Testing binaries #######
cargo-clippy:
runs-on:
labels: bare-metal
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: Setup Rust toolchain
run: |
rustup override unset
rustup show
# Development branch clippy check
- name: Clippy (dev)
if: github.ref != 'refs/heads/master' && !startsWith(github.ref, 'perm-')
run: SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --features try-runtime,runtime-benchmarks
# Main branch (master, perm-*) clippy check
# Disallows: todo
- name: Clippy (main)
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'perm-')
run: SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --features try-runtime,runtime-benchmarks -- -Dclippy::todo
build:
runs-on:
labels: bare-metal
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: metadata-hash
- name: Upload runtimes
uses: actions/upload-artifact@v4
with:
name: runtimes
path: runtimes
- name: Upload uncompressed runtimes
uses: actions/upload-artifact@v4
with:
name: uncompressed-runtimes
path: uncompressed-runtimes
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: moonbeam
path: build
check-wasm-size:
name: "Check WASM runtimes with Twiggy"
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: ["set-tags", "build"]
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: |
rustup override unset
rustup show
- name: Download Twiggy
run: cargo install twiggy
- name: Lookup for latest target branch build
run: |
TARGET_BRANCH=${{ github.event.pull_request.base.ref }}
LATEST_TARGET_BRANCH_BUILD=$(gh run -R moonbeam-foundation/moonbeam list -w Build --limit=100 --json databaseId,url,headBranch,event,status,conclusion,createdAt --jq ".[] | select(.headBranch == \"$TARGET_BRANCH\" and .event == \"push\" and .status == \"completed\" and .conclusion == \"success\") | .databaseId" | head -n 1)
echo "LATEST_TARGET_BRANCH_BUILD=$LATEST_TARGET_BRANCH_BUILD" >> $GITHUB_OUTPUT
- name: Download latest target branch build artifacts
run: |
gh run download $LATEST_TARGET_BRANCH_BUILD -n uncompressed-runtimes --dir uncompressed-runtimes-target-branch
gh run download $LATEST_TARGET_BRANCH_BUILD -n runtimes --dir runtimes-target-branch
- name: Check Runtimes size for target branch
run: |
PREVIOUS_MOONBASE=$(du -k runtimes-target-branch/* | awk '/moonbase_runtime/ {print $1}')
PREVIOUS_MOONBEAM=$(du -k runtimes-target-branch/* | awk '/moonbeam_runtime/ {print $1}')
PREVIOUS_MOONRIVER=$(du -k runtimes-target-branch/* | awk '/moonriver_runtime/ {print $1}')
echo "PREVIOUS_MOONBASE=$PREVIOUS_MOONBASE" >> $GITHUB_ENV
echo "PREVIOUS_MOONBEAM=$PREVIOUS_MOONBEAM" >> $GITHUB_ENV
echo "PREVIOUS_MOONRIVER=$PREVIOUS_MOONRIVER" >> $GITHUB_ENV
- name: "Download branch built runtime"
uses: actions/download-artifact@v4
with:
name: runtimes
path: runtimes-current-branch
- name: "Download branch built uncompressed-runtimes"
uses: actions/download-artifact@v4
with:
name: uncompressed-runtimes
path: uncompressed-runtimes-current-branch
- name: Check Runtimes size for current branch
run: |
CURRENT_MOONBASE=$(du -k runtimes-current-branch/* | awk '/moonbase_runtime/ {print $1}')
CURRENT_MOONBEAM=$(du -k runtimes-current-branch/* | awk '/moonbeam_runtime/ {print $1}')
CURRENT_MOONRIVER=$(du -k runtimes-current-branch/* | awk '/moonriver_runtime/ {print $1}')
echo "CURRENT_MOONBASE=$CURRENT_MOONBASE" >> $GITHUB_ENV
echo "CURRENT_MOONBEAM=$CURRENT_MOONBEAM" >> $GITHUB_ENV
echo "CURRENT_MOONRIVER=$CURRENT_MOONRIVER" >> $GITHUB_ENV
- name: Fetch latest release tag
id: fetch_latest_release
run: |
LATEST_RELEASE_TAG=$(gh api repos/moonbeam-foundation/moonbeam/releases --paginate --jq '.[] | select(.tag_name | test("^runtime-\\d+$")) | .tag_name' | sort -V | tail -n 1)
echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV
echo $LATEST_RELEASE_TAG
- name: Download latest release runtimes
run: |
gh release download $LATEST_RELEASE_TAG -R moonbeam-foundation/moonbeam -p "moonbeam-runtime-${LATEST_RELEASE_TAG#runtime-}.wasm" -p "moonbase-runtime-${LATEST_RELEASE_TAG#runtime-}.wasm" -p "moonriver-runtime-${LATEST_RELEASE_TAG#runtime-}.wasm" --dir runtimes-latest-release
- name: Check Runtimes size for latest release
run: |
LATEST_MOONBASE=$(du -k runtimes-latest-release/* | awk '/moonbase-runtime/ {print $1}')
LATEST_MOONBEAM=$(du -k runtimes-latest-release/* | awk '/moonbeam-runtime/ {print $1}')
LATEST_MOONRIVER=$(du -k runtimes-latest-release/* | awk '/moonriver-runtime/ {print $1}')
echo "LATEST_MOONBASE=$LATEST_MOONBASE" >> $GITHUB_ENV
echo "LATEST_MOONBEAM=$LATEST_MOONBEAM" >> $GITHUB_ENV
echo "LATEST_MOONRIVER=$LATEST_MOONRIVER" >> $GITHUB_ENV
- name: Create Twiggy diff reports
run: |
# Install Twiggy if not already installed
if ! command -v twiggy &> /dev/null; then
cargo install twiggy
fi
# Generate Twiggy diff reports in JSON format with top 100 entries
mkdir -p twiggy-diff-reports
twiggy diff -n 100 --format json uncompressed-runtimes-target-branch/moonbase_runtime.wasm uncompressed-runtimes-current-branch/moonbase_runtime.wasm > twiggy-diff-reports/twiggy_diff_moonbase.json
twiggy diff -n 100 --format json uncompressed-runtimes-target-branch/moonbeam_runtime.wasm uncompressed-runtimes-current-branch/moonbeam_runtime.wasm > twiggy-diff-reports/twiggy_diff_moonbeam.json
twiggy diff -n 100 --format json uncompressed-runtimes-target-branch/moonriver_runtime.wasm uncompressed-runtimes-current-branch/moonriver_runtime.wasm > twiggy-diff-reports/twiggy_diff_moonriver.json
- name: Upload Twiggy diff reports
uses: actions/upload-artifact@v4
with:
name: twiggy-diff-reports
path: twiggy-diff-reports
- name: Compare Runtimes sizes
run: |
# Create or truncate the file
echo "" > runtime_size_report.md
MOONBASE_DIFF=$((CURRENT_MOONBASE - PREVIOUS_MOONBASE))
MOONBEAM_DIFF=$((CURRENT_MOONBEAM - PREVIOUS_MOONBEAM))
MOONRIVER_DIFF=$((CURRENT_MOONRIVER - PREVIOUS_MOONRIVER))
LATEST_MOONBASE_DIFF=$((CURRENT_MOONBASE - LATEST_MOONBASE))
LATEST_MOONBEAM_DIFF=$((CURRENT_MOONBEAM - LATEST_MOONBEAM))
LATEST_MOONRIVER_DIFF=$((CURRENT_MOONRIVER - LATEST_MOONRIVER))
get_status_emoji() {
local size=$1
local diff=$2
if [ $size -gt 2400 ]; then
echo "🚨"
elif [ $diff -gt 0 ]; then
echo "⚠️"
else
echo "✅"
fi
}
MOONBASE_STATUS=$(get_status_emoji $CURRENT_MOONBASE $MOONBASE_DIFF)
MOONBEAM_STATUS=$(get_status_emoji $CURRENT_MOONBEAM $MOONBEAM_DIFF)
MOONRIVER_STATUS=$(get_status_emoji $CURRENT_MOONRIVER $MOONRIVER_DIFF)
LATEST_MOONBASE_STATUS=$(get_status_emoji $CURRENT_MOONBASE $LATEST_MOONBASE_DIFF)
LATEST_MOONBEAM_STATUS=$(get_status_emoji $CURRENT_MOONBEAM $LATEST_MOONBEAM_DIFF)
LATEST_MOONRIVER_STATUS=$(get_status_emoji $CURRENT_MOONRIVER $LATEST_MOONRIVER_DIFF)
MOONBASE_MSG="Moonbase runtime: ${CURRENT_MOONBASE} KB ($( [ $MOONBASE_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $MOONBASE_DIFF -gt 0 ] && echo "+" )${MOONBASE_DIFF} KB")) ${MOONBASE_STATUS}"
MOONBEAM_MSG="Moonbeam runtime: ${CURRENT_MOONBEAM} KB ($( [ $MOONBEAM_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $MOONBEAM_DIFF -gt 0 ] && echo "+" )${MOONBEAM_DIFF} KB")) ${MOONBEAM_STATUS}"
MOONRIVER_MSG="Moonriver runtime: ${CURRENT_MOONRIVER} KB ($( [ $MOONRIVER_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $MOONRIVER_DIFF -gt 0 ] && echo "+" )${MOONRIVER_DIFF} KB")) ${MOONRIVER_STATUS}"
LATEST_MOONBASE_MSG="Moonbase runtime: ${CURRENT_MOONBASE} KB ($( [ $LATEST_MOONBASE_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $LATEST_MOONBASE_DIFF -gt 0 ] && echo "+" )${LATEST_MOONBASE_DIFF} KB compared to latest release")) ${LATEST_MOONBASE_STATUS}"
LATEST_MOONBEAM_MSG="Moonbeam runtime: ${CURRENT_MOONBEAM} KB ($( [ $LATEST_MOONBEAM_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $LATEST_MOONBEAM_DIFF -gt 0 ] && echo "+" )${LATEST_MOONBEAM_DIFF} KB compared to latest release")) ${LATEST_MOONBEAM_STATUS}"
LATEST_MOONRIVER_MSG="Moonriver runtime: ${CURRENT_MOONRIVER} KB ($( [ $LATEST_MOONRIVER_DIFF -eq 0 ] && echo "no changes" || echo "$( [ $LATEST_MOONRIVER_DIFF -gt 0 ] && echo "+" )${LATEST_MOONRIVER_DIFF} KB compared to latest release")) ${LATEST_MOONRIVER_STATUS}"
echo "### WASM runtime size check:" > runtime_size_report.md
echo "" >> runtime_size_report.md
echo "#### Compared to target branch" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$MOONBASE_MSG" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$MOONBEAM_MSG" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$MOONRIVER_MSG" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "#### Compared to latest release (${LATEST_RELEASE_TAG})" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$LATEST_MOONBASE_MSG" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$LATEST_MOONBEAM_MSG" >> runtime_size_report.md
echo "" >> runtime_size_report.md
echo "$LATEST_MOONRIVER_MSG" >> runtime_size_report.md
cat runtime_size_report.md
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "WASM runtime size check"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: runtime_size_report.md
edit-mode: replace
rust-test:
runs-on:
labels: bare-metal
needs: ["set-tags"]
env:
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
SCCACHE_CACHE_SIZE: "100GB"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Setup Variables
shell: bash
run: |
echo "RUSTFLAGS=-C opt-level=3 -D warnings -C linker=clang -C link-arg=-fuse-ld=$(pwd)/mold/bin/mold" >> $GITHUB_ENV
- name: Setup Mold Linker
shell: bash
run: |
mkdir -p mold
curl -L --retry 10 --silent --show-error https://github.com/rui314/mold/releases/download/v2.30.0/mold-2.30.0-$(uname -m)-linux.tar.gz | tar -C $(realpath mold) --strip-components=1 -xzf -
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: |
if ! which "rustup" > /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
rustup override unset
rustup show
rustup target add wasm32-unknown-unknown
# Checks are run after uploading artifacts since they are modified by the tests
- name: Unit tests
run: |
cargo test --profile testnet --workspace --features=evm-tracing,runtime-benchmarks
- name: Run sccache stat for check pre test
run: ${SCCACHE_PATH} --show-stats
dev-test:
runs-on:
labels: bare-metal
needs: ["set-tags", "build"]
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
chain: ["moonbase", "moonriver", "moonbeam"]
shard: [1, 2, 3, 4]
env:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
DEBUG_COLORS: 1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Create local folders
run: |
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
- name: "Download branch built runtime"
uses: actions/download-artifact@v4
with:
name: runtimes
path: target/release/wbuild/${{ matrix.chain }}-runtime/
- name: "Download branch built node"
uses: actions/download-artifact@v4
with:
name: moonbeam
path: target/release
- name: "Run Moonwall Dev Tests"
uses: ./.github/workflow-templates/dev-tests
with:
moonwall_environment: dev_${{ matrix.chain }}
shard: ${{ matrix.shard }}
shard-count: 4
- name: Upload HTML report to s3
if: ${{ !github.event.pull_request.head.repo.fork}}
uses: opslayertech/[email protected]
id: S3
with:
aws_key_id: ${{ secrets.S3_COVERAGE_ID }}
aws_secret_access_key: ${{ secrets.S3_COVERAGE_KEY }}
aws_bucket: ${{ vars.S3_COVERAGE_BUCKET }}
destination_dir: "${{ needs.set-tags.outputs.test_s3_dir }}"
source_dir: "test/html"
acl: "none"
# - name: Upload to Moonscope
# if: github.event.pull_request.head.repo.full_name == github.repository
# run: |
# curl --location 'https://api.moonscope.kaki.dev/insert' \
# -X POST \
# --header 'moonwallenv: dev_${{ matrix.chain }}' \
# --header 'Authorization: Bearer ${{ secrets.MOONSCOPE_TOKEN }}' \
# --header 'table: dev_reports' \
# --header 'branch: ${{ needs.set-tags.outputs.git_branch }}' \
# --header 'Content-Type: application/json' \
# --max-time 30 \
# -d@test/tmp/testResults.json || echo "Curl command failed but continuing"
typescript-tracing-tests:
if: >
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
runs-on:
labels: bare-metal
needs: ["set-tags", "build", "dev-test"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v4
with:
name: moonbeam
path: build
- name: Use pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- run: |
mkdir -p target/release
- name: "Download branch built node"
uses: actions/download-artifact@v4
with:
name: moonbeam
path: target/release
- name: Get tracing runtimes
run: |
./scripts/build-last-tracing-runtime.sh ${{ needs.set-tags.outputs.git_branch }}
mkdir -p test/moonbase-overrides/
mv build/wasm/moonbase-runtime-local-substitute-tracing.wasm test/moonbase-overrides/
- name: Preparing the repository
run: |
chmod uog+x build/moonbeam
chmod uog+x target/release/moonbeam
#### Preparing the repository
cd moonbeam-types-bundle
pnpm i
pnpm build
#### Preparing the typescript api
cd ../typescript-api
pnpm i
pnpm build
- name: Running Tracing Tests
env:
DEBUG_COLOURS: "1"
NODE_OPTIONS: "--max-old-space-size=12288"
run: |
cd test
pnpm install
pnpm compile-solidity
pnpm moonwall test dev_moonbase_tracing
docker-moonbeam:
runs-on: ubuntu-latest
needs: ["set-tags", "build"]
if: ${{ needs.set-tags.outputs.image_exists == 'false' && !github.event.pull_request.head.repo.fork }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v4
with:
name: moonbeam
path: build
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=moonbeamfoundation/moonbeam
TAGS="${DOCKER_IMAGE}:sha-${{ needs.set-tags.outputs.sha8 }}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
version: latest
driver-opts: |
image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.MBF_DOCKERHUB_USERNAME }}
password: ${{ secrets.MBF_DOCKERHUB_PASSWORD }}
- name: Build and push moonbeam
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/moonbeam.Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
lazy-loading-tests:
runs-on:
labels: bare-metal
needs: ["set-tags", "build", "typescript-tracing-tests"]
strategy:
fail-fast: false
max-parallel: 1
matrix:
chain: ["moonbeam"]
env:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
DEBUG_COLORS: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Create local folders
run: |
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
mkdir -p test/tmp
- name: "Download branch built runtime"
uses: actions/download-artifact@v4
with:
name: runtimes
path: target/release/wbuild/${{ matrix.chain }}-runtime/
- name: "Download branch built node"
uses: actions/download-artifact@v4
with:
name: moonbeam
path: target/release
- name: Setup Moonbeam PolkadotJS types
shell: bash
run: |
#### Preparing the legacy types
cd moonbeam-types-bundle
pnpm i
pnpm build
#### Preparing the typescript api
cd ../typescript-api
pnpm i
pnpm build
cd ../test
pnpm add ../typescript-api
- name: "Run lazy loading tests"
run: |
chmod uog+x target/release/moonbeam
cd test
pnpm install
pnpm moonwall test lazy_loading_${{ matrix.chain }}
- name: Zip and Upload Node Logs on Failure
if: failure()
run: |
TIMESTAMP=$(date +%Y%m%d%H%M%S)
export NODE_LOGS_ZIP="node_logs_$TIMESTAMP.zip"
MOST_RECENT_ZOMBIE_DIR=$(ls -td /tmp/zombie-* | head -n 1)
find $MOST_RECENT_ZOMBIE_DIR -maxdepth 1 -type f -name '*.log' -exec zip -r $NODE_LOGS_ZIP {} \;
echo "NODE_LOGS_ZIP=${NODE_LOGS_ZIP}" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
if: failure()
with:
name: failed-node-logs
path: ${{ env.NODE_LOGS_ZIP }}
chopsticks-upgrade-test:
runs-on:
labels: bare-metal
needs: ["set-tags", "build", "typescript-tracing-tests"]
strategy:
fail-fast: false
matrix:
chain: ["moonbase", "moonriver", "moonbeam"]
env:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
DEBUG_COLORS: 1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- name: Create local folders
run: |
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
mkdir -p test/tmp/node_logs
- name: "Download runtime"
uses: actions/download-artifact@v4
with:
name: runtimes
path: target/release/wbuild/${{ matrix.chain }}-runtime/
- name: Setup Moonbeam PolkadotJS types
shell: bash
run: |
#### Preparing the legacy types
cd moonbeam-types-bundle
pnpm i
pnpm build
#### Preparing the typescript api
cd ../typescript-api
pnpm i
pnpm build
cd ../test
pnpm add ../typescript-api
- name: "Install and run upgrade test"
run: |
cd test
pnpm install
- name: Run Upgrade Test (with retry)
uses: nick-fields/retry@v3
with:
max_attempts: 3
timeout_minutes: 2
retry_on: error
command: |
cd test
pnpm moonwall test upgrade_${{matrix.chain}}
zombie_upgrade_test:
runs-on:
labels: bare-metal
needs: ["set-tags", "build", "typescript-tracing-tests"]
strategy:
fail-fast: false
max-parallel: 1
matrix:
## TODO: add moonriver here when it is ready
chain: ["moonbase", "moonbeam"]
env:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
DEBUG_COLORS: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Create local folders
run: |
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
mkdir -p test/tmp
- name: "Download branch built runtime"
uses: actions/download-artifact@v4
with:
name: runtimes
path: target/release/wbuild/${{ matrix.chain }}-runtime/
- name: "Download branch built node"
uses: actions/download-artifact@v4
with:
name: moonbeam
path: target/release
- name: Retrieve moonbeam binary from docker (for plainSpec generation)
run: |
MOONBEAM_COMMIT=${{ needs.set-tags.outputs.latest_rt_sha8 }}
DOCKER_TAG="moonbeamfoundation/moonbeam:sha-$MOONBEAM_COMMIT"
docker rm -f moonbeam_container 2> /dev/null | true
docker create --name moonbeam_container $DOCKER_TAG bash
docker cp moonbeam_container:moonbeam/moonbeam test/tmp/moonbeam_rt
docker rm -f moonbeam_container
- name: Setup Moonbeam PolkadotJS types
shell: bash
run: |
#### Preparing the legacy types
cd moonbeam-types-bundle
pnpm i
pnpm build
#### Preparing the typescript api
cd ../typescript-api
pnpm i
pnpm build
cd ../test
pnpm add ../typescript-api
- name: Prepare Chainspecs
run: |
cd test
pnpm install
## Generate old spec using latest published node, modify it, and generate raw spec
chmod uog+x tmp/moonbeam_rt
chmod uog+x ../target/release/moonbeam
tmp/moonbeam_rt build-spec --chain ${{ matrix.chain }}-local > tmp/${{ matrix.chain }}-plain-spec.json
pnpm tsx scripts/modify-plain-specs.ts process tmp/${{ matrix.chain }}-plain-spec.json tmp/${{ matrix.chain }}-modified-spec.json
tmp/moonbeam_rt build-spec --chain tmp/${{ matrix.chain }}-modified-spec.json --raw > tmp/${{ matrix.chain }}-raw-spec.json
pnpm tsx scripts/preapprove-rt-rawspec.ts process tmp/${{ matrix.chain }}-raw-spec.json tmp/${{ matrix.chain }}-modified-raw-spec.json ../target/release/wbuild/${{ matrix.chain }}-runtime/${{ matrix.chain }}_runtime.compact.compressed.wasm
- name: "Run zombie upgrade test"
run: |
cd test
pnpm moonwall test zombie_${{ matrix.chain }}
- name: "Run zombie RPC test"
run: |
cd test
pnpm moonwall test zombie_${{ matrix.chain }}_rpc
- name: Zip and Upload Node Logs on Failure
if: failure()
run: |
TIMESTAMP=$(date +%Y%m%d%H%M%S)
export NODE_LOGS_ZIP="node_logs_$TIMESTAMP.zip"
MOST_RECENT_ZOMBIE_DIR=$(ls -td /tmp/zombie-* | head -n 1)
find $MOST_RECENT_ZOMBIE_DIR -maxdepth 1 -type f -name '*.log' -exec zip -r $NODE_LOGS_ZIP {} \;
echo "NODE_LOGS_ZIP=${NODE_LOGS_ZIP}" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
if: failure()
with:
name: failed-node-logs
path: ${{ env.NODE_LOGS_ZIP }}