-
Notifications
You must be signed in to change notification settings - Fork 0
529 lines (460 loc) · 17.7 KB
/
ci.yml
File metadata and controls
529 lines (460 loc) · 17.7 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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
name: CI
on:
push:
branches: [master, main]
pull_request:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
changes:
name: Detect CI scope
runs-on: ubuntu-latest
outputs:
code: ${{ steps.scope.outputs.code }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Classify changed files
id: scope
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PUSH_BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
base="$PR_BASE_SHA"
head="$CURRENT_SHA"
range="$base...$head"
else
base="$PUSH_BEFORE_SHA"
head="$CURRENT_SHA"
range="$base..$head"
fi
if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then
echo "code=true" >> "$GITHUB_OUTPUT"
echo "No usable base SHA; running full CI."
exit 0
fi
if ! changed_paths="$(git diff --name-only "$range")"; then
echo "code=true" >> "$GITHUB_OUTPUT"
echo "Could not diff $range; running full CI."
exit 0
fi
echo "Changed paths:"
printf '%s\n' "$changed_paths"
code=false
while IFS= read -r path; do
[ -n "$path" ] || continue
case "$path" in
README.md|CHANGELOG.md|CONTRIBUTING.md|LICENSE|LICENSE.*|AGENTS.md|docs/*|*.md)
;;
*)
code=true
break
;;
esac
done <<< "$changed_paths"
echo "code=$code" >> "$GITHUB_OUTPUT"
if [ "$code" = "true" ]; then
echo "Code or CI-sensitive files changed; running full CI."
else
echo "Only documentation files changed; skipping expensive CI jobs."
fi
audit:
name: Supply-chain audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check dependency file changes
id: audit_changes
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PUSH_BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
base="$PR_BASE_SHA"
head="$CURRENT_SHA"
range="$base...$head"
else
base="$PUSH_BEFORE_SHA"
head="$CURRENT_SHA"
range="$base..$head"
fi
if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then
echo "run=true" >> "$GITHUB_OUTPUT"
echo "No usable base SHA; running cargo audit."
exit 0
fi
if ! changed_paths="$(git diff --name-only "$range")"; then
echo "run=true" >> "$GITHUB_OUTPUT"
echo "Could not diff $range; running cargo audit."
exit 0
fi
if grep -Eq '^(Cargo\.toml|Cargo\.lock)$' <<<"$changed_paths"; then
echo "run=true" >> "$GITHUB_OUTPUT"
echo "Dependency files changed; running cargo audit."
else
echo "run=false" >> "$GITHUB_OUTPUT"
echo "Cargo.toml/Cargo.lock unchanged; skipping cargo audit."
fi
- name: Install cargo-audit
if: steps.audit_changes.outputs.run == 'true'
uses: taiki-e/install-action@v2
with:
tool: cargo-audit
- name: Security audit
if: steps.audit_changes.outputs.run == 'true'
run: cargo audit
- name: Report skipped audit
if: steps.audit_changes.outputs.run != 'true'
run: echo "cargo audit skipped because dependency manifests did not change"
build:
name: Build release cdylib (linux)
runs-on: ubuntu-latest
needs: changes
if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust (stable)
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
- name: Cache cargo registry & target
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
restore-keys: |
build-${{ runner.os }}-${{ runner.arch }}-
- name: Build cdylib
run: cargo build --release
- name: Upload release cdylib
uses: actions/upload-artifact@v4
with:
name: qjson-linux-release
path: target/release/libqjson.so
if-no-files-found: error
retention-days: 1
rust:
name: Rust tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: changes
if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true'
strategy:
matrix:
os: [ubuntu-latest, macos-14]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust (stable)
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
- name: Cache cargo registry & target
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-test-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
restore-keys: |
cargo-test-${{ runner.os }}-${{ runner.arch }}-
- name: Test (release)
run: cargo test --release
- name: Test scalar-only (no AVX2/NEON feature)
run: cargo test --release --no-default-features
- name: Test debug scalar-only
if: matrix.os == 'ubuntu-latest'
run: cargo test --no-default-features
- name: Test with test-panic feature
if: matrix.os == 'ubuntu-latest'
run: cargo test --features test-panic --release
- name: Install LuaJIT for package validation
if: matrix.os == 'macos-14'
uses: ./.github/actions/setup-lua
with:
lua-version: "luajit-2.1.0-beta3"
- name: Resolve LuaJIT executable for package validation
if: matrix.os == 'macos-14'
id: mac_luajit
run: .github/scripts/resolve-luajit.sh
- name: Validate LuaRocks package (macOS)
if: matrix.os == 'macos-14'
env:
LUAJIT_BIN: ${{ steps.mac_luajit.outputs.path }}
run: |
rm -rf /tmp/lua-qjson-rock
ROCKSPEC="$(.github/scripts/latest-rockspec.py)"
luarocks make "$ROCKSPEC" --tree /tmp/lua-qjson-rock
eval "$(luarocks path --tree /tmp/lua-qjson-rock)"
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
"$LUAJIT_BIN" -e 'local qjson = require("qjson"); local doc = qjson.parse("{\"a\":42}"); assert(doc:get_i64("a") == 42)'
lua-lint:
name: Lua lint
runs-on: ubuntu-latest
needs: changes
if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true'
steps:
- uses: actions/checkout@v4
- name: Install Lua lint toolchain
uses: ./.github/actions/setup-lua
with:
lua-version: "luajit-2.1.0-beta3"
packages: >-
https://luarocks.org/argparse-0.7.2-1.src.rock
https://luarocks.org/luafilesystem-1.9.0-1.src.rock
https://luarocks.org/luacheck-1.2.0-1.src.rock
- name: Run Lua lint
run: make lua-lint
fuzz:
name: Fuzz corpus replay
runs-on: ubuntu-latest
needs: changes
if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust (nightly)
run: |
rustup toolchain install nightly --profile minimal --no-self-update
- name: Cache cargo registry & fuzz target
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin/cargo-fuzz
fuzz/target
key: fuzz-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'fuzz/Cargo.toml') }}
restore-keys: |
fuzz-${{ runner.os }}-${{ runner.arch }}-
- name: Install cargo-fuzz
run: |
if ! command -v cargo-fuzz >/dev/null 2>&1; then
cargo install --locked cargo-fuzz
fi
- name: Replay fuzz corpora
run: |
cargo +nightly fuzz run fuzz_parse_eager -- -runs=0
cargo +nightly fuzz run fuzz_depth -- -runs=0
cargo +nightly fuzz run fuzz_ffi_ops -- -runs=0
cargo +nightly fuzz run fuzz_parse_lazy -- -runs=0
sanitizers:
name: Sanitizers (Rust nightly)
runs-on: ubuntu-latest
needs: changes
if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust (nightly)
run: |
rustup toolchain install nightly --profile minimal --no-self-update
rustup +nightly target add x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc64-unknown-linux-gnu
rustup +nightly component add miri
- name: Cache cargo registry & target
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: sanitizers-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
restore-keys: |
sanitizers-${{ runner.os }}-${{ runner.arch }}-
- name: Miri FFI tests x86_64 (scalar scanner)
run: |
cargo +nightly miri test --target x86_64-unknown-linux-gnu --no-default-features --test ffi_smoke
cargo +nightly miri test --target x86_64-unknown-linux-gnu --no-default-features --test ffi_cursor
cargo +nightly miri test --target x86_64-unknown-linux-gnu --no-default-features --test ffi_strings
cargo +nightly miri test --target x86_64-unknown-linux-gnu --no-default-features --test ffi_ops_interleave
- name: Miri FFI tests i686 (32-bit validation)
run: |
cargo +nightly miri test --target i686-unknown-linux-gnu --no-default-features --test ffi_smoke
cargo +nightly miri test --target i686-unknown-linux-gnu --no-default-features --test ffi_cursor
cargo +nightly miri test --target i686-unknown-linux-gnu --no-default-features --test ffi_strings
cargo +nightly miri test --target i686-unknown-linux-gnu --no-default-features --test ffi_ops_interleave
- name: Miri FFI tests powerpc64 (big-endian validation)
run: |
cargo +nightly miri test --target powerpc64-unknown-linux-gnu --no-default-features --test ffi_smoke
cargo +nightly miri test --target powerpc64-unknown-linux-gnu --no-default-features --test ffi_cursor
cargo +nightly miri test --target powerpc64-unknown-linux-gnu --no-default-features --test ffi_strings
cargo +nightly miri test --target powerpc64-unknown-linux-gnu --no-default-features --test ffi_ops_interleave
- name: ASan FFI smoke tests
continue-on-error: true
env:
RUSTFLAGS: -Z sanitizer=address
run: |
cargo +nightly test --release --target x86_64-unknown-linux-gnu --test ffi_smoke
cargo +nightly test --release --target x86_64-unknown-linux-gnu --test ffi_strings
cargo +nightly test --release --target x86_64-unknown-linux-gnu --test ffi_ops_interleave
lua:
name: Lua integration tests (${{ matrix.runtime.name }})
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
runtime:
- name: upstream LuaJIT
lua_version: "luajit-2.1.0-beta3"
validate_rockspec: true
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Download release cdylib
uses: actions/download-artifact@v4
with:
name: qjson-linux-release
path: target/release
- name: Install LuaJIT (${{ matrix.runtime.name }})
uses: ./.github/actions/setup-lua
with:
lua-version: ${{ matrix.runtime.lua_version }}
install-luarocks: "false"
- name: Install Lua dependencies
run: .github/scripts/install-lua-test-deps.sh
- name: Install Rust for package validation
if: matrix.runtime.validate_rockspec
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
- name: Resolve LuaJIT executable
id: luajit
run: .github/scripts/resolve-luajit.sh
- name: Run busted tests (${{ matrix.runtime.name }})
env:
LUAJIT_BIN: ${{ steps.luajit.outputs.path }}
run: |
# ffi.load("qjson") uses dlopen which respects LD_LIBRARY_PATH,
# not LuaJIT's package.cpath. Point dlopen at the release build dir.
LD_LIBRARY_PATH="$PWD/target/release" \
busted --lua="$LUAJIT_BIN" tests/lua \
--lpath='./lua/?.lua'
- name: Validate LuaRocks package
if: matrix.runtime.validate_rockspec
env:
LUAJIT_BIN: ${{ steps.luajit.outputs.path }}
run: |
rm -rf /tmp/lua-qjson-rock
ROCKSPEC="$(.github/scripts/latest-rockspec.py)"
luarocks make "$ROCKSPEC" --tree /tmp/lua-qjson-rock
eval "$(luarocks path --tree /tmp/lua-qjson-rock)"
unset LD_LIBRARY_PATH
"$LUAJIT_BIN" -e 'local qjson = require("qjson"); local doc = qjson.parse("{\"a\":42}"); assert(doc:get_i64("a") == 42)'
busted --lua="$LUAJIT_BIN" tests/lua
lua-valgrind:
name: Lua valgrind memcheck (upstream LuaJIT)
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Download release cdylib
uses: actions/download-artifact@v4
with:
name: qjson-linux-release
path: target/release
- name: Install LuaJIT
uses: ./.github/actions/setup-lua
with:
lua-version: "luajit-2.1.0-beta3"
install-luarocks: "false"
- name: Install Lua dependencies
run: .github/scripts/install-lua-test-deps.sh
- name: Install valgrind
run: sudo apt-get install -y valgrind
- name: Resolve LuaJIT executable
id: luajit
run: .github/scripts/resolve-luajit.sh
- name: Run smoke tests under valgrind (upstream LuaJIT)
env:
LUAJIT_BIN: ${{ steps.luajit.outputs.path }}
LUA_INIT: if jit then jit.off() end
run: |
# Valgrind is an end-to-end canary for the real LuaJIT FFI path.
# Disable JIT compilation so Memcheck observes the interpreter + FFI
# boundary instead of LuaJIT's generated traces. Trace children so
# the LuaRocks busted launcher re-execs into the selected LuaJIT
# binary under Memcheck. Keep PR coverage to focused smoke specs;
# full Lua Valgrind runs live in lua-valgrind-full.yml.
LD_LIBRARY_PATH="$PWD/target/release" \
valgrind \
--trace-children=yes \
--error-exitcode=1 \
--leak-check=full \
--show-leak-kinds=definite,indirect,possible \
--errors-for-leak-kinds=definite,indirect,possible \
--num-callers=24 \
--suppressions=valgrind.supp \
busted --lua="$LUAJIT_BIN" \
tests/lua/basic_spec.lua \
tests/lua/escape_spec.lua \
tests/lua/gc_spec.lua \
tests/lua/lazy_table_spec.lua \
tests/lua/ordered_encode_spec.lua \
tests/lua/encode_errors_spec.lua \
tests/lua/encode_cjson_compat_spec.lua \
tests/lua/options_spec.lua \
--lpath='./lua/?.lua'
openresty:
name: OpenResty runtime (${{ matrix.openresty.version }})
runs-on: ubuntu-22.04
needs: build
permissions:
contents: read
strategy:
fail-fast: false
matrix:
openresty:
- version: "1.21.4.4"
image: "openresty/openresty:1.21.4.4-0-jammy"
full_busted: false
- version: "1.27.1.2"
image: "openresty/openresty:1.27.1.2-0-jammy"
full_busted: false
- version: "1.29.2.4"
image: "openresty/openresty:1.29.2.4-0-jammy"
full_busted: true
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Download release cdylib
uses: actions/download-artifact@v4
with:
name: qjson-linux-release
path: target/release
- name: Run OpenResty runtime checks
env:
OPENRESTY_IMAGE: ${{ matrix.openresty.image }}
OPENRESTY_FULL_BUSTED: ${{ matrix.openresty.full_busted }}
run: .github/scripts/run-openresty-runtime.sh