-
Notifications
You must be signed in to change notification settings - Fork 84
149 lines (136 loc) · 6.26 KB
/
build-wasm.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
on:
push:
tags:
- '*'
pull_request:
paths:
- ".github/workflows/build-wasm.yml"
name: Build&Publish WASM
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
permissions:
id-token: write
contents: read
jobs:
build-runtime-wasms:
environment: production # It needs the production GCP credentials to upload WASM
# Benchmark (with cache hit)
# ubuntu-latest 50 min
# ubuntu-latest-4-cores 34 min
# As this is not a critical PR feedback item, we can run it on free ubuntu-latest
runs-on: ubuntu-latest
strategy:
matrix:
chain: [ altair, centrifuge, development ]
name: build-runtime-${{ matrix.chain }}
env:
SRTOOL_IMAGE: "paritytech/srtool:1.77.0-0.15.0"
steps:
# PREP
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4
- name: Prep build on Ubuntu
uses: ./.github/actions/prep-ubuntu
# sccache does not work inside the srtool container
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # 2.7
with:
prefix-key: build
shared-key: wasm
workspaces: |
.
./target/srtool
cache-directories: ./runtime
# Use this to debug what's going on inside the srtool container
# - name: Run Docker SRTool
# uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 #v3
# with:
# image: paritytech/srtool:${{ matrix.rust_version }}
# options: --user root -v /home/runner/.cargo:/cargo-home -v ${{ github.workspace }}:/build -e BUILD_OPTS=${{ env.BUILD_OPTS || ''}} -e PACKAGE=${{ matrix.chain }}-runtime
# options: --user root -v /home/runner/.cargo:/cargo-home -v ${{ github.workspace }}:/build -e BUILD_OPTS=${{ env.BUILD_OPTS || ''}} -e PACKAGE=${{ matrix.chain }}-runtime
# run: |
# echo "---- Env VARS ----"
# echo "BUILD_OPT=${BUILD_OPT}"
# echo "PACKAGE=${PACKAGE}"
# echo "---- List Cache Folder ----"
# ls -la /cargo-home/
# du -sh /cargo-home/*
# echo "---- RUNNING BUILD ----"
# /srtool/build --app --json -cM
# Build and setup env vars:
- name: Run srtool # https://docs.substrate.io/reference/command-line-tools/srtool/
id: srtool_build
shell: bash
run: |
##"RUNNING SRTOOL"
echo ::group::Docker run srtool build ${{ inputs.chain }}
CMD="docker run --rm --user root --platform=linux/amd64
-e PROFILE=release -e PACKAGE=${{ matrix.chain }}-runtime -e BUILD_OPTS="--features=on-chain-release-build"
-v /home/runner/.cargo:/cargo-home -v ${{ github.workspace }}:/build
${{ env.SRTOOL_IMAGE }} /srtool/build --app --json -cM"
echo ::debug::build::docker_run $CMD
echo ::endgroup
# here we keep streaming the progress and fetch the last line for the json result
stdbuf -oL $CMD | {
while IFS= read -r line
do
echo ║ $line
JSON="$line"
done
echo "json=$JSON" >> $GITHUB_OUTPUT
WASM=`echo $JSON | jq -r .runtimes.compact.wasm`
echo "wasm=$WASM" >> $GITHUB_OUTPUT
Z_WASM=`echo $JSON | jq -r .runtimes.compressed.wasm`
echo "wasm_compressed=$Z_WASM" >> $GITHUB_OUTPUT
}
- name: Summary
run: |
## JSON output
echo "::group::JSON output"
PRETTY_JSON=$(echo '${{ steps.srtool_build.outputs.json }}' | jq .)
echo '${{ steps.srtool_build.outputs.json }}' | jq . > "${{ matrix.chain }}-srtool-digest.json"
echo "JSON Output:"
cat "${{ matrix.chain }}-srtool-digest.json"
echo "::endgroup"
- id: 'auth'
# if: github.event_name != 'pull_request'
uses: 'google-github-actions/auth@5a50e581162a13f4baa8916d01180d2acbc04363' # v2.1.0
with:
workload_identity_provider: ${{ secrets.GWIP_ARTIFACTS }}
service_account: ${{ secrets.GSA_ARTIFACTS }}
- name: Setup - gcloud / gsutil
if: ${{ steps.auth.outcome == 'success' }}
uses: google-github-actions/setup-gcloud@98ddc00a17442e89a24bbf282954a3b65ce6d200 # v2.1.0
- name: Publish artifacts to GCS
if: ${{ steps.auth.outcome == 'success' }}
shell: bash
run: |
## Publish WASM and JSON summary
echo '${{ steps.srtool_build.outputs.json }}' | jq . > "${{ matrix.chain }}-srtool-digest.json"
gsutil cp \
"${{ steps.srtool_build.outputs.wasm_compressed }}" \
"gs://centrifuge-wasm-repo/${{ matrix.chain }}/${{ matrix.chain }}-$(git rev-parse --short HEAD).wasm"
## Publish WASM and JSON summary
echo '${{ steps.srtool_build.outputs.json }}' | jq . > "${{ matrix.chain }}-srtool-digest.json"
gsutil cp \
"${{ steps.srtool_build.outputs.wasm_compressed }}" \
"gs://centrifuge-wasm-repo/${{ matrix.chain }}/${{ matrix.chain }}-$(git rev-parse --short HEAD).wasm"
gsutil cp \
"${{ matrix.chain }}-srtool-digest.json" \
"gs://centrifuge-wasm-repo/${{ matrix.chain }}/${{ matrix.chain }}-$(git rev-parse --short HEAD)-srtool-digest.json"
- name: Upload WASM to release tag ${{ github.ref_name }}
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # @v1
if: github.event_name == 'release'
# https://github.com/ncipollo/release-action
with:
tag: ${{ github.ref_name }}
commit: ${{ github.sha }}
artifacts: "${{ steps.srtool_build.outputs.wasm_compressed }}, ${{ matrix.chain }}-srtool-digest.json"
replacesArtifacts: true
allowUpdates: true
artifactErrorsFailBuild: true
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
# updateOnlyUnreleased: true # When allowUpdates is enabled, this will fail the action if the release it is updating is not a draft or a prerelease.