Skip to content

Commit 1041b15

Browse files
authored
ci: automatically shard int tests (#15367)
See #15366, but for int tests
1 parent ab603c3 commit 1041b15

File tree

3 files changed

+96
-16
lines changed

3 files changed

+96
-16
lines changed

.github/workflows/int.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createIntConfig } from './utilities/int-matrix.ts'
2+
3+
createIntConfig({
4+
databases: [
5+
'mongodb',
6+
'mongodb-atlas',
7+
'documentdb',
8+
'cosmosdb',
9+
'firestore',
10+
'postgres',
11+
'postgres-custom-schema',
12+
'postgres-uuid',
13+
'supabase',
14+
'sqlite',
15+
'sqlite-uuid',
16+
],
17+
shards: 3,
18+
})

.github/workflows/main.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,39 @@ jobs:
141141
env:
142142
NODE_OPTIONS: --max-old-space-size=8096
143143

144-
tests-int:
144+
# Generate the integration test matrix from TypeScript config
145+
int-matrix:
146+
name: Setup Int Matrix
145147
runs-on: ubuntu-24.04
146148
needs: [changes, build]
147149
if: needs.changes.outputs.needs_tests == 'true'
148-
name: int-${{ matrix.database }}
150+
outputs:
151+
matrix: ${{ steps.generate.outputs.matrix }}
152+
steps:
153+
- uses: actions/checkout@v4
154+
with:
155+
sparse-checkout: |
156+
.github/workflows
157+
.tool-versions
158+
159+
- uses: actions/setup-node@v4
160+
with:
161+
node-version-file: .tool-versions
162+
163+
- name: Generate matrix
164+
id: generate
165+
run: |
166+
matrix=$(node .github/workflows/int.config.ts)
167+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
168+
169+
tests-int:
170+
runs-on: ubuntu-24.04
171+
needs: int-matrix
172+
name: int-${{ matrix.database }}${{ matrix.total-shards > 1 && format(' ({0}/{1})', matrix.shard, matrix.total-shards) || '' }}
149173
timeout-minutes: 45
150174
strategy:
151175
fail-fast: false
152-
matrix:
153-
database:
154-
- mongodb
155-
- mongodb-atlas
156-
- documentdb
157-
- cosmosdb
158-
- firestore
159-
- postgres
160-
- postgres-custom-schema
161-
- postgres-uuid
162-
- supabase
163-
- sqlite
164-
- sqlite-uuid
176+
matrix: ${{ fromJson(needs.int-matrix.outputs.matrix) }}
165177

166178
env:
167179
AWS_ENDPOINT_URL: http://127.0.0.1:4566
@@ -206,7 +218,7 @@ jobs:
206218
database: ${{ matrix.database }}
207219

208220
- name: Integration Tests
209-
run: pnpm test:int
221+
run: pnpm test:int --shard=${{ matrix.shard }}/${{ matrix.total-shards }}
210222
env:
211223
NODE_OPTIONS: --max-old-space-size=8096
212224
PAYLOAD_DATABASE: ${{ matrix.database }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Integration Test Matrix Generation Utilities
3+
*
4+
* This module provides types and functions for generating the GitHub Actions
5+
* matrix configuration for integration tests.
6+
*/
7+
8+
export interface IntTestConfig {
9+
/** List of database adapters to test against */
10+
databases: string[]
11+
/** Number of shards to split each database test into */
12+
shards: number
13+
}
14+
15+
interface MatrixEntry {
16+
database: string
17+
shard: number
18+
'total-shards': number
19+
}
20+
21+
interface Matrix {
22+
include: MatrixEntry[]
23+
}
24+
25+
function generateMatrix(config: IntTestConfig): Matrix {
26+
const include: MatrixEntry[] = []
27+
28+
for (const database of config.databases) {
29+
for (let shard = 1; shard <= config.shards; shard++) {
30+
include.push({
31+
database,
32+
shard,
33+
'total-shards': config.shards,
34+
})
35+
}
36+
}
37+
38+
return { include }
39+
}
40+
41+
/**
42+
* Creates and outputs the integration test matrix configuration for GitHub Actions.
43+
* Prints the matrix JSON to stdout for consumption by the CI workflow.
44+
*
45+
* @param config - Database list and shard count
46+
*/
47+
export function createIntConfig(config: IntTestConfig): void {
48+
const matrix = generateMatrix(config)
49+
console.log(JSON.stringify(matrix))
50+
}

0 commit comments

Comments
 (0)