Skip to content

Commit d646ecd

Browse files
committed
chore(ci): break up postgrest slow tests
1 parent 95f789c commit d646ecd

File tree

6 files changed

+135
-7
lines changed

6 files changed

+135
-7
lines changed

.github/workflows/ci-core.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
4545
# - run: npx nx-cloud record -- echo Hello World
4646
# When you enable task distribution, run the e2e-ci task instead of e2e
47-
- name: Check generated types are in sync
47+
- name: Check common types are in sync
4848
run: npm run codegen:check
4949

5050
- name: Build affected packages
@@ -55,7 +55,11 @@ jobs:
5555

5656
- name: Run test:ci for affected packages
5757
run: npx nx affected --target=test:ci
58-
timeout-minutes: 20
58+
timeout-minutes: 15
59+
60+
- name: Run type tests for affected packages (parallel)
61+
run: npx nx affected --target=test:types:ci
62+
timeout-minutes: 15
5963

6064
- name: Upload coverage for functions-js (if affected)
6165
uses: coverallsapp/github-action@v2
@@ -109,11 +113,46 @@ jobs:
109113
flag-name: storage-js
110114
fail-on-error: false
111115
continue-on-error: true
116+
# Separate job for slow type generation check (runs in parallel)
117+
check-postgrest-generated-types:
118+
name: Check Postgrest Generated Types
119+
runs-on: ubuntu-latest
120+
steps:
121+
- uses: actions/checkout@v4
122+
with:
123+
filter: tree:0
124+
fetch-depth: 0
125+
- uses: actions/setup-node@v4
126+
with:
127+
node-version: 20
128+
cache: 'npm'
129+
- name: Install dependencies
130+
run: npm ci --legacy-peer-deps
131+
132+
- name: Check if database schema changed
133+
id: check_changes
134+
run: |
135+
git fetch origin ${{ github.base_ref }}
136+
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "packages/core/postgrest-js/test/db/"; then
137+
echo "changed=true" >> $GITHUB_OUTPUT
138+
else
139+
echo "changed=false" >> $GITHUB_OUTPUT
140+
fi
141+
142+
- name: Verify generated types are in sync
143+
if: steps.check_changes.outputs.changed == 'true'
144+
run: npm run codegen:check:postgrest
145+
timeout-minutes: 5
146+
147+
- name: Skip check
148+
if: steps.check_changes.outputs.changed != 'true'
149+
run: echo "⏭️ Skipping - no database schema changes detected"
150+
112151
# SUMMARY JOB
113152
all-core-tests-pass:
114153
name: All Core Package Tests Pass
115154
runs-on: ubuntu-latest
116-
needs: setup-build-test-node-20
155+
needs: [setup-build-test-node-20, check-postgrest-generated-types]
117156
steps:
118157
- name: Summary
119158
run: echo "✅ All core package tests passed successfully!"

.husky/pre-push

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Check if postgrest-js test database schema was modified
2+
if git diff --name-only origin/master...HEAD 2>/dev/null | grep -q "packages/core/postgrest-js/test/db/"; then
3+
echo "📝 Detected changes in postgrest-js test database schema..."
4+
echo "🔍 Checking if generated types are in sync..."
5+
6+
npm run codegen:check:postgrest
7+
8+
if [ $? -ne 0 ]; then
9+
echo ""
10+
echo "❌ Push blocked: Postgrest generated types are out of sync"
11+
echo ""
12+
echo "To fix this:"
13+
echo " 1. Run: npm run codegen:postgrest"
14+
echo " 2. Commit the updated test/types.generated.ts"
15+
echo " 3. Push again"
16+
echo ""
17+
exit 1
18+
fi
19+
20+
echo "✅ Postgrest generated types are in sync"
21+
fi

nx.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
"cache": true,
111111
"outputs": []
112112
},
113+
"test:types:ci": {
114+
"inputs": ["testing", "^production"],
115+
"dependsOn": ["build"],
116+
"cache": true,
117+
"outputs": []
118+
},
113119
"test:unit": {
114120
"inputs": ["testing", "^production"],
115121
"cache": true,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"prepare": "husky",
88
"codegen": "node scripts/sync-common-types.js",
99
"codegen:check": "node scripts/sync-common-types.js && git diff --exit-code packages/core/supabase-js/src/lib/rest/types/common && echo '\n✅ Generated types are in sync!' || (echo '\n❌ Generated types are out of sync.\n Run: npm run codegen\n Then commit the changes.\n' && exit 1)",
10+
"codegen:postgrest": "node scripts/generate-postgrest-types.js",
11+
"codegen:check:postgrest": "node scripts/generate-postgrest-types.js && git diff --exit-code packages/core/postgrest-js/test/types.generated.ts && echo '\n✅ Postgrest generated types are in sync!' || (echo '\n❌ Postgrest generated types are out of sync.\n Run: npm run codegen:postgrest\n Then commit the changes.\n' && exit 1)",
1012
"release-canary": "npx tsx scripts/release-canary.ts",
1113
"release-stable": "npx tsx scripts/release-stable.ts"
1214
},

