Repository navigation
118 lines (101 loc) · 3.64 KB
/
Copy pathjs-sdk-node-example.yaml
File metadata and controls
118 lines (101 loc) · 3.64 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
name: js-sdk-node-example
on:
pull_request:
permissions:
contents: read
jobs:
test-node-example:
name: Test Braintrust Node Example
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js 20 for building
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install SDK dependencies
working-directory: js
run: pnpm install
- name: Build SDK
working-directory: js
run: npm run build
- name: Setup Node.js 14 for testing
uses: actions/setup-node@v4
with:
node-version: "14"
- name: Configure for CJS and update imports
working-directory: js/examples/otel
run: |
# Backup original files and use CJS versions
mv package.json package-esm.json.bak
cp package-cjs.json package.json
# Only swap tsconfig if it exists
if [ -f tsconfig.json ]; then
mv tsconfig.json tsconfig-esm.json.bak
fi
cp tsconfig-cjs.json tsconfig.json
# Update import to use compiled CJS dist files
sed -i 's|from "../../src"|from "../../dist/index.js"|g' nodesdk_example.ts
echo "Updated nodesdk_example.ts to use compiled CJS files"
- name: Install OTEL example dependencies
working-directory: js/examples/otel
run: npm install
- name: Compile example to JavaScript
working-directory: js/examples/otel
run: |
npm run build
echo "Verifying compiled file exists..."
ls -la nodesdk_example.js
echo "Compiled successfully!"
- name: Verify OTEL dependencies installed
working-directory: js/examples/otel
run: |
echo "Verifying OTEL packages installed..."
packages=(
"@opentelemetry/api"
"@opentelemetry/sdk-trace-base"
"@opentelemetry/sdk-node"
"@opentelemetry/context-async-hooks"
"openai"
)
for package in "${packages[@]}"; do
if [ ! -d "node_modules/$package" ]; then
echo "❌ Package $package not found"
exit 1
fi
echo "✅ $package verified"
done
echo "All required packages verified successfully"
- name: Check if API key is available
id: check_api_key
run: |
if [ -z "${{ secrets.BRAINTRUST_API_KEY }}" ]; then
echo "api_key_available=false" >> $GITHUB_OUTPUT
echo "⚠️ BRAINTRUST_API_KEY secret not set - test will be skipped"
else
echo "api_key_available=true" >> $GITHUB_OUTPUT
fi
- name: Run OTEL example with npm start
if: steps.check_api_key.outputs.api_key_available == 'true'
working-directory: js/examples/otel
env:
BRAINTRUST_OTEL_COMPAT: false
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
run: |
node -e "console.log('ESM mode:', typeof import.meta.url === 'string')"
npm start
- name: Restore original config files
if: always()
working-directory: js/examples/otel
run: |
# Restore original files
mv package-esm.json.bak package.json || true
if [ -f tsconfig-esm.json.bak ]; then
mv tsconfig-esm.json.bak tsconfig.json || true
fi
# Restore original imports and remove compiled file
git checkout nodesdk_example.ts || true
rm -f nodesdk_example.js || true