-
Notifications
You must be signed in to change notification settings - Fork 6
391 lines (365 loc) · 16.3 KB
/
rust.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
name: Rust
on:
merge_group:
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
# Detect changes in each subcrate
changes:
runs-on: ubuntu-latest
outputs:
# List of changed packages, including `fixture-generator` if the light client packages were changed
packages: ${{ steps.get-packages.outputs.packages }}
# List of changed light client packages, excluding `fixture-generator`
lc-packages: ${{ steps.get-packages.outputs.lc-packages }}
solidity-packages: ${{ steps.get-packages.outputs.solidity-packages }}
move-packages: ${{ steps.get-packages.outputs.move-packages }}
aptos: ${{ steps.filter.outputs.aptos }}
ethereum: ${{ steps.filter.outputs.ethereum }}
kadena: ${{ steps.filter.outputs.kadena }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
aptos:
- 'aptos/**'
ethereum:
- 'ethereum/**'
kadena:
- 'kadena/**'
fixture-generator:
- 'fixture-generator/**'
- name: Get list of changed packages
id: get-packages
run: |
PACKAGES=$(echo '${{ steps.filter.outputs.changes }}' | jq -c '.')
# Remove `fixture-generator` if it exists, as we don't want to run tests or the cycle checker
LC_PACKAGES=$(echo "$PACKAGES" | jq -c 'del(.[] | select(. == "fixture-generator"))')
# Remove `ethereum` if it exists, as we don't use it for Solidity tests
SOLIDITY_PACKAGES=$(echo "$LC_PACKAGES" | jq -c 'del(.[] | select(. == "ethereum"))')
# Remove `aptos` and `kadena` if they exist, as we don't use them for Move tests
MOVE_PACKAGES=$(echo "$LC_PACKAGES" | jq -c 'del(.[] | select(. == "aptos" or . == "kadena"))')
# If any packages were changed, ensure we run clippy on `fixture-generator` as it imports all light clients
if [ "$PACKAGES" != "[]" ]; then
if ! echo "$PACKAGES" | jq -e '.[] | select(. == "fixture-generator")' > /dev/null; then
PACKAGES=$(echo "$PACKAGES" | jq -c '. + ["fixture-generator"]')
fi
fi
echo "packages=$PACKAGES" | tee -a "$GITHUB_OUTPUT"
echo "lc-packages=$LC_PACKAGES" | tee -a "$GITHUB_OUTPUT"
echo "solidity-packages=$SOLIDITY_PACKAGES" | tee -a "$GITHUB_OUTPUT"
echo "move-packages=$MOVE_PACKAGES" | tee -a "$GITHUB_OUTPUT"
test:
needs: changes
runs-on: warp-ubuntu-latest-x64-16x
if: ${{ needs.changes.outputs.lc-packages != '[]' && needs.changes.outputs.lc-packages != '' }}
strategy:
fail-fast: false
matrix:
# Parse JSON array containing names of all changed light client packages,
# e.g. ['aptos', 'ethereum', 'kadena'] if `aptos`, `ethereum`, `kadena`, and `fixture-generator` contain changes.
package: ${{ fromJSON(needs.changes.outputs.lc-packages) }}
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
- name: Setup CI
uses: ./.github/actions/setup
# make sure benches don't bit-rot
- name: build benches
run: |
cargo check --benches --all-features
working-directory: ${{ github.workspace }}/${{ matrix.package }}/light-client
- name: Run cargo test in workspace
run: |
cargo nextest run --workspace --release --profile ci --all-features
working-directory: ${{ github.workspace }}/${{ matrix.package }}
clippy:
needs: changes
runs-on: warp-ubuntu-latest-x64-16x
if: ${{ needs.changes.outputs.packages != '[]' && needs.changes.outputs.packages != '' }}
strategy:
fail-fast: false
matrix:
# Parse JSON array containing names of all changed packages,
# e.g. ['aptos', 'ethereum', 'kadena', 'fixture-generator'] if `aptos`, `ethereum` and `kadena` contain changes.
# We always run 'fixture-generator' clippy tests if it or any light client was changed.
package: ${{ fromJSON(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.REPO_TOKEN }}
- name: Setup CI
uses: ./.github/actions/setup
# See '.cargo/config' for list of enabled/disabled clippy lints
- name: rustfmt
run: cargo fmt --all --check
working-directory: ${{ github.workspace }}/${{ matrix.package }}
# The stable toolchain is used to run clippy so as to not hit nightly errors
- name: cargo clippy
run: cargo xclippy -D warnings
working-directory: ${{ github.workspace }}/${{ matrix.package }}
- name: Doctests
if: ${{ matrix.package != 'fixture-generator'}}
run: |
cargo test --doc
working-directory: ${{ github.workspace }}/${{ matrix.package }}
- run: cargo install --locked cargo-deny
- name: Cargo-deny check
run: |
cargo deny --manifest-path ${{ matrix.package }}/Cargo.toml check
- name: Cargo-deny check programs
if: ${{ matrix.package != 'fixture-generator'}}
run: |
find ${{ matrix.package }}/programs -type d -name "target" -prune -o -type f -name "Cargo.toml" -exec cargo deny --manifest-path {} check \;
solidity-unit-tests:
needs: changes
runs-on: warp-ubuntu-latest-x64-16x
if: ${{ needs.changes.outputs.solidity-packages != '[]' && needs.changes.outputs.solidity-packages != '' }}
strategy:
fail-fast: false
matrix:
# Parse JSON array containing names of all changed light client packages relevant to Solidity,
# e.g. ['aptos', 'kadena'] if `aptos`, `ethereum` and `kadena` contain changes.
package: ${{ fromJSON(needs.changes.outputs.solidity-packages) }}
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.REPO_TOKEN }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Check formatting
run: |
forge fmt --check
working-directory: ${{ github.workspace }}/${{ matrix.package }}/solidity/contracts/
- name: Run Forge build
run: |
forge --version
forge build
working-directory: ${{ github.workspace }}/${{ matrix.package }}/solidity/contracts/
- name: Run Forge tests
run: |
forge test
working-directory: ${{ github.workspace }}/${{ matrix.package }}/solidity/contracts/
move-tests:
needs: changes
runs-on: warp-ubuntu-latest-x64-16x
if: ${{ needs.changes.outputs.move-packages != '[]' && needs.changes.outputs.move-packages != '' }}
strategy:
fail-fast: false
matrix:
# Parse JSON array containing names of all changed light client packages relevant to Move,
# e.g. ['ethereum'] if `aptos`, `ethereum` and `kadena` contain changes.
package: ${{ fromJSON(needs.changes.outputs.move-packages) }}
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.REPO_TOKEN }}
- name: Install Move
run: |
python3 --version
curl -fsSL "https://aptos.dev/scripts/install_cli.py" | python3
echo "PATH=$HOME/.local/bin:$PATH" | tee -a $GITHUB_ENV
- name: Check Aptos account balance
id: check_balance
run: |
balance_output=$(aptos account balance --profile testnet)
echo "Balance output: $balance_output"
balance=$(echo $balance_output | jq '.Result[0].balance')
echo "Balance value: $balance"
if [ "$balance" -lt 100000000 ]; then
echo "Balance is below threshold. Funding the account..."
aptos account fund-with-faucet --profile testnet
else
echo "Balance is sufficient. No action needed."
fi
working-directory: ${{ github.workspace }}/${{ matrix.package }}/move
- name: Run unit tests
run: |
aptos move test --named-addresses plonk_verifier_addr=devnet
working-directory: ${{ github.workspace }}/${{ matrix.package }}/move
- name: Test verifier contract
run: |
for file in $(find "sources/fixtures" -name "fixture_*.json"); do
aptos move run-script --compiled-script-path build/plonk-verifier/bytecode_scripts/run_verification.mv --json-file $file --profile testnet --local --assume-yes >> out.txt
done
for outcome in $(grep "success" out.txt | awk '{ print $2 }'); do
if [[ "${outcome%?}" != "true" ]]; then
echo "Verification failed, exiting..."
exit 1
fi
done
working-directory: ${{ github.workspace }}/${{ matrix.package }}/move
cycle-count-regression:
needs: changes
runs-on: warp-ubuntu-latest-x64-32x
if: ${{ needs.changes.outputs.lc-packages != '[]' && needs.changes.outputs.lc-packages != '' }}
strategy:
fail-fast: false
matrix:
# Parse JSON array containing names of all changed light client packages
# e.g. ['aptos', 'ethereum', 'kadena'] if all directories contain changes
package: ${{ fromJSON(needs.changes.outputs.lc-packages) }}
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
- name: Setup CI
uses: ./.github/actions/setup
- name: Set env
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_REF=${{ github.base_ref }}
elif [[ "${{ github.event_name }}" == "merge_group" ]]; then
BASE_REF=${{ github.event.merge_group.base_ref }}
fi
if [[ "${{ matrix.package }}" == "aptos" ]]; then
TESTS="test_execute_inclusion test_execute_epoch_change test_execute_sig"
FEATURES="--features aptos"
elif [[ "${{ matrix.package }}" == "ethereum" ]]; then
TESTS="test_execute_inclusion test_execute_committee_change"
FEATURES="--features ethereum"
elif [[ "${{ matrix.package }}" == "kadena" ]]; then
TESTS="test_execute_spv test_execute_longest_chain"
FEATURES="--features kadena"
fi
echo "BASE_REF=$BASE_REF" | tee -a $GITHUB_ENV
echo "TESTS=$TESTS" | tee -a $GITHUB_ENV
echo "FEATURES=$FEATURES" | tee -a $GITHUB_ENV
- name: Get cycle counts for PR
id: get_cycles_pr
run: |
CYCLE_COUNTS='[]'
set -o pipefail
for test_name in ${{ env.TESTS }}; do
cargo nextest run --verbose --release --profile ci ${{ env.FEATURES }} --package ${{ matrix.package }}-lc --no-capture -E "test($test_name)" 2>&1 | tee out.txt
num_cycles=$(cat out.txt | grep -o 'summary: cycles=[0-9]\+' | awk -F'=' '{ print $2 }')
CYCLE_COUNTS=$(echo $CYCLE_COUNTS | jq -c ". += [{\"${test_name}\": \"$num_cycles\"}]")
done
set +o pipefail
echo "CYCLE_COUNTS=$CYCLE_COUNTS" | tee -a "$GITHUB_OUTPUT"
working-directory: ${{ github.workspace }}/${{ matrix.package }}/light-client
env:
RUST_LOG: debug
- uses: actions/checkout@v4
with:
ref: ${{ env.BASE_REF }}
- name: Get cycle counts for base branch
id: regression-check
run: |
counter=0
CYCLE_COUNTS='${{ steps.get_cycles_pr.outputs.CYCLE_COUNTS }}'
echo "$CYCLE_COUNTS"
FAILING_TESTS=""
REGRESSION="false"
set -o pipefail
for test_name in ${{ env.TESTS }}; do
cargo nextest run --verbose --release --profile ci ${{ env.FEATURES }} --package ${{ matrix.package }}-lc --no-capture -E "test($test_name)" 2>&1 | tee out.txt
num_cycles_base=$(cat out.txt | grep -o 'summary: cycles=[0-9]\+' | awk -F'=' '{ print $2 }')
num_cycles_pr=$(echo "$CYCLE_COUNTS" | jq ".[$counter] | to_entries | .[0].value")
echo "$test_name summary"
echo "Base = $num_cycles_base cycles, PR = ${num_cycles_pr:1:-1} cycles"
if [[ "$num_cycles_pr" > "$num_cycles_base" ]]; then
echo "Performance regression for test ${test_name}"
REGRESSION="true"
FAILING_TESTS+="\`${test_name}\`\n"
FAILING_TESTS+="Cycles before: ${num_cycles_base//\"/}\n"
FAILING_TESTS+="Cycles after: ${num_cycles_pr//\"/}\n"
fi
counter=$((counter + 1))
done
set +o pipefail
echo "regression=$REGRESSION" | tee -a $GITHUB_OUTPUT
echo "failing-tests<<EOF" >> $GITHUB_OUTPUT
echo -e "$FAILING_TESTS" | tee -a $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "WORKFLOW_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | tee -a $GITHUB_ENV
working-directory: ${{ github.workspace }}/${{ matrix.package }}/light-client
env:
RUST_LOG: debug
- uses: actions/checkout@v4
- name: Comment on failing run
if: steps.regression-check.outputs.regression == 'true' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Benchmark cycle count regression check failed :x:
${{ steps.regression-check.outputs.failing-tests }}
${{ env.WORKFLOW_URL }}
- uses: JasonEtco/create-an-issue@v2
if: steps.regression-check.outputs.regression == 'true' && github.event_name == 'merge_group'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_URL: ${{ env.WORKFLOW_URL }}
FAILING_TESTS: ${{ steps.regression-check.outputs.failing-tests }}
with:
update_existing: true
filename: .github/BENCH_CYCLE_REGRESSION.md
check-job-results:
if: always()
# Modify to remove required status checks as needed
# If there is a breaking change, override manually via force merge or temporarily remove
# `check-job-results` altogether as a required check in branch protection rules
needs: [ changes, test, clippy, solidity-unit-tests, move-tests, cycle-count-regression ]
runs-on: ubuntu-latest
steps:
- name: Check job results
id: check-results
run: |
# Create an associative array of job results
declare -A job_results=(
["changes"]="${{ needs.changes.result }}"
["test"]="${{ needs.test.result }}"
["clippy"]="${{ needs.clippy.result }}"
["solidity-unit-tests"]="${{ needs.solidity-unit-tests.result }}"
["move-tests"]="${{ needs.move-tests.result }}"
["cycle-count-regression"]="${{ needs.cycle-count-regression.result }}"
)
# Iterate through the jobs and get their results
failed_count=0
for job in "${!job_results[@]}"; do
RESULT=${job_results[$job]}
if [[ "$RESULT" == "failure" ]]; then
failed_count=$((failed_count + 1))
fi
echo "$job result: $RESULT"
done
if [ "$failed_count" -gt 0 ]; then
echo "Some jobs failed"
echo "result=failure" | tee -a $GITHUB_OUTPUT
else
echo "All jobs succeeded or were skipped"
echo "result=success" | tee -a $GITHUB_OUTPUT
fi
- name: Error on job failure
run: |
if [[ "${{ steps.check-results.outputs.result }}" == "failure" ]]; then
exit 1
fi