-
Notifications
You must be signed in to change notification settings - Fork 4
576 lines (491 loc) Β· 20 KB
/
Copy pathpublish-bun.yml
File metadata and controls
576 lines (491 loc) Β· 20 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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
name: Publish to GitHub Packages (Bun Compatible)
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (semantic version)'
required: true
type: string
dry_run:
description: 'Run in dry-run mode only'
required: false
type: boolean
default: true
tag:
description: 'Bun tag (latest, beta, alpha, etc.)'
required: false
type: string
default: 'latest'
push:
tags:
- 'bun-v*'
release:
types: [published]
permissions:
contents: write
packages: write
id-token: write
jobs:
validate:
name: Validate Package for Bun
runs-on: ubuntu-latest
defaults:
run:
working-directory: terraphim_ai_nodejs
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Check package.json validity
run: |
bun -e "const pkg = require('./package.json'); console.log('Package name:', pkg.name); console.log('Version:', pkg.version);"
- name: Validate Bun compatibility
run: |
# Test that the package works correctly with Bun
bun -e "
const pkg = require('./package.json');
console.log('Package loaded successfully with Bun');
console.log('Bun metadata:', pkg.bun);
"
- name: Validate version format
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/tags\/bun-v//')
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi
echo "Version to publish: $VERSION"
fi
build:
name: Build Multi-Platform Binaries for Bun
runs-on: ${{ matrix.settings.host }}
needs: validate
defaults:
run:
working-directory: terraphim_ai_nodejs
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: macos-latest
target: aarch64-apple-darwin
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_docker: true
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
if: ${{ !matrix.settings.use_docker }}
with:
node-version: '20'
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.use_docker }}
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
.cargo-cache
target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
- name: Install dependencies
if: ${{ !matrix.settings.use_docker }}
run: yarn install --frozen-lockfile
- name: Build custom Docker image for aarch64
if: ${{ matrix.settings.use_docker }}
working-directory: ${{ github.workspace }}
run: |
docker build -t terraphim-napi-aarch64:latest -f docker/Dockerfile.napi-aarch64 .
- name: Build in docker
if: ${{ matrix.settings.use_docker }}
working-directory: ${{ github.workspace }}
run: |
docker run --rm \
-v ${{ github.workspace }}:/build \
-w /build/terraphim_ai_nodejs \
terraphim-napi-aarch64:latest \
bash -c "yarn install --frozen-lockfile && yarn build --target ${{ matrix.settings.target }}"
- name: Build
run: yarn build --target ${{ matrix.settings.target }}
if: ${{ !matrix.settings.use_docker }}
- name: Upload artifact
uses: actions/upload-artifact@v5
with:
name: bindings-${{ matrix.settings.target }}
path: terraphim_ai_nodejs/*.node
if-no-files-found: error
test-bun-compatibility:
name: Test Bun Compatibility
runs-on: ${{ matrix.settings.os }}
needs: build
# Tests are advisory - don't block publish on test failures
continue-on-error: true
defaults:
run:
working-directory: terraphim_ai_nodejs
strategy:
fail-fast: false
matrix:
settings:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bun:
- 'latest'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ matrix.bun }}
- name: Install dependencies
run: bun install
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: terraphim_ai_nodejs
- name: Test package functionality with Bun
run: |
# Create Bun-specific test
cat > test-bun-functionality.js << 'EOF'
import * as pkg from './index.js';
console.log('Testing package functionality with Bun v' + process.versions.bun);
console.log('Available functions:', Object.keys(pkg));
// Test autocomplete functionality
if (typeof pkg.buildAutocompleteIndexFromJson === 'function') {
console.log('buildAutocompleteIndexFromJson available');
const thesaurus = {
name: "Test",
data: {
"machine learning": {
id: 1,
nterm: "machine learning",
url: "https://example.com/ml"
}
}
};
const indexBytes = pkg.buildAutocompleteIndexFromJson(JSON.stringify(thesaurus));
console.log('Autocomplete index built:', indexBytes.length, 'bytes');
// Convert to Buffer for Bun compatibility
const indexBuffer = Buffer.from(indexBytes);
const results = pkg.autocomplete(indexBuffer, "machine", 10);
console.log('Autocomplete search results:', results.length, 'items');
}
// Test knowledge graph functionality
if (typeof pkg.buildRoleGraphFromJson === 'function') {
console.log('buildRoleGraphFromJson available');
const thesaurus = {
name: "Test",
data: {
"machine learning": {
id: 1,
nterm: "machine learning",
url: "https://example.com/ml"
}
}
};
const graphBytes = pkg.buildRoleGraphFromJson("Test Role", JSON.stringify(thesaurus));
console.log('Role graph built:', graphBytes.length, 'bytes');
// Convert to Buffer for Bun compatibility
const graphBuffer = Buffer.from(graphBytes);
const stats = pkg.getGraphStats(graphBuffer);
console.log('Graph stats loaded:', stats);
}
console.log('All functionality tests passed with Bun!');
EOF
bun test-bun-functionality.js
- name: Test performance with Bun
run: |
# Performance benchmark
cat > benchmark-bun.js << 'EOF'
import * as pkg from './index.js';
import { performance } from 'perf_hooks';
const thesaurus = {
name: "Performance Test",
data: {
"machine learning": { id: 1, nterm: "machine learning", url: "https://example.com/ml" },
"deep learning": { id: 2, nterm: "deep learning", url: "https://example.com/dl" },
"neural networks": { id: 3, nterm: "neural networks", url: "https://example.com/nn" }
}
};
// Benchmark autocomplete
const start = performance.now();
const indexBytes = pkg.buildAutocompleteIndexFromJson(JSON.stringify(thesaurus));
const buildTime = performance.now() - start;
// Convert to Buffer for Bun compatibility
const indexBuffer = Buffer.from(indexBytes);
const searchStart = performance.now();
const results = pkg.autocomplete(indexBuffer, "machine", 10);
const searchTime = performance.now() - searchStart;
console.log('Performance Metrics (Bun):');
console.log(' - Index building:', buildTime.toFixed(2), 'ms');
console.log(' - Search time:', searchTime.toFixed(2), 'ms');
console.log(' - Results found:', results.length);
console.log(' - Index size:', indexBytes.length, 'bytes');
EOF
bun benchmark-bun.js
create-universal-macos-bun:
name: Create Universal macOS Binary for Bun
runs-on: macos-latest
needs: build
# Universal binary is optional - don't block on failure
continue-on-error: true
defaults:
run:
working-directory: terraphim_ai_nodejs
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Download macOS x64 artifact
uses: actions/download-artifact@v4
with:
name: bindings-x86_64-apple-darwin
path: ${{ github.workspace }}/artifacts
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v4
with:
name: bindings-aarch64-apple-darwin
path: ${{ github.workspace }}/artifacts
- name: Create universal binary
working-directory: ${{ github.workspace }}/artifacts
run: |
echo "Files in artifacts directory:"
ls -la
# Find the actual .node files
X64_NODE=$(find . -name "*.darwin-x64.node" -o -name "*x86_64-apple-darwin.node" | head -1)
ARM64_NODE=$(find . -name "*.darwin-arm64.node" -o -name "*aarch64-apple-darwin.node" | head -1)
echo "x64 node: $X64_NODE"
echo "arm64 node: $ARM64_NODE"
if [ -n "$X64_NODE" ] && [ -n "$ARM64_NODE" ]; then
lipo -create "$X64_NODE" "$ARM64_NODE" -output terraphim_ai_nodejs.darwin-universal.node
ls -la *.node
else
echo "Could not find both architecture binaries"
exit 1
fi
- name: Upload universal binary
uses: actions/upload-artifact@v5
with:
name: bindings-universal-apple-darwin
path: ${{ github.workspace }}/artifacts/terraphim_ai_nodejs.darwin-universal.node
if-no-files-found: error
publish-to-bun:
name: Publish to GitHub Packages
runs-on: [self-hosted, Linux]
needs: build
# Run after builds complete (tests and universal are optional)
if: always() && needs.build.result == 'success'
environment: production
defaults:
run:
working-directory: terraphim_ai_nodejs
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
scope: '@terraphim'
- name: Verify GitHub token
run: |
echo "Using GITHUB_TOKEN for GitHub Packages authentication"
echo "Registry: https://npm.pkg.github.com"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifacts
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Prepare package for Bun publishing
run: |
# Copy all built binaries to package directory
find ${{ github.workspace }}/artifacts -name "*.node" -exec cp {} . \;
# List what we have
echo "Built binaries for Bun:"
ls -la *.node || echo "No .node files found"
# Update package.json version if provided (skip npm scripts)
if [[ "${{ inputs.version }}" != "" ]]; then
echo "Updating version to ${{ inputs.version }}"
npm version ${{ inputs.version }} --no-git-tag-version --ignore-scripts
fi
- name: Configure package managers
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure npm for GitHub Packages
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
echo "@terraphim:registry=https://npm.pkg.github.com" >> ~/.npmrc
# Configure Bun registry for GitHub Packages
cat > ~/.bunfig.toml << 'EOF'
[install.scopes]
"@terraphim" = { url = "https://npm.pkg.github.com", token = "$NODE_AUTH_TOKEN" }
EOF
# Show current package info
echo "Package information:"
npm pack --dry-run | head -20
- name: Determine publishing strategy
id: strategy
run: |
VERSION_TYPE="patch"
REGISTRY="npm"
NPM_TAG="latest"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ inputs.version }}" != "" ]]; then
VERSION_TYPE="manual"
NPM_TAG="${{ inputs.tag }}"
fi
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then
VERSION_TAG=$(echo "${{ github.ref }}" | sed 's/refs\/tags\/bun-v//')
if [[ "$VERSION_TAG" =~ -beta$ ]]; then
NPM_TAG="beta"
elif [[ "$VERSION_TAG" =~ -alpha$ ]]; then
NPM_TAG="alpha"
elif [[ "$VERSION_TAG" =~ -rc ]]; then
NPM_TAG="rc"
else
NPM_TAG="latest"
fi
elif [[ "${{ github.event_name }}" == "release" ]]; then
NPM_TAG="latest"
fi
echo "version_type=$VERSION_TYPE" >> $GITHUB_OUTPUT
echo "npm_tag=$NPM_TAG" >> $GITHUB_OUTPUT
echo "registry=$REGISTRY" >> $GITHUB_OUTPUT
echo "π― Publishing strategy: $VERSION_TYPE -> $NPM_TAG ($REGISTRY)"
- name: Run napi prepublish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Running napi prepublish to create platform packages..."
# Run napi prepublish - it may fail if release exists, that's ok
npx napi prepublish -t npm --skip-gh-release || echo "napi prepublish completed (release may already exist)"
echo "Platform packages created:"
ls -la npm/ 2>/dev/null || echo "No npm/ directory"
- name: Publish to GitHub Packages (works with Bun)
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
echo "Dry run mode - checking package only"
npm publish --dry-run --access public --tag ${{ steps.strategy.outputs.npm_tag }} --ignore-scripts
else
echo "Publishing @terraphim/autocomplete to GitHub Packages"
echo "Registry: https://npm.pkg.github.com"
echo "Tag: ${{ steps.strategy.outputs.npm_tag }}"
# Publish to GitHub Packages
npm publish --access public --tag ${{ steps.strategy.outputs.npm_tag }} --ignore-scripts
echo "Package published successfully!"
echo "Install with: npm install @terraphim/autocomplete --registry=https://npm.pkg.github.com"
echo "Or with Bun: bun add @terraphim/autocomplete"
fi
- name: Verify package on GitHub Packages
if: inputs.dry_run != 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Verifying package on GitHub Packages..."
# Wait a moment for registry to update
sleep 10
# Check if package is available
PACKAGE_NAME="@terraphim/autocomplete"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "Checking: $PACKAGE_NAME@$PACKAGE_VERSION"
npm view $PACKAGE_NAME@$PACKAGE_VERSION --registry=https://npm.pkg.github.com || echo "Package not immediately visible (may take a few minutes)"
echo "Package verification completed"
echo "GitHub Packages URL: https://github.com/terraphim/terraphim-ai/packages"
- name: Create Bun-specific GitHub Release
if: startsWith(github.ref, 'refs/tags/') && inputs.dry_run != 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: "@terraphim/autocomplete ${{ github.ref_name }} (Bun Optimized)"
body: |
## Node.js Package Release (Bun Compatible)
**Package**: `@terraphim/autocomplete`
**Version**: ${{ steps.strategy.outputs.version_type }}
**Tag**: ${{ steps.strategy.outputs.npm_tag }}
**Runtime**: Bun Optimized
### π Installation Options
**With Bun (Recommended):**
```bash
bun add @terraphim/autocomplete@${{ steps.strategy.outputs.npm_tag }}
```
**With npm:**
```bash
npm install @terraphim/autocomplete@${{ steps.strategy.outputs.npm_tag }}
```
**With yarn:**
```bash
yarn add @terraphim/autocomplete@${{ steps.strategy.outputs.npm_tag }}
```
### β‘ Bun Performance Benefits
- **π Faster Installation**: Bun's native package manager
- **π¦ Optimized Dependencies**: Better dependency resolution
- **π§ͺ Native Testing**: Built-in test runner
- **β‘ Hot Reloading**: Faster development cycles
### β¨ Features
- **Autocomplete**: Fast prefix search with scoring
- **Knowledge Graph**: Semantic connectivity analysis
- **Native Performance**: Rust backend with NAPI bindings
- **Cross-Platform**: Linux, macOS, Windows support
- **TypeScript**: Auto-generated type definitions
### π Performance
- **Autocomplete Index**: ~749 bytes
- **Knowledge Graph**: ~856 bytes
- **Native Library**: ~10MB (optimized for production)
### π Bun-Specific Features
- **Native Module Loading**: Optimized for Bun's runtime
- **Fast Test Execution**: Bun's test runner integration
- **Enhanced Dependency Resolution**: Faster and more accurate
### Links
- [GitHub Package](https://github.com/terraphim/terraphim-ai/packages)
- [Bun documentation](https://bun.sh/docs)
- [Package Documentation](https://github.com/terraphim/terraphim-ai/tree/main/terraphim_ai_nodejs)
---
π€ Generated on: $(date)
π’ Bun-optimized with love from Terraphim AI
draft: false
prerelease: ${{ steps.strategy.outputs.npm_tag != 'latest' }}
- name: Notify on success
if: inputs.dry_run != 'true'
run: |
echo "Publishing workflow completed successfully!"
echo "Package: @terraphim/autocomplete"
echo "Registry: GitHub Packages (npm.pkg.github.com)"
echo "Tag: ${{ steps.strategy.outputs.npm_tag }}"
echo "Version: $(node -p "require('./package.json').version")"
echo ""
echo "Install with:"
echo " npm install @terraphim/autocomplete --registry=https://npm.pkg.github.com"
echo " bun add @terraphim/autocomplete"