-
Notifications
You must be signed in to change notification settings - Fork 6
348 lines (309 loc) · 11.2 KB
/
Copy pathmain-ci.yml
File metadata and controls
348 lines (309 loc) · 11.2 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
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
name: Main CI
on:
push:
branches: [main, next]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: main-ci-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
packages: ${{ steps.filter.outputs.packages }}
infra_ci: ${{ steps.filter.outputs.infra_ci }}
general_ci: ${{ steps.filter.outputs.general_ci }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
packages:
- "packages/**"
- "Scarb.toml"
- "Scarb.lock"
- ".tool-versions"
infra_ci:
- ".github/workflows/**"
- ".github/prompts/**"
- ".github/pull_request_template.md"
general_ci:
- "codecov.yml"
- ".tool-versions"
infra-validate:
needs: changes
if: needs.changes.outputs.infra_ci == 'true' || needs.changes.outputs.general_ci == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- name: Validate workflow YAML
run: |
YAML_CLI="yaml@2.8.1"
for file in .github/workflows/*.yml .github/workflows/*.yaml; do
[ -f "$file" ] || continue
npx -y "$YAML_CLI" valid < "$file"
done
if [ -f codecov.yml ]; then
npx -y "$YAML_CLI" valid < codecov.yml
fi
- name: Validate package count matches codecov config
run: |
matrix_count=$(grep -cE '^\s+module:' .github/workflows/main-ci.yml)
codecov_count=$(grep 'after_n_builds:' codecov.yml | grep -oE '[0-9]+')
echo "Matrix modules: $matrix_count"
echo "Codecov after_n_builds: $codecov_count"
if [ "$matrix_count" != "$codecov_count" ]; then
echo "::error::Matrix has $matrix_count modules but codecov.yml expects $codecov_count builds"
echo "::error::Update codecov.yml after_n_builds to match module count"
exit 1
fi
echo "Configuration validated: $matrix_count modules"
lint:
needs: changes
if: needs.changes.outputs.packages == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
tool-versions: .tool-versions
cache: false
- name: Scarb fmt
run: scarb fmt --check --workspace
setup:
needs: [changes, lint]
if: needs.changes.outputs.packages == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- name: Extract tool versions
run: |
echo "SCARB_VERSION=$(grep '^scarb ' .tool-versions | awk '{print $2}')" >> "$GITHUB_ENV"
echo "FOUNDRY_VERSION=$(grep '^starknet-foundry ' .tool-versions | awk '{print $2}')" >> "$GITHUB_ENV"
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
cache: false
- uses: foundry-rs/setup-snfoundry@v4
with:
starknet-foundry-version: ${{ env.FOUNDRY_VERSION }}
- name: Cache Scarb dependencies
uses: actions/cache@v4
with:
path: ~/.cache/scarb
key: ${{ runner.os }}-scarb-deps-${{ hashFiles('**/Scarb.toml', '**/Scarb.lock') }}
restore-keys: |
${{ runner.os }}-scarb-deps-
- name: Cache Cargo (snforge plugin + Scarb Rust deps)
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-snforge-${{ env.FOUNDRY_VERSION }}
restore-keys: |
${{ runner.os }}-cargo-snforge-
- name: Fetch dependencies
run: scarb fetch
- name: Warm snforge plugin cache
run: snforge --version
- name: Verify workspace compiles (no warnings)
run: |
scarb build --workspace 2>&1 | tee /tmp/build.log
if grep -qE '^ --> .*\.cairo:[0-9]+:[0-9]+' /tmp/build.log; then
echo "::error::Build produced compiler warnings. Fix all warnings before merging."
grep -B1 -E '^ --> .*\.cairo:[0-9]+:[0-9]+' /tmp/build.log
exit 1
fi
test:
name: test (${{ matrix.module }})
needs: setup
runs-on: ${{ matrix.runner }}
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
# NOTE: When adding/removing modules, also update:
# - codecov.yml: after_n_builds must equal module count
# - AGENTS.md: CI Configuration section
include:
# Embeddable Game Standard
- package: game_components_embeddable_game_standard
module: token
runner: ubuntu-latest-32
fuzzer_runs: 32
- package: game_components_embeddable_game_standard
module: minigame
runner: ubuntu-latest-8
fuzzer_runs: 32
- package: game_components_embeddable_game_standard
module: metagame
runner: ubuntu-latest-8
fuzzer_runs: 32
- package: game_components_embeddable_game_standard
module: registry
runner: ubuntu-latest-8
fuzzer_runs: 32
- package: game_components_embeddable_game_standard
module: token_lite
runner: ubuntu-latest-8
fuzzer_runs: 32
# Metagame
- package: game_components_metagame
module: leaderboard
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: registration
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: entry_requirement
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: entry_fee
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: prize
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: ticket_booth
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_metagame
module: merkledrop
runner: ubuntu-latest-4
fuzzer_runs: 256
# Economy
- package: game_components_economy
module: tokenomics
runner: ubuntu-latest-4
fuzzer_runs: 256
# Utilities
- package: game_components_utilities
module: math
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_utilities
module: distribution
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_utilities
module: utils
runner: ubuntu-latest-4
fuzzer_runs: 256
- package: game_components_utilities
module: renderer
runner: ubuntu-latest-4
fuzzer_runs: 256
# Presets (standalone package, no module filter)
- package: game_components_presets
module: presets
runner: ubuntu-latest-4
fuzzer_runs: 256
steps:
- uses: actions/checkout@v6
- name: Extract tool versions
run: |
echo "SCARB_VERSION=$(grep '^scarb ' .tool-versions | awk '{print $2}')" >> "$GITHUB_ENV"
echo "FOUNDRY_VERSION=$(grep '^starknet-foundry ' .tool-versions | awk '{print $2}')" >> "$GITHUB_ENV"
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
cache: false
- uses: foundry-rs/setup-snfoundry@v4
with:
starknet-foundry-version: ${{ env.FOUNDRY_VERSION }}
- name: Cache Scarb dependencies
uses: actions/cache@v4
with:
path: ~/.cache/scarb
key: ${{ runner.os }}-scarb-deps-${{ hashFiles('**/Scarb.toml', '**/Scarb.lock') }}
restore-keys: |
${{ runner.os }}-scarb-deps-
- name: Cache Cargo (snforge plugin)
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-snforge-${{ env.FOUNDRY_VERSION }}
restore-keys: |
${{ runner.os }}-cargo-snforge-
- name: Cache tools
uses: actions/cache@v4
id: cache-tools
with:
path: |
~/.local/bin/cairo-coverage
~/.local/bin/universal-sierra-compiler
key: ${{ runner.os }}-tools-cairo-coverage-universal-sierra-compiler-v1
- name: Install tools
if: steps.cache-tools.outputs.cache-hit != 'true'
run: |
(curl -L https://raw.githubusercontent.com/software-mansion/cairo-coverage/main/scripts/install.sh | sh) &
(curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh) &
wait
- name: Cache compiled packages
uses: actions/cache@v4
with:
path: target/
key: ${{ runner.os }}-target-${{ matrix.package }}-${{ matrix.module }}-${{ env.SCARB_VERSION }}-${{ hashFiles('packages/**/*.cairo', '**/Scarb.toml', '**/Scarb.lock') }}
restore-keys: |
${{ runner.os }}-target-${{ matrix.package }}-${{ matrix.module }}-${{ env.SCARB_VERSION }}-
- name: Run tests with coverage
run: |
if [ "${{ matrix.package }}" = "game_components_${{ matrix.module }}" ]; then
snforge test -p ${{ matrix.package }} --fuzzer-runs ${{ matrix.fuzzer_runs }} --coverage 2>&1 | tee /tmp/test.log
else
snforge test -p ${{ matrix.package }} "::${{ matrix.module }}::" --fuzzer-runs ${{ matrix.fuzzer_runs }} --coverage 2>&1 | tee /tmp/test.log
fi
- name: Check for compiler warnings
if: always() && steps.cache-tools.outcome != 'failure'
run: |
if [ -f /tmp/test.log ] && grep -qE '^ --> .*\.cairo:[0-9]+:[0-9]+' /tmp/test.log; then
echo "::error::Test compilation produced warnings. Fix all warnings before merging."
grep -B1 -E '^ --> .*\.cairo:[0-9]+:[0-9]+' /tmp/test.log
exit 1
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage.lcov
flags: ${{ matrix.module }}
token: ${{ secrets.CODECOV_TOKEN }}
main-ci:
needs:
- changes
- infra-validate
- lint
- setup
- test
if: always()
runs-on: ubuntu-latest
steps:
- name: Evaluate results
env:
NEEDS_JSON: ${{ toJson(needs) }}
run: |
FAILED=$(echo "$NEEDS_JSON" | jq -r '
to_entries[]
| select(.value.result == "failure" or .value.result == "cancelled")
| .key
')
if [ -n "$FAILED" ]; then
echo "::error::Failing jobs:"
echo "$FAILED"
exit 1
fi
echo "All required jobs passed or were skipped"