packages/core/postgrest-js/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"build:esm": "cpy wrapper.mjs dist/esm/",
4040
"docs": "typedoc src/index.ts --out docs/v2",
4141
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
42-
"test": "npm run format:check && npm run test:types && npm run db:clean && npm run db:run && npm run test:generated-types && npm run test:run && npm run db:clean && node test/smoke.cjs && node test/smoke.mjs",
43-
"test:ci": "npm run format:check && npm run test:types:ci && npm run db:clean && npm run db:run && npm run test:generated-types && npm run test:run && npm run db:clean && node test/smoke.cjs && node test/smoke.mjs",
42+
"test": "npm run format:check && npm run test:types && npm run db:clean && npm run db:run && npm run test:run && npm run db:clean && node test/smoke.cjs && node test/smoke.mjs",
43+
"test:ci": "npm run db:clean && npm run db:run && npm run test:run && npm run db:clean && npm run test:smoke",
4444
"test:run": "jest --runInBand --coverage",
45-
"test:generated-types": "npm run db:generate-test-types && git diff --exit-code test/types.generated.ts || (echo '❌ Generated types are not up to date. Run npm run db:generate-test-types.' && exit 1)",
45+
"test:smoke": "node test/smoke.cjs && node test/smoke.mjs",
4646
"test:update": "npm run db:clean && npm run db:run && npm run db:generate-test-types && jest --runInBand --updateSnapshot && npm run db:clean",
4747
"test:types": "npm run build && tstyche",
48-
"test:types:ci": "npm run build && tstyche --target '4.7,5.5,latest'",
48+
"test:types:ci": "tstyche --target '4.7,5.5,latest'",
4949
"test:types:watch": "chokidar 'src/**/*.ts' 'test/**/*.ts' -c 'npm run test:types'",
5050
"type-check": "tsc --noEmit --project tsconfig.json",
5151
"type-check:test": "tsc --noEmit --project tsconfig.test.json",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Generate TypeScript types for postgrest-js tests from the test database
5+
*
6+
* This script spins up the Docker test infrastructure, generates types
7+
* from the database schema, and writes them to test/types.generated.ts
8+
*/
9+
10+
const { execSync } = require('child_process')
11+
const path = require('path')
12+
13+
const POSTGREST_DIR = path.join(__dirname, '../packages/core/postgrest-js')
14+
const DB_DIR = path.join(POSTGREST_DIR, 'test/db')
15+
const OUTPUT_FILE = path.join(POSTGREST_DIR, 'test/types.generated.ts')
16+
17+
function exec(command, options = {}) {
18+
try {
19+
return execSync(command, {
20+
stdio: 'inherit',
21+
...options,
22+
})
23+
} catch (error) {
24+
console.error(`❌ Command failed: ${command}`)
25+
process.exit(1)
26+
}
27+
}
28+
29+
function main() {
30+
console.log('🔄 Generating postgrest-js test types...\n')
31+
32+
// Start Docker containers
33+
console.log('📦 Starting Docker containers...')
34+
exec('docker compose up --detach', { cwd: DB_DIR })
35+
36+
// Wait for services to be ready
37+
console.log('⏳ Waiting for services to be ready...')
38+
exec('npx wait-for-localhost 8080')
39+
exec('npx wait-for-localhost 3000')
40+
41+
// Generate types from database
42+
console.log('🔧 Generating types from database...')
43+
exec(
44+
`curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ${OUTPUT_FILE}`,
45+
{ cwd: POSTGREST_DIR, stdio: 'inherit' }
46+
)
47+
48+
// Run post-generation script to update JSON type
49+
console.log('🔧 Post-processing generated types...')
50+
exec('node scripts/update-json-type.js', { cwd: POSTGREST_DIR })
51+
52+
// Clean up Docker containers
53+
console.log('🧹 Cleaning up Docker containers...')
54+
exec('docker compose down --volumes', { cwd: DB_DIR })
55+
56+
console.log('\n✅ Type generation complete!')
57+
console.log(` Output: ${OUTPUT_FILE}`)
58+
}
59+
60+
main()

0 commit comments

Comments
 (0)