-
Notifications
You must be signed in to change notification settings - Fork 411
555 lines (474 loc) · 19.1 KB
/
primary.yml
File metadata and controls
555 lines (474 loc) · 19.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
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
name: BAML Runtime
on:
pull_request:
branches:
- canary
push:
paths:
- "engine/**"
- ".github/workflows/primary.yml"
- "typescript/**"
branches:
- canary
# need to run this periodically on the default branch to populate the build cache
schedule:
# daily at 2am PST
- cron: 0 10 * * *
merge_group:
types: [checks_requested]
workflow_dispatch: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: read
repository-projects: read
# Common environment variables
env:
# Turbo remote caching
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: gloo
jobs:
# Determine if runtime-related files have changed
# This job enables auto-pass when only baml_language/ or typescript/apps/beps/ files are modified
determine_changes:
name: "Determine changes"
runs-on: ubuntu-latest
outputs:
# Flag that is raised when runtime-related code is changed
# If false, we can skip all runtime tests since only baml_language/ or beps/ changed
runtime: ${{ steps.check_runtime.outputs.changed }}
skip_reason: ${{ steps.check_runtime.outputs.skip_reason }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Determine merge base
id: merge_base
env:
BASE_REF: ${{ github.event.pull_request.base.ref || 'canary' }}
run: |
sha=$(git merge-base HEAD "origin/${BASE_REF}" 2>/dev/null || echo "")
if [ -z "$sha" ]; then
# Fallback for workflow_dispatch or schedule
sha=$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD)
fi
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
- name: Check if runtime code changed
id: check_runtime
env:
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
run: |
# For scheduled runs, workflow_dispatch, or pushes to canary, always run
if [[ "${{ github.event_name }}" == "schedule" ]] || \
[[ "${{ github.event_name }}" == "workflow_dispatch" ]] || \
[[ "${{ github.ref }}" == "refs/heads/canary" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "skip_reason=" >> "$GITHUB_OUTPUT"
exit 0
fi
# Get list of all changed files
CHANGED_FILES=$(git diff --name-only "${MERGE_BASE}...HEAD" 2>/dev/null || echo "")
if [ -z "$CHANGED_FILES" ]; then
echo "No changes detected, running all tests"
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "skip_reason=" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Check if ALL changed files are in baml_language/ or typescript/apps/beps/ (auto-skip paths)
# If any file is outside these paths, we need to run the tests
RUNTIME_CHANGED="false"
ONLY_BAML_LANGUAGE="true"
ONLY_BEPS="true"
while IFS= read -r file; do
# Skip empty lines
[ -z "$file" ] && continue
# Check if file is in baml_language/
if [[ ! "$file" =~ ^baml_language/ ]]; then
ONLY_BAML_LANGUAGE="false"
fi
# Check if file is in typescript/apps/beps/
if [[ ! "$file" =~ ^typescript/apps/beps/ ]]; then
ONLY_BEPS="false"
fi
# Check if file is in a path that requires runtime tests
# Runtime tests are needed for: engine/, typescript/ (except beps), integ-tests/, .github/workflows/primary.yml
if [[ "$file" =~ ^engine/ ]] || \
[[ "$file" =~ ^integ-tests/ ]] || \
[[ "$file" == ".github/workflows/primary.yml" ]] || \
[[ "$file" =~ ^\.github/actions/ ]] || \
([[ "$file" =~ ^typescript/ ]] && [[ ! "$file" =~ ^typescript/apps/beps/ ]]); then
RUNTIME_CHANGED="true"
fi
done <<< "$CHANGED_FILES"
# Determine skip reason
SKIP_REASON=""
if [[ "$RUNTIME_CHANGED" == "false" ]]; then
if [[ "$ONLY_BAML_LANGUAGE" == "true" ]]; then
SKIP_REASON="Only baml_language/ files changed - these are covered by CI - BAML Language workflow"
elif [[ "$ONLY_BEPS" == "true" ]]; then
SKIP_REASON="Only typescript/apps/beps/ files changed - these are covered by CI - BAML Language BEPs workflow"
else
SKIP_REASON="No runtime-related files changed (only baml_language/ or typescript/apps/beps/)"
fi
fi
echo "Runtime changed: $RUNTIME_CHANGED"
echo "Skip reason: $SKIP_REASON"
echo "changed=${RUNTIME_CHANGED}" >> "$GITHUB_OUTPUT"
echo "skip_reason=${SKIP_REASON}" >> "$GITHUB_OUTPUT"
# Auto-pass summary when skipping runtime tests
skip-summary:
name: "Skip Summary"
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'false'
steps:
- name: Report skipped tests
run: |
echo "## ⏭️ BAML Runtime Tests Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Reason:** ${{ needs.determine_changes.outputs.skip_reason }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The BAML Runtime tests have been automatically skipped because the changes in this PR don't affect the runtime code." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### What this means:" >> $GITHUB_STEP_SUMMARY
echo "- ✅ No runtime code was modified" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Changes are covered by other CI workflows" >> $GITHUB_STEP_SUMMARY
echo "- ✅ This is an intentional optimization to reduce CI time" >> $GITHUB_STEP_SUMMARY
# Run all quality checks in parallel (lightweight setup)
lint:
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'true'
strategy:
matrix:
check:
[typescript-lint, rust-format, rust-lint, rust-lint-wasm, python-lint]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
# Setup Node.js for TypeScript lint
- name: Setup Node.js
if: matrix.check == 'typescript-lint'
uses: ./.github/actions/setup-node
with:
node-action-version: "v6"
# Setup Rust for Rust checks
- name: Setup Rust
if: contains(matrix.check, 'rust')
uses: ./.github/actions/setup-rust
with:
enable-wasm: ${{ matrix.check == 'rust-lint-wasm' && 'true' || 'false' }}
# Install protoc-gen-go for rust-lint (needed by baml_cffi build.rs)
- name: Setup Go
if: matrix.check == 'rust-lint'
uses: ./.github/actions/setup-go
- name: Setup Python
if: matrix.check == 'python-lint'
uses: ./.github/actions/setup-python
with:
cache: "false"
- name: Run TypeScript lint
if: matrix.check == 'typescript-lint'
run: pnpm format:ci
- name: Run Rust format check
if: matrix.check == 'rust-format'
run: |
# Ensure rustfmt is installed for the mise-managed toolchain
rustup component add rustfmt || true
cargo fmt --check -- --config imports_granularity=Crate --config group_imports=StdExternalCrate
working-directory: engine
- name: Run Rust lint (Clippy)
if: matrix.check == 'rust-lint'
run: RUSTFLAGS="-A unused -D warnings" cargo clippy --workspace -- -D clippy::print_stdout
working-directory: engine
- name: Run Rust lint WASM (Clippy)
if: matrix.check == 'rust-lint-wasm'
run: RUSTFLAGS="-A unused -D warnings" cargo clippy --target wasm32-unknown-unknown
working-directory: engine/baml-schema-wasm
- name: Run Python lint
if: matrix.check == 'python-lint'
run: |
cd integ-tests/python && uv run ruff check .
typecheck:
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
# Setup Node.js for TypeScript lint
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
node-action-version: "v6"
# Setup Rust for Rust checks
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
enable-wasm: true
# Install protoc-gen-go
- name: Setup Go
uses: ./.github/actions/setup-go
- name: Run typecheck for typescript and rust
run: pnpm typecheck --force
build-wasm:
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
targets: wasm32-unknown-unknown
enable-wasm: true
- name: Build rust for wasm32
run: cargo build --target=wasm32-unknown-unknown
working-directory: engine/baml-schema-wasm
# Test node generator (only needs CLI)
test-generators:
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
node-action-version: "v6"
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
enable-wasm: false
enable-cross: false
cache-on-failure: false
- name: Setup Go
uses: ./.github/actions/setup-go
with:
install-goimports: true
install-protoc-gen-go: false
- name: Test Generators (1 of 3)
run: |
pnpm build:debug && pnpm generate || (echo "::error:: merge canary and run codegen again" && exit 1)
working-directory: integ-tests/typescript
- name: Ensure No Changes (1 of 3)
run: |
git diff --exit-code || (echo "::error:: merge canary and run codegen again" && exit 1)
- name: Test Generators (2 of 3)
run: |
pnpm build:debug && pnpm generate || (echo "::error:: merge canary and run codegen again" && exit 1)
working-directory: integ-tests/typescript
- name: Ensure No Changes (2 of 3)
run: |
git diff --exit-code || (echo "::error:: merge canary and run codegen again" && exit 1)
- name: Test Generators (3 of 3)
run: |
pnpm build:debug && pnpm generate || (echo "::error:: merge canary and run codegen again" && exit 1)
working-directory: integ-tests/typescript
- name: Ensure No Changes (3 of 3)
run: |
git diff --exit-code || (echo "::error:: merge canary and run codegen again" && exit 1)
# Run tests in parallel (rebuild what's needed)
tests:
runs-on: ubuntu-latest
needs: determine_changes
if: needs.determine_changes.outputs.runtime == 'true'
strategy:
matrix:
test-suite: [rust-unit, python-integration]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Setup Go
uses: ./.github/actions/setup-go
- name: Setup Node.js
if: matrix.test-suite == 'python-integration'
uses: ./.github/actions/setup-node
with:
node-action-version: "v6"
- name: Setup Python
uses: ./.github/actions/setup-python
with:
cache: "false"
- name: Setup Ruby
if: matrix.test-suite == 'rust-unit'
uses: ./.github/actions/setup-ruby
- name: Run Rust unit tests
if: matrix.test-suite == 'rust-unit'
run: |
# Find Ruby library path and add it to LD_LIBRARY_PATH
RUBY_LIB_PATH=$(ruby -e 'puts RbConfig::CONFIG["libdir"]')
export LD_LIBRARY_PATH="${RUBY_LIB_PATH}:${LD_LIBRARY_PATH}"
# Build baml_cffi shared library
cargo build --package baml_cffi
echo "Listing current directory:"
ls -la
echo "Listing release directory:"
ls -la engine/target/release/libbaml_cffi.* || true
ls -la engine/target/release/baml_cffi.* || true
echo "Listing debug directory:"
ls -la engine/target/debug/libbaml_cffi.* || true
ls -la engine/target/debug/baml_cffi.* || true
export BAML_LIBRARY_PATH=${{ github.workspace }}/engine/target/debug/libbaml_cffi.so
echo "Listing BAML_LIBRARY_PATH:"
echo $BAML_LIBRARY_PATH
# list the contents of the BAML_LIBRARY_PATH
ls -la $BAML_LIBRARY_PATH
# Copy the dylib to a stable location to prevent cargo test from rebuilding it mid-test
# This fixes "file too short" errors caused by cargo truncating the file during rebuild
STABLE_DYLIB_PATH="${{ runner.temp }}/libbaml_cffi.so"
cp $BAML_LIBRARY_PATH "$STABLE_DYLIB_PATH"
echo "Copied dylib to stable location: $STABLE_DYLIB_PATH"
ls -la "$STABLE_DYLIB_PATH"
# Run tests
echo "BAML_LIBRARY_PATH=$STABLE_DYLIB_PATH" >> $GITHUB_ENV
BAML_LIBRARY_PATH="$STABLE_DYLIB_PATH" cargo test --features skip-integ-tests --verbose -- --nocapture
working-directory: engine
- name: Run Python integration tests
if: matrix.test-suite == 'python-integration'
run: |
cd integ-tests/python && ./run_tests.sh
# Build CLI for releases only
build-cli:
needs: determine_changes
if: github.event_name == 'release' && needs.determine_changes.outputs.runtime == 'true'
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
targets: ${{ matrix.target }}
- name: Setup Go
uses: ./.github/actions/setup-go
- name: Build CLI
run: cargo build --release --bin baml-cli --target ${{ matrix.target }}
working-directory: engine
- name: Upload CLI artifact
uses: actions/upload-artifact@v4
with:
name: baml-cli-${{ matrix.target }}
path: engine/target/release/baml-cli*
# CI Failure Alert - Required status check using "skipped = success" pattern
# See: https://devopsdirective.com/posts/2025/08/github-actions-required-checks-for-conditional-jobs/
#
# This job exploits GitHub's behavior where skipped jobs report as "Success".
# - When all tests pass (or are intentionally skipped): this job SKIPS → reports SUCCESS
# - When any test fails or is cancelled: this job RUNS and FAILS → blocks merge
#
# Configure "BAML Runtime / CI Failure Alert" as a required status check.
ci-failure-alert:
name: "CI Failure Alert"
runs-on: ubuntu-latest
needs:
- determine_changes
- lint
- typecheck
- build-wasm
- test-generators
- tests
# Only run if something failed or was cancelled (otherwise skip → success)
if: ${{ failure() || cancelled() }}
steps:
- name: Report failure
run: |
echo "## ❌ CI Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "One or more required jobs failed or were cancelled." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Result |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| lint | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| typecheck | ${{ needs.typecheck.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| build-wasm | ${{ needs.build-wasm.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| test-generators | ${{ needs.test-generators.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| tests | ${{ needs.tests.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::error::One or more CI jobs failed!"
exit 1
# Sync Zed extension to separate repository
sync-zed-repository:
runs-on: ubuntu-latest
needs: determine_changes
# Only run on pushes to canary branch or manual dispatch, and only if runtime changed
if: github.ref == 'refs/heads/canary' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && needs.determine_changes.outputs.runtime == 'true'
steps:
- name: Checkout main repository
uses: actions/checkout@v4
with:
path: main-repo
- name: Checkout zed-baml repository
uses: actions/checkout@v4
with:
repository: BoundaryML/zed-baml
token: ${{ secrets.SAM_BAML_ZED_GITHUB_TOKEN }}
path: zed-baml-repo
- name: Setup rsync
run: sudo apt-get update && sudo apt-get install -y rsync
- name: Sync zed directory contents
run: |
# Change to the source directory
cd main-repo/engine/zed
# Create a temporary directory for filtered content
mkdir -p /tmp/zed-sync
# Copy files respecting gitignore
rsync -av \
--exclude-from=.gitignore \
--exclude='.git' \
--exclude='.gitignore' \
./ /tmp/zed-sync/
# Copy the gitignore file separately (we want it in the target repo)
cp .gitignore /tmp/zed-sync/
- name: Update zed-baml repository
run: |
cd zed-baml-repo
# Remove all existing content except .git
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
# Copy new content
cp -r /tmp/zed-sync/* .
cp /tmp/zed-sync/.gitignore . 2>/dev/null || true
# Configure git
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
# Add and commit changes
git add .
# Check if there are changes to commit
if ! git diff --staged --quiet; then
git commit -m "Sync from main repository - $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
git push
echo "✅ Successfully synced zed extension to zed-baml repository"
else
echo "ℹ️ No changes to sync"
fi