-
Notifications
You must be signed in to change notification settings - Fork 12
237 lines (210 loc) · 9.08 KB
/
check-runtime-migration.yml
File metadata and controls
237 lines (210 loc) · 9.08 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
name: Check Runtime Migrations
# If you modify more jobs, ensure that you add them as required to the job "confirmMigrationsPassed"
# which is located at the end of this file (more info in the job)
on:
push:
branches: [main, "release-*"]
pull_request:
branches: [main, "release-*"]
workflow_dispatch:
schedule:
- cron: '0 5 * * *' # Daily at 5 AM UTC
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# drop permissions for default token
permissions: {}
jobs:
changes:
uses: ./.github/workflows/check-changed-files.yml
permissions:
contents: read
pull-requests: read
runtime-matrix:
if: needs.changes.outputs.should-run == 'true'
needs: [changes]
runs-on: ubuntu-latest
outputs:
runtime: ${{ steps.runtime.outputs.runtime }}
name: Extract tasks from matrix
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- id: runtime
run: |
# Expand each runtime into one task per try_runtime instance,
# overlaying the instance's name (as `instance`) and `uris` onto
# the runtime object. Strip the nested `instances` list so each
# emitted entry only carries per-(runtime, instance) data.
TASKS=$(jq '[
.[] as $r
| ($r.try_runtime.instances // [])[] as $i
| select(($i.uris // []) | length > 0)
| $r
+ { instance: $i.name, uris: $i.uris }
+ { try_runtime: ($r.try_runtime | del(.instances)) }
]' scripts/runtimes-matrix.json)
SKIPPED_TASKS=$(jq '[.[] | select(((.try_runtime.instances // []) | length) == 0)]' scripts/runtimes-matrix.json)
echo --- Running the following tasks ---
echo $TASKS
echo --- Skipping the following runtimes with no try_runtime.instances ---
echo $SKIPPED_TASKS
# Strip whitespace from Tasks now that we've logged it
TASKS=$(echo $TASKS | jq -c .)
echo "runtime=$TASKS" >> $GITHUB_OUTPUT
prepare-try-runtime:
name: Prepare try-runtime
needs: [changes]
if: needs.changes.outputs.should-run == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Polkadot binaries
uses: ./.github/actions/use-polkadot-binaries
with:
groups: try-runtime
mode: prepare
prepare-snapshots:
name: prepare-snapshot (${{ matrix.runtime.name }} / ${{ matrix.runtime.instance }})
needs: [runtime-matrix, prepare-try-runtime]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }}
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
# Snapshot lookup uses a deliberately-non-matching primary `key:` so
# `restore-keys` always falls through to the most recent dated entry.
# With `lookup-only` the snapshot isn't restored — we just decide
# whether to regenerate. `cache-matched-key` is empty iff nothing was
# found, which is also the case on the daily `schedule` (lookup
# skipped) so the snapshot is force-refreshed nightly.
- name: Check if snapshot exists in cache
id: cache-restore
if: github.event_name != 'schedule'
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
lookup-only: true
path: snapshot.raw
key: try-runtime-snapshot-${{ matrix.runtime.name }}-${{ matrix.runtime.instance }}
restore-keys: |
try-runtime-snapshot-${{ matrix.runtime.name }}-${{ matrix.runtime.instance }}-
fail-on-cache-miss: false
- name: Set up Polkadot binaries
if: steps.cache-restore.outputs.cache-matched-key == ''
uses: ./.github/actions/use-polkadot-binaries
with:
groups: try-runtime
mode: consume
- name: Generate snapshot for ${{ matrix.runtime.name }} (${{ matrix.runtime.instance }})
if: steps.cache-restore.outputs.cache-matched-key == ''
env:
RUNTIME_NAME: ${{ matrix.runtime.name }}
RUNTIME_INSTANCE: ${{ matrix.runtime.instance }}
RUNTIME_URIS_JSON: ${{ toJSON(matrix.runtime.uris) }}
run: |
echo "Generating snapshot for $RUNTIME_NAME ($RUNTIME_INSTANCE)..."
URI_ARGS=()
while IFS= read -r uri; do
URI_ARGS+=(--uri "$uri")
done < <(echo "$RUNTIME_URIS_JSON" | jq -r '.[]')
echo "Using URIs: ${URI_ARGS[*]}"
for i in {1..10}; do
echo "Snapshot creation attempt $i/10"
if try-runtime create-snapshot "${URI_ARGS[@]}" -- snapshot.raw; then
if [ -f "snapshot.raw" ] && [ -s "snapshot.raw" ]; then
echo "Snapshot created successfully"
break
fi
fi
echo "Snapshot creation failed, attempt $i/10"
rm -f snapshot.raw
if [ "$i" -eq 10 ]; then
echo "All snapshot creation attempts failed"
exit 1
fi
sleep 10
done
- name: Get Date
id: get-date
run: |
echo "today=$(/bin/date -u "+%Y%m%d")" >> "$GITHUB_OUTPUT"
shell: bash
- name: Save snapshot to cache
if: steps.cache-restore.outputs.cache-matched-key == ''
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: snapshot.raw
key: try-runtime-snapshot-${{ matrix.runtime.name }}-${{ matrix.runtime.instance }}-${{ steps.get-date.outputs.today }}
check-migrations:
name: check-migration (${{ matrix.runtime.name }} / ${{ matrix.runtime.instance }})
needs: [runtime-matrix, prepare-try-runtime, prepare-snapshots]
runs-on: ubuntu-latest
timeout-minutes: 120
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'
strategy:
fail-fast: false
matrix:
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }}
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: "Fetch upstream tags"
if: github.event_name == 'pull_request'
env:
BASE_REPO: ${{ github.event.pull_request.base.repo.full_name }}
run: |
git remote add upstream "https://github.com/${BASE_REPO}.git"
git fetch upstream --tags
- name: Set up Polkadot binaries
uses: ./.github/actions/use-polkadot-binaries
with:
groups: try-runtime
mode: consume
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master
with:
targets: "wasm32v1-none"
components: "rust-src"
toolchain: "${{ env.RUST_STABLE_VERSION }}"
- name: Restore snapshot from cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: snapshot.raw
key: try-runtime-snapshot-${{ matrix.runtime.name }}-${{ matrix.runtime.instance }}-
fail-on-cache-miss: true
- name: Run ${{ matrix.runtime.name }} (${{ matrix.runtime.instance }}) Runtime Checks
env:
PACKAGE_NAME: ${{ matrix.runtime.package }}
TRY_RUNTIME_SPEC_NAME_CHECK: ${{ matrix.runtime.try_runtime.spec_name_check}}
TRY_RUNTIME_EXTRA_FLAGS: ${{ matrix.runtime.try_runtime.extra_flags }}
run: |
try-runtime --version
FEATURES="try-runtime"
echo "Setting features: ${FEATURES}"
cargo build --release -p "$PACKAGE_NAME" --features "$FEATURES" -q --locked
RUNTIME_BLOB_NAME=$(echo "$PACKAGE_NAME" | sed 's/-/_/g').compact.compressed.wasm
RUNTIME_BLOB_PATH="./target/release/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME"
export RUST_LOG=remote-ext=debug,runtime=trace
(set -x; try-runtime \
--runtime "$RUNTIME_BLOB_PATH" \
$TRY_RUNTIME_SPEC_NAME_CHECK \
on-runtime-upgrade --checks="all" \
$TRY_RUNTIME_EXTRA_FLAGS \
snap --path snapshot.raw)
# This will only run if all the tests in its "needs" array passed.
# Add this as your required job, becuase if the matrix changes size (new things get added)
# it will still require all the steps to succeed.
# If you add more jobs, remember to add them to the "needs" array.
confirmMigrationsPassed:
runs-on: ubuntu-latest
name: All migrations passed
if: always() && github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'
needs: [changes, prepare-try-runtime, prepare-snapshots, check-migrations]
steps:
- name: Decide outcome
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
- run: echo '### Good job! All the migrations passed 🚀' >> $GITHUB_STEP_SUMMARY