-
Notifications
You must be signed in to change notification settings - Fork 0
473 lines (409 loc) · 16.2 KB
/
ci.yml
File metadata and controls
473 lines (409 loc) · 16.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
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
name: CI
on:
push:
branches: [main, dev]
tags: ["v*"]
pull_request:
branches: [main]
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm install --ignore-scripts
- run: npx prettier --check .
build-linux-glibc:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install system dependencies
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list
sudo apt-get update
sudo apt-get install -y llvm-21 llvm-21-dev clang-21 lld-21 \
cmake make gcc g++ \
autoconf automake libtool \
libzstd-dev zlib1g-dev libsqlite3-dev libcurl4-openssl-dev
sudo ln -sf /usr/bin/llc-21 /usr/bin/llc
sudo ln -sf /usr/bin/opt-21 /usr/bin/opt
sudo ln -sf /usr/bin/clang-21 /usr/bin/clang
clang --version 2>&1 | head -2
llc --version 2>&1 | head -4
- name: Install npm dependencies
run: npm install
- name: Cache vendor libraries
uses: actions/cache@v4
with:
path: |
vendor/
c_bridges/*.o
key: vendor-${{ runner.os }}-${{ hashFiles('scripts/build-vendor.sh', 'scripts/vendor-pins.sh', 'c_bridges/*.c') }}
- name: Build vendor libraries
run: bash scripts/build-vendor.sh
- name: Build compiler
run: npm run build
- name: Verify vendor libraries
run: |
fail=0
for lib in vendor/bdwgc/libgc.a vendor/yyjson/libyyjson.a vendor/libuv/build/libuv.a vendor/picohttpparser/picohttpparser.o c_bridges/lws-bridge.o c_bridges/multipart-bridge.o c_bridges/regex-bridge.o c_bridges/child-process-bridge.o c_bridges/child-process-spawn.o c_bridges/os-bridge.o c_bridges/time-bridge.o c_bridges/base64-bridge.o c_bridges/url-bridge.o c_bridges/dotenv-bridge.o c_bridges/watch-bridge.o; do
if [ ! -f "$lib" ]; then
echo "MISSING: $lib"
fail=1
else
echo "OK: $lib ($(wc -c < "$lib") bytes)"
fi
done
if [ "$fail" -eq 1 ]; then
echo "Vendor library build incomplete - aborting before tests"
exit 1
fi
- name: Build tree-sitter TSX objects
run: |
mkdir -p build
TS_SRC=node_modules/tree-sitter-typescript/tsx/src
TS_INCLUDE=node_modules/tree-sitter-typescript
clang -c -O2 -fPIC -I $TS_SRC -I $TS_INCLUDE $TS_SRC/parser.c -o build/tree-sitter-typescript-parser.o
clang -c -O2 -fPIC -I $TS_SRC -I $TS_INCLUDE $TS_SRC/scanner.c -o build/tree-sitter-typescript-scanner.o
clang -c -O2 -fPIC -I vendor/tree-sitter/lib/include c_bridges/treesitter-bridge.c -o build/treesitter-bridge.o
- name: Build native chad
run: node dist/chad-node.js build src/chad-native.ts -o .build/chad --target-cpu=x86-64
- name: Run unit tests (node compiler)
run: npm run test:node
timeout-minutes: 10
- name: Run unit tests (native compiler)
run: npm run test:native
timeout-minutes: 10
- name: Smoke test native chad
run: |
.build/chad build examples/hello.ts -o /tmp/hello
/tmp/hello
- name: Run examples
run: bash scripts/run-examples.sh
timeout-minutes: 5
- name: Run self-hosting tests
run: node --import tsx --test tests/self-hosting.test.ts
timeout-minutes: 15
- name: Build target SDK
run: bash scripts/build-target-sdk.sh
- name: Package release artifact
run: |
mkdir -p release/lib
cp .build/chad release/
cp build/tree-sitter-typescript-parser.o release/lib/
cp build/tree-sitter-typescript-scanner.o release/lib/
cp build/treesitter-bridge.o release/lib/
cp vendor/tree-sitter/libtree-sitter.a release/lib/
cp vendor/bdwgc/libgc.a release/lib/
cp vendor/yyjson/libyyjson.a release/lib/
cp vendor/libuv/build/libuv.a release/lib/
cp vendor/picohttpparser/picohttpparser.o release/lib/
cp c_bridges/lws-bridge.o release/lib/
cp c_bridges/multipart-bridge.o release/lib/
cp c_bridges/regex-bridge.o release/lib/
cp c_bridges/child-process-bridge.o release/lib/
cp c_bridges/child-process-spawn.o release/lib/
cp c_bridges/os-bridge.o release/lib/
cp c_bridges/time-bridge.o c_bridges/base64-bridge.o c_bridges/url-bridge.o release/lib/
cp c_bridges/dotenv-bridge.o release/lib/
cp c_bridges/watch-bridge.o release/lib/
tar -czf chadscript-linux-x64.tar.gz -C release chad lib
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: chadscript-linux-x64
path: chadscript-linux-x64.tar.gz
- name: Upload target SDK
uses: actions/upload-artifact@v4
with:
name: chadscript-target-linux-x64
path: chadscript-target-linux-x64.tar.gz
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install system dependencies
run: |
brew install llvm cmake autoconf automake libtool zstd
echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH
- name: Install npm dependencies
run: npm install
- name: Cache vendor libraries
uses: actions/cache@v4
with:
path: |
vendor/
c_bridges/*.o
key: vendor-${{ runner.os }}-${{ hashFiles('scripts/build-vendor.sh', 'scripts/vendor-pins.sh', 'c_bridges/*.c') }}
- name: Build vendor libraries
run: bash scripts/build-vendor.sh
- name: Build compiler
run: npm run build
- name: Verify vendor libraries
run: |
fail=0
for lib in vendor/bdwgc/libgc.a vendor/yyjson/libyyjson.a vendor/libuv/build/libuv.a vendor/picohttpparser/picohttpparser.o c_bridges/lws-bridge.o c_bridges/multipart-bridge.o c_bridges/regex-bridge.o c_bridges/child-process-bridge.o c_bridges/child-process-spawn.o c_bridges/os-bridge.o c_bridges/time-bridge.o c_bridges/base64-bridge.o c_bridges/url-bridge.o c_bridges/dotenv-bridge.o c_bridges/watch-bridge.o; do
if [ ! -f "$lib" ]; then
echo "MISSING: $lib"
fail=1
else
echo "OK: $lib"
fi
done
if [ "$fail" -eq 1 ]; then
echo "Vendor library build incomplete - aborting before tests"
exit 1
fi
- name: Build tree-sitter TSX objects
run: |
mkdir -p build
TS_SRC=node_modules/tree-sitter-typescript/tsx/src
TS_INCLUDE=node_modules/tree-sitter-typescript
clang -c -O2 -fPIC -I $TS_SRC -I $TS_INCLUDE $TS_SRC/parser.c -o build/tree-sitter-typescript-parser.o
clang -c -O2 -fPIC -I $TS_SRC -I $TS_INCLUDE $TS_SRC/scanner.c -o build/tree-sitter-typescript-scanner.o
clang -c -O2 -fPIC -I vendor/tree-sitter/lib/include c_bridges/treesitter-bridge.c -o build/treesitter-bridge.o
- name: Build native chad
run: node dist/chad-node.js build src/chad-native.ts -o .build/chad
- name: Run unit tests (node compiler)
run: npm run test:node
timeout-minutes: 10
- name: Run unit tests (native compiler)
run: npm run test:native
timeout-minutes: 10
- name: Sign macOS binaries
run: |
codesign --sign - --force .build/chad
- name: Smoke test native chad
run: |
.build/chad build examples/hello.ts -o /tmp/hello
/tmp/hello
- name: Run examples
run: bash scripts/run-examples.sh
timeout-minutes: 5
- name: Run self-hosting tests
run: node --import tsx --test tests/self-hosting.test.ts
timeout-minutes: 15
- name: Build target SDK
run: bash scripts/build-target-sdk.sh
- name: Package release artifact
run: |
mkdir -p release/lib
cp .build/chad release/
cp build/tree-sitter-typescript-parser.o release/lib/
cp build/tree-sitter-typescript-scanner.o release/lib/
cp build/treesitter-bridge.o release/lib/
cp vendor/tree-sitter/libtree-sitter.a release/lib/
cp vendor/bdwgc/libgc.a release/lib/
cp vendor/yyjson/libyyjson.a release/lib/
cp vendor/libuv/build/libuv.a release/lib/
cp vendor/picohttpparser/picohttpparser.o release/lib/
cp c_bridges/lws-bridge.o release/lib/
cp c_bridges/multipart-bridge.o release/lib/
cp c_bridges/regex-bridge.o release/lib/
cp c_bridges/child-process-bridge.o release/lib/
cp c_bridges/child-process-spawn.o release/lib/
cp c_bridges/os-bridge.o release/lib/
cp c_bridges/time-bridge.o c_bridges/base64-bridge.o c_bridges/url-bridge.o release/lib/
cp c_bridges/dotenv-bridge.o release/lib/
cp c_bridges/watch-bridge.o release/lib/
tar -czf chadscript-macos-arm64.tar.gz -C release chad lib
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: chadscript-macos-arm64
path: chadscript-macos-arm64.tar.gz
- name: Upload target SDK
uses: actions/upload-artifact@v4
with:
name: chadscript-target-macos-arm64
path: chadscript-target-macos-arm64.tar.gz
test-artifact:
needs: [build-linux-glibc, build-macos]
strategy:
matrix:
include:
- os: ubuntu-22.04
artifact: chadscript-linux-x64
- os: macos-latest
artifact: chadscript-macos-arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list
sudo apt-get update
sudo apt-get install -y llvm-21 clang-21 libsqlite3-dev libzstd-dev zlib1g-dev
sudo ln -sf /usr/bin/llc-21 /usr/bin/llc
sudo ln -sf /usr/bin/opt-21 /usr/bin/opt
sudo ln -sf /usr/bin/clang-21 /usr/bin/clang
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install llvm zstd
echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
- name: Install via install.sh
run: |
SKIP_PROMPTS=1 CHADSCRIPT_URL="file://$(pwd)/${{ matrix.artifact }}.tar.gz" bash install.sh
echo "$HOME/.chadscript" >> $GITHUB_PATH
- name: Verify binary
run: |
file ~/.chadscript/chad.bin
ls -la ~/.chadscript/lib/
- name: Verify lib/ contains all required artifacts
run: |
fail=0
for lib in \
libgc.a \
libyyjson.a \
libuv.a \
libtree-sitter.a \
picohttpparser.o \
lws-bridge.o \
multipart-bridge.o \
regex-bridge.o \
child-process-bridge.o \
child-process-spawn.o \
os-bridge.o \
time-bridge.o \
dotenv-bridge.o \
watch-bridge.o \
tree-sitter-typescript-parser.o \
tree-sitter-typescript-scanner.o \
treesitter-bridge.o; do
if [ ! -f "$HOME/.chadscript/lib/$lib" ]; then
echo "MISSING from release: lib/$lib"
fail=1
else
echo "OK: lib/$lib ($(wc -c < "$HOME/.chadscript/lib/$lib") bytes)"
fi
done
if [ "$fail" -eq 1 ]; then
echo ""
echo "ERROR: Release artifact is missing required library files."
echo "Check the 'Package release artifact' step in the build job."
exit 1
fi
echo ""
echo "All $(ls ~/.chadscript/lib/ | wc -l) library files present."
- name: Smoke test - hello world
run: |
echo 'console.log("Hello from release artifact!");' > /tmp/hello.ts
chad run /tmp/hello.ts
- name: Smoke test - compile to binary
run: |
echo 'process.exit(42);' > /tmp/exit42.ts
chad build /tmp/exit42.ts -o /tmp/exit42
/tmp/exit42 || [ $? -eq 42 ]
- name: Smoke test - JSON bridge (libyyjson)
run: |
cat > /tmp/test-json.ts << 'EOF'
interface JsonObj {
name: string;
version: number;
}
const obj = JSON.parse<JsonObj>('{"name":"chad","version":1}');
const back = JSON.stringify(obj);
if (back.includes("chad")) {
console.log("TEST_PASSED");
}
EOF
OUTPUT=$(chad run /tmp/test-json.ts)
echo "$OUTPUT"
echo "$OUTPUT" | grep -q "TEST_PASSED"
- name: Smoke test - regex bridge
run: |
cat > /tmp/test-regex.ts << 'EOF'
function main(): void {
const re = /hello/;
const result = "hello world".match(re);
if (result !== null && result[0] === "hello") {
console.log("TEST_PASSED");
}
}
main();
EOF
OUTPUT=$(chad run /tmp/test-regex.ts)
echo "$OUTPUT"
echo "$OUTPUT" | grep -q "TEST_PASSED"
- name: Smoke test - child_process bridge
run: |
cat > /tmp/test-execsync.ts << 'EOF'
import { execSync } from "child_process";
function main(): void {
const output = execSync("echo bridge_works");
if (output.trim() === "bridge_works") {
console.log("TEST_PASSED");
}
}
main();
EOF
OUTPUT=$(chad run /tmp/test-execsync.ts)
echo "$OUTPUT"
echo "$OUTPUT" | grep -q "TEST_PASSED"
- name: Smoke test - compile hackernews example (exercises HTTP + sqlite bridges)
run: |
chad build examples/hackernews/app.ts -o /tmp/hackernews
file /tmp/hackernews
echo "Hackernews example compiled successfully"
release:
needs: [build-linux-glibc, build-macos, test-artifact]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Delete old latest release
run: gh release delete latest --yes --cleanup-tag 2>/dev/null || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
- name: Create latest release
run: |
gh release create latest \
--title "Latest Build" \
--notes "Automated release from ${GITHUB_REF_NAME} branch. Download native binaries and target SDKs below." \
--latest \
artifacts/**/*.tar.gz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
tagged-release:
needs: [build-linux-glibc, build-macos, test-artifact]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: artifacts/**/*.tar.gz
generate_release_notes: true