Repository navigation
479 lines (434 loc) · 21 KB
/
Copy pathprebuild.yml
File metadata and controls
479 lines (434 loc) · 21 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
name: Prebuild
on:
pull_request:
types: [opened, synchronize, reopened]
branches: [main, 0.x]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions: {}
jobs:
changes:
name: Detect code changes
runs-on: starsling-ubuntu-24.04-2
permissions:
contents: read
outputs:
has_code: ${{ steps.filter.outputs.has_code }}
steps:
- name: Check for code changes
id: filter
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
compare_json=$(mktemp)
if ! gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"repos/$REPOSITORY/compare/$BASE_SHA...$HEAD_SHA" \
> "$compare_json"; then
echo "Compare API failed; running Prebuild fail-closed."
echo "has_code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! file_count=$(jq -er \
'if (.files | type) == "array" then (.files | length) else error("missing files array") end' \
"$compare_json"); then
echo "Compare API result was invalid; running Prebuild fail-closed."
echo "has_code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "$file_count" -ge 300 ]; then
echo "Compare API result reached its 300-file response limit; running Prebuild fail-closed."
echo "has_code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
CHANGED=$(jq -r '.files[].filename' "$compare_json" \
| grep -vE '^(docs/|examples/|\.changeset/|explorations/)' || true)
if [ -n "$CHANGED" ]; then
echo "has_code=true" >> "$GITHUB_OUTPUT"
else
echo "has_code=false" >> "$GITHUB_OUTPUT"
fi
prebuild:
name: Build
needs: changes
runs-on: starsling-ubuntu-24.04
timeout-minutes: 20
if: needs.changes.outputs.has_code == 'true' && github.repository == 'mastra-ai/mastra'
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_CACHE: ${{ secrets.TURBO_TOKEN == '' && 'local:rw' || 'remote:rw' }}
NODE_OPTIONS: --max-old-space-size=8192
permissions:
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@e8d4307400f9427dba7cb98e488d6ab85f1cec5f
timeout-minutes: 20
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2
- name: Setup pnpm and Node.js
uses: ./.github/actions/setup-pnpm-node
- name: Cache turbo build setup
if: ${{ env.TURBO_TOKEN == '' }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: .turbo/cache
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-
- name: Build
run: pnpm turbo --filter "!./examples/**/*" --filter "!./docs/" --filter "!./explorations/**/*" build
affected-tests:
name: Detect affected tests
needs: changes
if: github.repository == 'mastra-ai/mastra' && needs.changes.outputs.has_code == 'true'
runs-on: starsling-ubuntu-24.04
timeout-minutes: 10
outputs:
run_full: ${{ steps.compute.outputs.run_full }}
test_files: ${{ steps.compute.outputs.test_files }}
unit_test_files: ${{ steps.compute.outputs.unit_test_files }}
e2e_test_files: ${{ steps.compute.outputs.e2e_test_files }}
e2e_changed: ${{ steps.compute.outputs.e2e_changed }}
experiment_worker_e2e_changed: ${{ steps.compute.outputs.experiment_worker_e2e_changed }}
mastracode_e2e_changed: ${{ steps.compute.outputs.mastracode_e2e_changed }}
stores_changed: ${{ steps.compute.outputs.stores_changed }}
workspaces_changed: ${{ steps.compute.outputs.workspaces_changed }}
memory_changed: ${{ steps.compute.outputs.memory_changed }}
affected_store_tests: ${{ steps.compute.outputs.affected_store_tests }}
affected_workspace_tests: ${{ steps.compute.outputs.affected_workspace_tests }}
workspace_packages: ${{ steps.compute.outputs.workspace_packages }}
workspace_docker_packages: ${{ steps.compute.outputs.workspace_docker_packages }}
affected_memory_tests: ${{ steps.compute.outputs.affected_memory_tests }}
permissions:
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@e8d4307400f9427dba7cb98e488d6ab85f1cec5f
timeout-minutes: 20
with:
fetch-depth: 0
# Partial clone: name-only diffs need trees, not blob contents.
filter: blob:none
- name: Setup pnpm and Node.js
uses: ./.github/actions/setup-pnpm-node
with:
install-dependencies: false
- name: Install affected-test dependencies
run: pnpm install --frozen-lockfile --ignore-scripts --filter mastra-turbo
- name: Compute affected test files
id: compute
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
git diff --name-only \
"$BASE_SHA...$HEAD_SHA" \
> /tmp/changed-files.txt
CHANGED=$(grep -E '/src/.*\.(ts|tsx)$' /tmp/changed-files.txt \
| grep -vE '__fixtures__|/fixtures/' \
|| true)
if [ -z "$CHANGED" ]; then
echo "No source file changes found — skipping unit and E2E test selection."
printf '{"affectedTests":[],"count":0,"testFiles":1}\n' > /tmp/affected.json
else
echo "Changed source files:"
echo "$CHANGED"
# Run affected-tests tool
echo "$CHANGED" | xargs node scripts/affected-tests.mjs --json > /tmp/affected.json
fi
# Parse results, split unit/E2E files, and compute downstream gates.
node <<'NODE'
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('/tmp/affected.json', 'utf-8'));
const changedFiles = fs.readFileSync('/tmp/changed-files.txt', 'utf-8').split(/\r?\n/).filter(Boolean);
const nonMarkdownChangedFiles = changedFiles.filter(file => !file.endsWith('.md'));
const affectedTests = (data.affectedTests || []).sort();
const count = data.count || 0;
const total = data.testFiles || 1;
const ratio = count / total;
const hasChangedSource = changedFiles.some(file => /\/src\/.*\.(ts|tsx)$/.test(file) && !/__fixtures__|\/fixtures\//.test(file));
const runFull = hasChangedSource && ratio > 0.5;
const output = (line) => fs.appendFileSync(process.env.GITHUB_OUTPUT, line);
const outputList = (name, files) => {
output(`${name}<<AFFECTED_EOF\n`);
output(`${files.join('\n')}${files.length > 0 ? '\n' : ''}`);
output('AFFECTED_EOF\n');
};
const changed = (predicate) => nonMarkdownChangedFiles.some(predicate);
const affected = (predicate) => affectedTests.some(predicate);
const isPackageE2eTest = (file) => file.startsWith('packages/') && (
file.includes('.e2e.') ||
file.startsWith('packages/evals/src/scorers/llm/') ||
file.startsWith('packages/rag/src/')
);
const isExternalE2eTest = (file) =>
file.startsWith('e2e-tests/') || file.startsWith('packages/playground/e2e/');
const unitTestFiles = affectedTests.filter(file => !isPackageE2eTest(file) && !isExternalE2eTest(file));
const e2eTestFiles = affectedTests.filter(isPackageE2eTest);
const affectedStoreTests = affected(file => file.startsWith('stores/'));
const affectedWorkspaceTests = affected(file => file.startsWith('workspaces/'));
const affectedMemoryTests = affected(file => file.startsWith('packages/memory/integration-tests/'));
const {
discoverWorkspacePackages,
selectWorkspacePackages,
} = require('./.github/scripts/ci-routing.cjs');
const workspaceSelection = selectWorkspacePackages({
affectedTests,
changedFiles,
runFull,
workspacePackages: discoverWorkspacePackages(),
});
const storesChanged = affectedStoreTests || changed(file =>
file.startsWith('stores/') ||
file === '.github/workflows/test-combined-stores.yml' ||
file === '.github/workflows/prebuild.yml'
);
const workspacesChanged = workspaceSelection.packages.length > 0;
const memoryChanged = affectedMemoryTests || changed(file =>
file.startsWith('packages/memory/') || file === '.github/workflows/prebuild.yml'
);
const { studioE2eChanged } = require('./.github/scripts/studio-e2e-routing.cjs');
const e2eChanged = studioE2eChanged(nonMarkdownChangedFiles) || affected(isExternalE2eTest) || (runFull && hasChangedSource) || changed(file =>
(file.startsWith('e2e-tests/') &&
!file.startsWith('e2e-tests/experiment-worker/') &&
!file.startsWith('e2e-tests/_local-registry-setup/')) ||
file.startsWith('packages/playground/e2e/') ||
file.startsWith('packages/playground-ui/') ||
file.startsWith('server-adapters/hono/') ||
file.startsWith('packages/server/') ||
// e2e-mcp-compat: the core MCP/tool contract must keep published @mastra/mcp 1.x working.
file.startsWith('packages/core/src/mcp/') ||
file.startsWith('packages/core/src/tools/') ||
file.startsWith('packages/mcp/integration-tests/') ||
file === '.github/workflows/e2e-tests.yml' ||
file === 'pnpm-lock.yaml'
);
const mastracodeE2eChanged = changed(file =>
file.startsWith('mastracode/') ||
file.startsWith('packages/core/') ||
file === 'pnpm-lock.yaml' ||
file === '.github/workflows/mastracode-e2e.yml'
);
output(`affected_store_tests=${affectedStoreTests}\n`);
const workspaceDockerPackages = workspaceSelection.packages.filter(packageName =>
['s3', 'gcs', 'azure'].includes(packageName),
);
output(`affected_workspace_tests=${affectedWorkspaceTests}\n`);
output(`workspace_packages=${JSON.stringify(workspaceSelection.packages)}\n`);
output(`workspace_docker_packages=${JSON.stringify(workspaceDockerPackages)}\n`);
output(`affected_memory_tests=${affectedMemoryTests}\n`);
output(`stores_changed=${storesChanged}\n`);
output(`workspaces_changed=${workspacesChanged}\n`);
const { experimentWorkerE2eChanged } = require('./.github/scripts/experiment-worker-routing.cjs');
const experimentEntryFiles = ['packages/cli/src/commands/index.ts', 'packages/cli/src/index.ts'];
const changedEntryFiles = changedFiles.filter(file => experimentEntryFiles.includes(file));
const experimentEntryDiff = changedEntryFiles.length
? require('child_process').execFileSync(
'git',
['diff', '--unified=0', `${process.env.BASE_SHA}...${process.env.HEAD_SHA}`, '--', ...changedEntryFiles],
{ encoding: 'utf8' },
)
: '';
const experimentWorkerChanged = experimentWorkerE2eChanged(nonMarkdownChangedFiles, experimentEntryDiff);
output(`memory_changed=${memoryChanged}\n`);
output(`e2e_changed=${e2eChanged}\n`);
output(`experiment_worker_e2e_changed=${experimentWorkerChanged}\n`);
output(`mastracode_e2e_changed=${mastracodeE2eChanged}\n`);
console.error(`Affected: ${count}/${total} tests (${(ratio * 100).toFixed(1)}%)`);
console.error(`Affected unit/type tests: ${unitTestFiles.length}`);
console.error(`Affected package E2E tests: ${e2eTestFiles.length}`);
console.error(`Workspace packages (${workspaceSelection.reason}): ${workspaceSelection.packages.join(', ') || 'none'}`);
fs.appendFileSync(
process.env.GITHUB_STEP_SUMMARY,
`## Workspace test routing\n\n- Reason: \`${workspaceSelection.reason}\`\n- Packages: ${workspaceSelection.packages.length ? workspaceSelection.packages.map(pkg => `\`${pkg}\``).join(', ') : 'none'}\n`,
);
if (runFull) {
console.error('Above 50% threshold — running full suite.');
output('run_full=true\n');
output('test_files=\n');
output('unit_test_files=\n');
output('e2e_test_files=\n');
} else {
console.error(`Running ${count} affected tests.`);
output('run_full=false\n');
outputList('test_files', affectedTests);
outputList('unit_test_files', unitTestFiles);
outputList('e2e_test_files', e2eTestFiles);
}
NODE
- name: Save affected-tests outputs for downstream workflow
if: always()
env:
E2E_CHANGED: ${{ steps.compute.outputs.e2e_changed }}
EXPERIMENT_WORKER_E2E_CHANGED: ${{ steps.compute.outputs.experiment_worker_e2e_changed }}
MASTRACODE_E2E_CHANGED: ${{ steps.compute.outputs.mastracode_e2e_changed }}
STORES_CHANGED: ${{ steps.compute.outputs.stores_changed }}
WORKSPACES_CHANGED: ${{ steps.compute.outputs.workspaces_changed }}
MEMORY_CHANGED: ${{ steps.compute.outputs.memory_changed }}
AFFECTED_STORE_TESTS: ${{ steps.compute.outputs.affected_store_tests }}
AFFECTED_WORKSPACE_TESTS: ${{ steps.compute.outputs.affected_workspace_tests }}
WORKSPACE_PACKAGES: ${{ steps.compute.outputs.workspace_packages }}
AFFECTED_MEMORY_TESTS: ${{ steps.compute.outputs.affected_memory_tests }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
mkdir -p /tmp/affected-outputs
echo "$E2E_CHANGED" > /tmp/affected-outputs/e2e_changed.txt
echo "$EXPERIMENT_WORKER_E2E_CHANGED" > /tmp/affected-outputs/experiment_worker_e2e_changed.txt
echo "$MASTRACODE_E2E_CHANGED" > /tmp/affected-outputs/mastracode_e2e_changed.txt
echo "$STORES_CHANGED" > /tmp/affected-outputs/stores_changed.txt
echo "$WORKSPACES_CHANGED" > /tmp/affected-outputs/workspaces_changed.txt
echo "$MEMORY_CHANGED" > /tmp/affected-outputs/memory_changed.txt
echo "$AFFECTED_STORE_TESTS" > /tmp/affected-outputs/affected_store_tests.txt
echo "$AFFECTED_WORKSPACE_TESTS" > /tmp/affected-outputs/affected_workspace_tests.txt
echo "$WORKSPACE_PACKAGES" > /tmp/affected-outputs/workspace_packages.json
echo "$AFFECTED_MEMORY_TESTS" > /tmp/affected-outputs/affected_memory_tests.txt
echo "$BASE_SHA" > /tmp/affected-outputs/base_sha.txt
echo "$HEAD_SHA" > /tmp/affected-outputs/head_sha.txt
- name: Upload affected-tests artifact
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: affected-tests-outputs
path: /tmp/affected-outputs/
retention-days: 1
test-suite:
name: Unit and E2E Tests
needs: [changes, prebuild, affected-tests]
if: always() && github.repository == 'mastra-ai/mastra' && needs.changes.result == 'success' && (needs.changes.outputs.has_code != 'true' || needs.prebuild.result == 'success')
uses: ./.github/workflows/test-suite.yml
permissions:
actions: read
contents: read
with:
head_sha: ${{ github.event.pull_request.head.sha }}
base_ref: ${{ github.event.pull_request.base.ref }}
has_code: ${{ needs.changes.outputs.has_code }}
unit_test_files: ${{ needs.affected-tests.outputs.unit_test_files }}
e2e_test_files: ${{ needs.affected-tests.outputs.e2e_test_files }}
run_full: ${{ needs.affected-tests.outputs.run_full }}
secrets:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
e2e-tests:
name: E2E Tests
needs: [changes, affected-tests, prebuild]
if: always() && github.repository == 'mastra-ai/mastra' && (needs.affected-tests.outputs.e2e_changed == 'true' || needs.affected-tests.outputs.experiment_worker_e2e_changed == 'true') && needs.prebuild.result == 'success'
uses: ./.github/workflows/e2e-tests.yml
permissions:
contents: read
with:
head_sha: ${{ github.event.pull_request.head.sha }}
experiment_worker_e2e_changed: ${{ needs.affected-tests.outputs.experiment_worker_e2e_changed == 'true' }}
secrets:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
mastracode-e2e:
name: Mastra Code E2E
needs: [changes, affected-tests, prebuild]
if: always() && github.repository == 'mastra-ai/mastra' && needs.affected-tests.outputs.mastracode_e2e_changed == 'true' && needs.prebuild.result == 'success'
uses: ./.github/workflows/mastracode-e2e.yml
permissions:
contents: read
with:
head_sha: ${{ github.event.pull_request.head.sha }}
secrets:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
combined-stores-tests:
name: Combined Store Tests
needs: [changes, affected-tests, prebuild]
if: always() && github.repository == 'mastra-ai/mastra' && needs.affected-tests.outputs.stores_changed == 'true' && needs.prebuild.result == 'success'
uses: ./.github/workflows/test-combined-stores.yml
permissions:
contents: read
with:
head_sha: ${{ github.event.pull_request.head.sha }}
secrets:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
ASTRA_DB_ENDPOINT: ${{ secrets.ASTRA_DB_ENDPOINT }}
ASTRA_DB_TOKEN: ${{ secrets.ASTRA_DB_TOKEN }}
ABHI_CLOUDFLARE_API_TOKEN: ${{ secrets.ABHI_CLOUDFLARE_API_TOKEN }}
ABHI_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.ABHI_CLOUDFLARE_ACCOUNT_ID }}
workspace-tests:
name: Workspace Tests
needs: [changes, affected-tests, prebuild]
if: always() && github.repository == 'mastra-ai/mastra' && needs.affected-tests.outputs.workspaces_changed == 'true' && needs.prebuild.result == 'success'
uses: ./.github/workflows/test-workspaces.yml
permissions:
contents: read
with:
head_sha: ${{ github.event.pull_request.head.sha }}
workspace_packages: ${{ needs.affected-tests.outputs.workspace_packages }}
workspace_docker_packages: ${{ needs.affected-tests.outputs.workspace_docker_packages }}
secrets:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
memory-test:
name: Memory Tests
needs: [affected-tests, prebuild]
if: always() && github.repository == 'mastra-ai/mastra' && needs.affected-tests.outputs.memory_changed == 'true' && needs.prebuild.result == 'success'
runs-on: starsling-ubuntu-24.04
permissions:
contents: read
timeout-minutes: 15
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mastra
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:8
ports:
- 6379:6379
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_CACHE: remote:r
steps:
- uses: actions/checkout@e8d4307400f9427dba7cb98e488d6ab85f1cec5f
timeout-minutes: 20
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup pnpm and Node.js
uses: ./.github/actions/setup-pnpm-node
- name: Cache turbo build setup
if: ${{ env.TURBO_TOKEN == '' }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: .turbo/cache
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-
- name: Build dependencies
run: pnpm turbo build --filter "./stores/libsql" --filter "./stores/pg" --filter "./stores/upstash" --filter "mastra" --filter "@mastra/memory" --filter "@mastra/fastembed" --filter "@internal/llm-recorder" --filter "@internal/test-utils"
env:
NODE_OPTIONS: '--max_old_space_size=8192'
- name: Install integration test dependencies
run: pnpm install
working-directory: packages/memory/integration-tests
- name: Run Memory tests
run: pnpm vitest run
working-directory: packages/memory/integration-tests
env:
NODE_OPTIONS: '--max_old_space_size=8192'
DB_URL: 'postgresql://postgres:postgres@localhost:5432/mastra'