Skip to content

Commit 5e069f4

Browse files
committed
Add Cloudflare Workers testing to GitHub Actions matrix
- Add comprehensive CI workflow with Cloudflare Workers testing - Add dedicated Cloudflare Workers test workflow - Include edge environment testing with memory constraints - Add health check endpoint to worker example - Create test script for Cloudflare Workers compatibility - Test both CommonJS and ESM builds in Workers environment - Add documentation for setting up Cloudflare Workers testing This addresses issues that may only occur in Cloudflare Node.js compact environments by ensuring the SDK is tested in those specific conditions.
1 parent 2bd4fc7 commit 5e069f4

File tree

7 files changed

+658
-3
lines changed

7 files changed

+658
-3
lines changed

.github/workflows/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# GitHub Actions Workflows
2+
3+
This directory contains GitHub Actions workflows for testing the Nylas Node.js SDK in various environments, including Cloudflare Workers.
4+
5+
## Workflows
6+
7+
### `ci.yml`
8+
Comprehensive CI workflow that tests the SDK across:
9+
- Multiple Node.js versions (16, 18, 20, 22)
10+
- Cloudflare Workers environment
11+
- Edge-like environments with memory constraints
12+
- Different module formats (CommonJS, ESM, CJS wrapper)
13+
- Security audits
14+
15+
### `cloudflare-workers-test.yml`
16+
Focused workflow for testing Cloudflare Workers compatibility:
17+
- Tests SDK in Cloudflare Workers environment
18+
- Validates optional types work correctly
19+
- Tests both CommonJS and ESM builds
20+
- Optional deployment testing (requires secrets)
21+
22+
## Cloudflare Workers Testing Setup
23+
24+
### Required Secrets
25+
26+
To enable full Cloudflare Workers testing (including deployment), add these secrets to your GitHub repository:
27+
28+
1. **CLOUDFLARE_API_TOKEN**: Your Cloudflare API token
29+
- Go to [Cloudflare Dashboard](https://dash.cloudflare.com/) → My Profile → API Tokens
30+
- Create a token with "Edit Cloudflare Workers" permissions
31+
- Copy the token value
32+
33+
2. **CLOUDFLARE_ACCOUNT_ID**: Your Cloudflare account ID
34+
- Find this in your Cloudflare dashboard under "Overview"
35+
36+
### Setting Up Secrets
37+
38+
1. Go to your GitHub repository
39+
2. Navigate to Settings → Secrets and variables → Actions
40+
3. Click "New repository secret"
41+
4. Add both `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`
42+
43+
### Testing Without Secrets
44+
45+
The workflows will still run and test Cloudflare Workers compatibility even without these secrets. The deployment step will be skipped, but all local testing will still occur.
46+
47+
### Local Testing
48+
49+
You can also test Cloudflare Workers compatibility locally:
50+
51+
```bash
52+
# Install dependencies
53+
npm ci
54+
55+
# Build the SDK
56+
npm run build
57+
58+
# Test in the edge environment
59+
cd examples/edge-environment
60+
npm install
61+
npm run dev # Start local development server
62+
```
63+
64+
## What Gets Tested
65+
66+
### Cloudflare Workers Environment
67+
- SDK can be imported in Cloudflare Workers context
68+
- Optional types work correctly (no TypeScript errors)
69+
- Both CommonJS and ESM builds are compatible
70+
- Client creation works without errors
71+
- Memory constraints are handled properly
72+
73+
### Edge-like Environments
74+
- Tests with reduced memory limits (64MB, 128MB)
75+
- Optimized Node.js settings for compact environments
76+
- Verifies SDK works in constrained environments
77+
78+
### Module Format Compatibility
79+
- CommonJS (`require()`)
80+
- ESM (`import`)
81+
- CJS wrapper for better compatibility
82+
83+
## Troubleshooting
84+
85+
### Common Issues
86+
87+
1. **Worker deployment fails**: Check that your Cloudflare API token has the correct permissions
88+
2. **Type errors in Workers**: Ensure optional types are properly defined in the SDK
89+
3. **Memory issues**: The edge environment tests help identify memory-related problems
90+
91+
### Debugging
92+
93+
- Check the workflow logs for specific error messages
94+
- Test locally using the edge environment example
95+
- Verify your Cloudflare account has Workers enabled

.github/workflows/ci.yml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- cursor/make-type-optional-and-update-changelog-23e9
7+
- main
8+
- develop
9+
pull_request:
10+
branches:
11+
- main
12+
- develop
13+
14+
jobs:
15+
# Standard Node.js testing across multiple versions
16+
test:
17+
name: Test Node.js ${{ matrix.node-version }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
node-version: [16, 18, 20, 22]
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
cache: 'npm'
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Run linting
36+
run: npm run lint:ci
37+
38+
- name: Run tests
39+
run: npm test
40+
41+
- name: Run type checking
42+
run: npx tsc --noEmit
43+
44+
# Test in Cloudflare Workers environment
45+
test-cloudflare-workers:
46+
name: Test in Cloudflare Workers
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Node.js
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version: '20'
56+
cache: 'npm'
57+
58+
- name: Install dependencies
59+
run: npm ci
60+
61+
- name: Install Wrangler CLI
62+
run: npm install -g wrangler@latest
63+
64+
- name: Build the SDK
65+
run: npm run build
66+
67+
- name: Setup Cloudflare Worker test environment
68+
run: |
69+
cd examples/edge-environment
70+
npm install
71+
npm run build
72+
73+
- name: Deploy to Cloudflare Workers (dry run)
74+
uses: cloudflare/wrangler-action@v3
75+
with:
76+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
77+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
78+
command: deploy --dry-run
79+
workingDirectory: examples/edge-environment
80+
81+
- name: Test Cloudflare Worker locally
82+
run: |
83+
cd examples/edge-environment
84+
# Test that the worker can be built and type-checked
85+
npx wrangler dev --local --port 8787 &
86+
WORKER_PID=$!
87+
sleep 10
88+
89+
# Test basic functionality
90+
curl -f http://localhost:8787/health || echo "Health check failed"
91+
92+
# Kill the worker process
93+
kill $WORKER_PID
94+
95+
# Test in Cloudflare Workers with actual deployment (only on main branch)
96+
deploy-cloudflare-workers:
97+
name: Deploy and Test Cloudflare Workers
98+
runs-on: ubuntu-latest
99+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
100+
needs: [test, test-cloudflare-workers]
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v4
104+
105+
- name: Setup Node.js
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: '20'
109+
cache: 'npm'
110+
111+
- name: Install dependencies
112+
run: npm ci
113+
114+
- name: Build the SDK
115+
run: npm run build
116+
117+
- name: Setup Cloudflare Worker test environment
118+
run: |
119+
cd examples/edge-environment
120+
npm install
121+
npm run build
122+
123+
- name: Deploy to Cloudflare Workers
124+
uses: cloudflare/wrangler-action@v3
125+
with:
126+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
127+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
128+
command: deploy
129+
workingDirectory: examples/edge-environment
130+
131+
- name: Test deployed Cloudflare Worker
132+
run: |
133+
# Wait for deployment to be ready
134+
sleep 30
135+
136+
# Get the worker URL from wrangler output
137+
WORKER_URL=$(cd examples/edge-environment && npx wrangler whoami --format json | jq -r '.subdomain')
138+
echo "Testing worker at: https://${WORKER_URL}.workers.dev"
139+
140+
# Test the deployed worker
141+
curl -f "https://${WORKER_URL}.workers.dev/health" || echo "Deployed worker health check failed"
142+
143+
# Test in different Node.js environments including compact/edge-like environments
144+
test-edge-environments:
145+
name: Test Edge-like Environments
146+
runs-on: ubuntu-latest
147+
strategy:
148+
matrix:
149+
include:
150+
- name: "Node.js 20 (minimal)"
151+
node-version: "20"
152+
env: "NODE_OPTIONS=--max-old-space-size=128"
153+
- name: "Node.js 18 (minimal)"
154+
node-version: "18"
155+
env: "NODE_OPTIONS=--max-old-space-size=128"
156+
- name: "Node.js 20 (compact)"
157+
node-version: "20"
158+
env: "NODE_OPTIONS=--max-old-space-size=64 --optimize-for-size"
159+
steps:
160+
- name: Checkout code
161+
uses: actions/checkout@v4
162+
163+
- name: Setup Node.js ${{ matrix.node-version }}
164+
uses: actions/setup-node@v4
165+
with:
166+
node-version: ${{ matrix.node-version }}
167+
cache: 'npm'
168+
169+
- name: Install dependencies
170+
run: npm ci
171+
172+
- name: Build the SDK
173+
run: npm run build
174+
175+
- name: Test in edge-like environment
176+
env:
177+
NODE_OPTIONS: ${{ matrix.env }}
178+
run: |
179+
# Test basic SDK functionality in constrained environment
180+
node -e "
181+
const nylas = require('./lib/cjs/nylas.js');
182+
console.log('SDK loaded successfully in edge environment');
183+
184+
// Test that types are properly optional
185+
const config = { apiKey: 'test-key' };
186+
const client = new nylas.Nylas(config);
187+
console.log('Client created successfully');
188+
"
189+
190+
- name: Test ESM in edge-like environment
191+
env:
192+
NODE_OPTIONS: ${{ matrix.env }}
193+
run: |
194+
# Test ESM build in constrained environment
195+
node --input-type=module -e "
196+
import nylas from './lib/esm/nylas.js';
197+
console.log('ESM SDK loaded successfully in edge environment');
198+
199+
const config = { apiKey: 'test-key' };
200+
const client = new nylas(config);
201+
console.log('ESM client created successfully');
202+
"
203+
204+
# Build and test different module formats
205+
test-module-formats:
206+
name: Test Module Formats
207+
runs-on: ubuntu-latest
208+
steps:
209+
- name: Checkout code
210+
uses: actions/checkout@v4
211+
212+
- name: Setup Node.js
213+
uses: actions/setup-node@v4
214+
with:
215+
node-version: '20'
216+
cache: 'npm'
217+
218+
- name: Install dependencies
219+
run: npm ci
220+
221+
- name: Build all formats
222+
run: npm run build
223+
224+
- name: Test CommonJS
225+
run: |
226+
node -e "
227+
const nylas = require('./lib/cjs/nylas.js');
228+
console.log('CommonJS build works');
229+
const client = new nylas.Nylas({ apiKey: 'test' });
230+
console.log('CommonJS client created');
231+
"
232+
233+
- name: Test ESM
234+
run: |
235+
node --input-type=module -e "
236+
import nylas from './lib/esm/nylas.js';
237+
console.log('ESM build works');
238+
const client = new nylas({ apiKey: 'test' });
239+
console.log('ESM client created');
240+
"
241+
242+
- name: Test CJS Wrapper
243+
run: |
244+
node -e "
245+
const nylas = require('./cjs-wrapper.js');
246+
console.log('CJS wrapper works');
247+
const client = new nylas.Nylas({ apiKey: 'test' });
248+
console.log('CJS wrapper client created');
249+
"
250+
251+
# Security and dependency checks
252+
security-check:
253+
name: Security Check
254+
runs-on: ubuntu-latest
255+
steps:
256+
- name: Checkout code
257+
uses: actions/checkout@v4
258+
259+
- name: Setup Node.js
260+
uses: actions/setup-node@v4
261+
with:
262+
node-version: '20'
263+
cache: 'npm'
264+
265+
- name: Install dependencies
266+
run: npm ci
267+
268+
- name: Run security audit
269+
run: npm audit --audit-level=moderate
270+
271+
- name: Check for known vulnerabilities
272+
run: npx audit-ci --moderate

0 commit comments

Comments
 (0)