-
Notifications
You must be signed in to change notification settings - Fork 1
455 lines (383 loc) · 13.9 KB
/
ci.yml
File metadata and controls
455 lines (383 loc) · 13.9 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
name: CI
permissions:
contents: write
checks: write
pull-requests: write
on:
push:
branches: [ main ]
workflow_dispatch: # Allow manual trigger
env:
CARGO_TERM_COLOR: always
RUST_VERSION: "1.92.0"
RUSTC_WRAPPER: ""
CARGO_BUILD_RUSTC_WRAPPER: ""
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
jobs:
fmt:
name: Format Check
runs-on: ubuntu-latest
if: false # Only run on manual trigger
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt
- name: Run rustfmt
run: cargo fmt --all -- --check
clippy:
name: Clippy Check
runs-on: ubuntu-latest
if: false # Only run on manual trigger
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: clippy
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
clang \
libclang-dev \
pkg-config \
libssl-dev
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v5
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache cargo build
uses: actions/cache@v5
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-target-
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
# test:
# name: Test Suite
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v6
# - name: Install Rust toolchain
# uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: ${{ env.RUST_VERSION }}
# - name: Install system dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y --no-install-recommends \
# clang \
# libclang-dev \
# pkg-config \
# libssl-dev
# - name: Cache cargo registry
# uses: actions/cache@v5
# with:
# path: ~/.cargo/registry
# key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-cargo-registry-
# - name: Cache cargo index
# uses: actions/cache@v5
# with:
# path: ~/.cargo/git
# key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-cargo-index-
# - name: Cache cargo build
# uses: actions/cache@v5
# with:
# path: target
# key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-cargo-build-target-
# - name: Run tests
# run: cargo test --workspace --all-features
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
clang \
libclang-dev \
pkg-config \
libssl-dev
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v5
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache cargo build
uses: actions/cache@v5
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-target-
- name: Install cargo-nextest
run: |
curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
- name: Run tests (nextest)
id: nextest
run: |
cargo nextest run \
--profile ci \
--workspace \
--exclude kalam-pg-extension \
--no-fail-fast \
--failure-output immediate-final
continue-on-error: true
- name: Normalize JUnit suite durations for test-reporter
if: always() && hashFiles('target/nextest/ci/junit.xml') != ''
run: |
python3 << 'PYTHON_SCRIPT'
import math
import xml.etree.ElementTree as ET
junit_path = "target/nextest/ci/junit.xml"
def parse_time(raw):
if raw is None:
return None
try:
value = float(raw)
except ValueError:
return None
return value if math.isfinite(value) else None
def format_time(value):
return f"{value:.6f}".rstrip("0").rstrip(".") or "0"
tree = ET.parse(junit_path)
root = tree.getroot()
suites = [root] if root.tag == "testsuite" else root.findall("./testsuite")
suite_times = []
changed = False
for testsuite in suites:
suite_time = parse_time(testsuite.get("time"))
if suite_time is None:
suite_time = 0.0
for testcase in testsuite.findall("./testcase"):
case_time = parse_time(testcase.get("time"))
if case_time is not None:
suite_time += case_time
for attempt in testcase:
attempt_time = parse_time(attempt.get("time"))
if attempt_time is not None:
suite_time += attempt_time
testsuite.set("time", format_time(suite_time))
changed = True
suite_times.append(suite_time)
report_time = parse_time(root.get("time"))
if report_time is None and suite_times:
root.set("time", format_time(sum(suite_times)))
changed = True
if changed:
tree.write(junit_path, encoding="utf-8", xml_declaration=True)
print(f"Normalized JUnit durations in {junit_path}")
else:
print(f"JUnit durations already present in {junit_path}")
PYTHON_SCRIPT
- name: Parse test results and generate badge
if: always() && hashFiles('target/nextest/ci/junit.xml') != ''
run: |
JUNIT_FILE="target/nextest/ci/junit.xml"
if [ ! -f "$JUNIT_FILE" ]; then
echo "Error: JUnit XML report not found at $JUNIT_FILE"
exit 1
fi
# Parse JUnit XML using Python (available in ubuntu-latest)
eval $(python3 << 'PYTHON_SCRIPT'
import xml.etree.ElementTree as ET
import sys
try:
tree = ET.parse("target/nextest/ci/junit.xml")
root = tree.getroot()
total = 0
failures = 0
errors = 0
# Sum up all testsuite elements
for testsuite in root.findall('.//testsuite'):
total += int(testsuite.get('tests', 0))
failures += int(testsuite.get('failures', 0))
errors += int(testsuite.get('errors', 0))
failed = failures + errors
passed = total - failed
print(f"TOTAL={total}")
print(f"PASSED={passed}")
print(f"FAILED={failed}")
if total == 0:
print("Error: No tests found in JUnit report", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f"Error parsing JUnit XML: {e}", file=sys.stderr)
sys.exit(1)
PYTHON_SCRIPT
)
echo "Tests: $PASSED passed, $FAILED failed (total: $TOTAL)"
# Determine badge color and message
if [ "$FAILED" -eq "0" ]; then
COLOR="brightgreen"
MESSAGE="$PASSED/$TOTAL passed"
else
COLOR="red"
MESSAGE="$PASSED/$TOTAL passed, $FAILED failed"
fi
echo "Badge: $MESSAGE ($COLOR)"
# Generate badge JSON
mkdir -p .github/badges
cat > .github/badges/tests.json << EOF
{
"schemaVersion": 1,
"label": "overall tests ($TOTAL)",
"message": "$MESSAGE",
"color": "$COLOR"
}
EOF
cat .github/badges/tests.json
# Fail the step if tests failed
if [ "$FAILED" -ne "0" ]; then
exit 1
fi
- name: Fail if JUnit report is missing after a successful nextest run
if: always() && steps.nextest.outcome == 'success' && hashFiles('target/nextest/ci/junit.xml') == ''
run: |
echo "Error: JUnit XML report not found at target/nextest/ci/junit.xml"
exit 1
- name: Publish test report
if: always() && hashFiles('target/nextest/ci/junit.xml') != ''
uses: dorny/test-reporter@v1
with:
name: nextest
path: target/nextest/ci/junit.xml
reporter: java-junit
- name: Fail workflow if nextest did not complete successfully
if: always() && steps.nextest.outcome != 'success'
run: |
echo "nextest failed before completing the workspace suite"
exit 1
- name: Commit badge
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
set -euo pipefail
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout -B ci-test-badge-update
git add .github/badges/tests.json
if git diff --staged --quiet; then
echo "Test badge file already up to date"
exit 0
fi
git commit -m "Update test badge [skip ci]"
git push origin HEAD:main
license_compliance:
name: License Compliance
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Setup Node 24
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install cargo-license
shell: bash
run: |
set -euo pipefail
cargo install cargo-license --locked
- name: Generate Rust runtime license report
shell: bash
run: |
set -euo pipefail
mkdir -p target/license
cargo license -j --avoid-dev-deps --avoid-build-deps -o target/license/rust-runtime-licenses.json
- name: Install UI dependencies
shell: bash
working-directory: ui
run: |
set -euo pipefail
npm install --no-audit --no-fund
- name: Generate UI production license report
shell: bash
run: |
set -euo pipefail
cd ui
npx --yes license-checker --production --excludePrivatePackages --json > ../target/license/ui-licenses.json
- name: Install SDK dependencies
shell: bash
working-directory: link/sdks/typescript/client
run: |
set -euo pipefail
npm install --no-audit --no-fund
- name: Generate SDK production license report
shell: bash
run: |
set -euo pipefail
cd link/sdks/typescript/client
npx --yes license-checker --production --json > "$GITHUB_WORKSPACE/target/license/sdk-licenses.json"
- name: Install npm CLI dependencies
shell: bash
working-directory: link/sdks/typescript/cli
run: |
set -euo pipefail
npm install --ignore-scripts --no-audit --no-fund
- name: Generate npm CLI production license report
shell: bash
run: |
set -euo pipefail
cd link/sdks/typescript/cli
npx --yes license-checker --production --json > "$GITHUB_WORKSPACE/target/license/npm-cli-licenses.json"
- name: Validate licenses and generate third-party report
shell: bash
run: |
set -euo pipefail
python3 scripts/license_compliance.py \
--policy cargo-license-check.toml \
--rust-report target/license/rust-runtime-licenses.json \
--ui-report target/license/ui-licenses.json \
--sdk-report target/license/sdk-licenses.json \
--cli-report target/license/npm-cli-licenses.json \
--output target/license/THIRD_PARTY_LICENSES.md
- name: Upload license reports
uses: actions/upload-artifact@v6
with:
name: license-reports
path: target/license/
if-no-files-found: error