-
Notifications
You must be signed in to change notification settings - Fork 14
262 lines (224 loc) · 9.1 KB
/
Copy pathtest.yml
File metadata and controls
262 lines (224 loc) · 9.1 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
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
name: Lint and Test
on:
push:
branches: [main, release-v*]
pull_request:
branches: [main, release-v*]
# Cancel in-progress runs on new pushes to the same PR/branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
env:
SUI_VERSION: "1.75.2"
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
packages: ${{ steps.set-matrix.outputs.packages }}
steps:
- name: Set package matrix
id: set-matrix
run: |
PACKAGES='["contracts/access", "contracts/allowance", "contracts/finance", "contracts/sale", "contracts/timelock", "contracts/utils", "math/core", "math/fixed_point", "collections"]'
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
- name: Cache Sui binary
id: cache-sui
uses: actions/cache@v4
with:
path: ~/.local/bin/sui
key: sui-${{ runner.os }}-${{ env.SUI_VERSION }}
- name: Install Sui CLI from binary
if: steps.cache-sui.outputs.cache-hit != 'true'
run: |
mkdir -p ~/.local/bin
curl -fLJ https://github.com/MystenLabs/sui/releases/download/mainnet-v${{ env.SUI_VERSION }}/sui-mainnet-v${{ env.SUI_VERSION }}-ubuntu-x86_64.tgz -o sui.tgz
tar -xzf sui.tgz
chmod +x sui
mv sui ~/.local/bin/
- name: Verify Sui installation
run: |
export PATH="$HOME/.local/bin:$PATH"
sui --version
check-move-formatting:
name: Move Formatter Check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check Move formatting
uses: MystenLabs/move-formatter-action@v1
with:
prettier-plugin-move-version: "latest"
working-directory: "."
pattern: "**/*.move"
write-changes: false
lint:
name: Lint ${{ matrix.package }}
needs: setup
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
package: ${{ fromJson(needs.setup.outputs.packages) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore Sui CLI
uses: ./.github/actions/restore-sui
with:
version: ${{ env.SUI_VERSION }}
- name: Lint
run: sui move build --lint --warnings-are-errors
working-directory: ./${{ matrix.package }}
- name: Lint tests
run: sui move build --test --lint --warnings-are-errors
working-directory: ./${{ matrix.package }}
- name: Docgen clean
run: sui move build --doc
working-directory: ./${{ matrix.package }}
# Fast, untraced run: the primary regression gate. Finishes in seconds even
# for the heaviest suites, so a failing test is reported quickly.
test:
name: Test ${{ matrix.package }}
needs: [setup, lint]
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: true
matrix:
package: ${{ fromJson(needs.setup.outputs.packages) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore Sui CLI
uses: ./.github/actions/restore-sui
with:
version: ${{ env.SUI_VERSION }}
- name: Run tests
run: sui move test
working-directory: ./${{ matrix.package }}
# Coverage runs separately because `sui move test --trace` (required by
# `sui move coverage lcov`) traces every VM instruction and is orders of
# magnitude slower than a plain test run - the randomized sort/median tests in
# `math/core` alone emit multi-gigabyte traces. Keeping it out of the gate
# means regressions surface fast in `test`, and a slow trace never blocks a
# merge (`continue-on-error`). It only runs once `test` is green.
coverage:
name: Coverage ${{ matrix.package }}
# `setup` is needed for the package matrix below; `test` gates this on a
# green fast run so we never trace a broken build.
needs: [setup, test]
runs-on: ubuntu-latest
timeout-minutes: 40
continue-on-error: true
permissions:
contents: read
pull-requests: write
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.setup.outputs.packages) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore Sui CLI
uses: ./.github/actions/restore-sui
with:
version: ${{ env.SUI_VERSION }}
- name: Run tests with tracing
# `--rand-num-iters 1`: coverage only needs each line executed once; the
# full randomized property iterations run in the `test` job above.
#
# Some suites build large collections whose traces run into multiple GB -
# the heaviest never finish under `--trace` (>40 min) - and `sui move
# test` has no exclude flag, so we disable them at the source level for
# the traced run and restore via git. They still run untraced in the
# `test` job above. Two scopes:
# * `collections`: the whole `*_differential_tests` modules.
# * others: individually named heavy tests (any test attribute).
shell: bash
run: |
set -euo pipefail
diff_files=$(grep -rlE --include='*.move' 'module .*_differential_tests;' tests 2>/dev/null || true)
heavy_tests='quick_sort_random_is_sorted_and_preserves_elements'
heavy_files=$(grep -rlE --include='*.move' "fun ($heavy_tests)" tests 2>/dev/null || true)
disabled=()
[ -n "$diff_files" ] && disabled+=($diff_files)
[ -n "$heavy_files" ] && disabled+=($heavy_files)
if [ ${#disabled[@]} -gt 0 ]; then
trap 'git checkout -- "${disabled[@]}"' EXIT
[ -n "$diff_files" ] && perl -0pi -e 's/#\[test\]/#[allow(unused_function)]/g' $diff_files
[ -n "$heavy_files" ] && perl -0pi -e "s/#\[(test|random_test)\]\n(fun ($heavy_tests))/#[allow(unused_function)]\n\$2/g" $heavy_files
# Fail loudly if the disable didn't happen (e.g. after a reformat),
# otherwise the traced run silently hangs again. Capture the list
# first so `sui move test` can't die from SIGPIPE (which under
# pipefail would mask a match and skip this guard).
if ! test_list=$(sui move test --list 2>&1); then
echo "::error::failed to enumerate Move tests before tracing" >&2
printf '%s\n' "$test_list" >&2
exit 1
fi
if grep -qE "_differential_tests::|::($heavy_tests)" <<<"$test_list"; then
echo "::error::failed to disable heavy tests before tracing" >&2
exit 1
fi
fi
sui move test --trace --rand-num-iters 1
working-directory: ./${{ matrix.package }}
- name: Generate Codecov report
run: sui move coverage lcov > lcov.info
working-directory: ./${{ matrix.package }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
file: ./${{ matrix.package }}/lcov.info
flags: ${{ matrix.package }}
name: ${{ matrix.package }}
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
codegen:
name: Codegen (validate + drift + tests)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install the Move formatter (prettier plugin)
run: npm ci
- name: Install codegen
run: pip install -e "scripts/gaussian_codegen[dev]"
- name: Validate committed CDF coefficients
run: python -m gaussian_codegen.cdf.validate
- name: Check CDF coefficients are in sync with the generator
run: python -m gaussian_codegen.cdf.emit_coefficients --check
- name: Check CDF test vectors are in sync with the generator
run: python -m gaussian_codegen.cdf.emit_test_vectors --check
- name: Validate committed PDF coefficients
run: python -m gaussian_codegen.pdf.validate
- name: Check PDF coefficients are in sync with the generator
run: python -m gaussian_codegen.pdf.emit_coefficients --check
- name: Check PDF test vectors are in sync with the generator
run: python -m gaussian_codegen.pdf.emit_test_vectors --check
- name: Validate committed Inverse-CDF coefficients
run: python -m gaussian_codegen.inverse_cdf.validate
- name: Check Inverse-CDF coefficients are in sync with the generator
run: python -m gaussian_codegen.inverse_cdf.emit_coefficients --check
- name: Check Inverse-CDF test vectors are in sync with the generator
run: python -m gaussian_codegen.inverse_cdf.emit_test_vectors --check
- name: Run codegen unit tests
run: pytest scripts/gaussian_codegen/tests -q