Skip to content

Commit 3048ddb

Browse files
jumskiclaude
andcommitted
Optimize CI: separate fast tests from live infrastructure tests
Split test targets into two categories: - test: Fast tests without infrastructure (vitest, types) - test:live: Tests requiring live infrastructure (pgtap, integration) Enable Nx Cloud caching for verification tasks: - Remove local: true from verify-* targets - Add db:verify meta-target for verification pipeline - Verification results now cached across CI jobs Restructure CI workflow: - Job 1: db-verification (runs once, caches to Nx Cloud) - Job 2: fast-tests (restores cache, runs all packages in parallel) - Job 3-5: *-live-tests (separate jobs per package infrastructure) - Job 6: edge-worker-e2e (unchanged) Benefits: - verify-migrations runs once instead of multiple times - Fast tests complete in ~2-3 min with full parallelization - Simple commands: nx affected -t test (fast), nx affected -t test:live (infra) - Nx handles dependency resolution and caching automatically 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bde6bed commit 3048ddb

File tree

14 files changed

+414
-189
lines changed

14 files changed

+414
-189
lines changed

.github/actions/setup/action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: 'Setup pgflow workspace'
22
description: 'Common setup steps for pgflow CI workflow (run after checkout)'
33

4+
inputs:
5+
atlas-cloud-token:
6+
description: 'Atlas Cloud token for schema verification'
7+
required: false
8+
49
runs:
510
using: 'composite'
611
steps:
@@ -29,6 +34,20 @@ runs:
2934
cache-dependency-path: |
3035
**/pnpm-lock.yaml
3136
37+
- name: Setup Deno
38+
uses: denoland/setup-deno@v2
39+
with:
40+
deno-version: '1.45.2'
41+
42+
- name: Install sqruff
43+
uses: quarylabs/install-sqruff-cli-action@main
44+
45+
- name: Setup Atlas
46+
if: inputs.atlas-cloud-token != ''
47+
uses: ariga/setup-atlas@master
48+
with:
49+
cloud-token: ${{ inputs.atlas-cloud-token }}
50+
3251
- name: Install dependencies
3352
shell: bash
3453
run: pnpm install --frozen-lockfile --prefer-offline

.github/workflows/ci.yml

Lines changed: 177 additions & 110 deletions
Large diffs are not rendered by default.

nx.json

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,23 @@
8181
"preview": {
8282
"dependsOn": ["^build"]
8383
},
84-
"supabase:*": {
84+
"supabase:start": {
85+
"local": true,
86+
"cache": false
87+
},
88+
"supabase:stop": {
89+
"local": true,
90+
"cache": false
91+
},
92+
"supabase:status": {
93+
"local": true,
94+
"cache": false
95+
},
96+
"supabase:reset": {
97+
"local": true,
98+
"cache": false
99+
},
100+
"supabase:restart": {
85101
"local": true,
86102
"cache": false
87103
},
@@ -95,9 +111,14 @@
95111
"local": true
96112
},
97113
"verify-*": {
98-
"local": true,
99114
"cache": true
100115
},
116+
"db:verify": {
117+
"cache": true
118+
},
119+
"test:live": {
120+
"local": true
121+
},
101122
"dump-realtime-schema": {
102123
"local": true,
103124
"cache": true

pkgs/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"module": "./dist/index.js",
1717
"devDependencies": {
1818
"@types/node": "^22.14.1",
19+
"supabase": "^2.34.3",
1920
"tsx": "^4.19.3"
2021
},
2122
"dependencies": {

pkgs/cli/project.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,23 @@
3535
}
3636
},
3737
"test": {
38+
"executor": "nx:noop",
39+
"inputs": ["default", "^production"],
40+
"dependsOn": ["test:vitest"]
41+
},
42+
"test:live": {
3843
"executor": "nx:noop",
3944
"inputs": ["default", "^production"],
4045
"dependsOn": [
41-
"test:vitest",
4246
"test:e2e:install",
4347
"test:e2e:compile",
4448
"test:e2e:async-hang-issue-123"
4549
],
4650
"options": {
4751
"parallel": false
52+
},
53+
"metadata": {
54+
"description": "Tests requiring external tools (Supabase CLI)"
4855
}
4956
},
5057
"test:vitest": {
@@ -75,14 +82,8 @@
7582
"dependsOn": ["test:e2e:install", "build"],
7683
"inputs": ["default", "^production"],
7784
"options": {
78-
"commands": [
79-
"rm -rf supabase/",
80-
"npx -y supabase@latest init --force --with-vscode-settings --with-intellij-settings",
81-
"node dist/index.js compile examples/analyze_website.ts --deno-json examples/deno.json --supabase-path supabase",
82-
"./scripts/assert-flow-compiled"
83-
],
84-
"cwd": "{projectRoot}",
85-
"parallel": false
85+
"command": "./scripts/test-compile",
86+
"cwd": "{projectRoot}"
8687
}
8788
},
8889
"test:e2e:async-hang-issue-123": {

pkgs/cli/scripts/test-async-hang-issue-123

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

44
# Script to test if pgflow CLI compile hangs on flows with async functions
55
# This reproduces issue #123: https://github.com/pgflow-dev/pgflow/issues/123
@@ -12,25 +12,27 @@ set -e
1212
cd "$(dirname "$0")/.."
1313
ROOT_DIR=$(pwd)
1414

15+
# Create unique temp directory for this test
16+
TEST_DIR=$(mktemp -d)
17+
trap "rm -rf $TEST_DIR" EXIT
18+
1519
echo "🧪 Testing async function compilation"
1620
echo " Issue #123: https://github.com/pgflow-dev/pgflow/issues/123"
21+
echo "📁 Test directory: $TEST_DIR"
1722
echo ""
1823

19-
# Clean up any existing output
20-
echo "🧹 Cleaning up old test directory"
21-
rm -rf supabase/
22-
23-
# Initialize a fresh Supabase project
24+
# Initialize a fresh Supabase project in temp dir
25+
cd "$TEST_DIR"
2426
echo "🏗️ Creating new Supabase project"
25-
npx -y supabase@latest init --force --with-vscode-settings --with-intellij-settings
27+
pnpm --dir="$ROOT_DIR" supabase init --workdir "$TEST_DIR" --with-vscode-settings --with-intellij-settings
2628

2729
# Install pgflow with our CLI
2830
echo "📦 Installing pgflow with CLI"
29-
node dist/index.js install --supabase-path supabase/ --yes
31+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
3032

3133
# Try to compile the flow with async functions
3234
echo "🔧 Compiling flow with async functions"
33-
timeout 30s node dist/index.js compile examples/async-function-hang.ts --deno-json examples/deno.json --supabase-path supabase || {
35+
timeout 30s node "$ROOT_DIR/dist/index.js" compile "$ROOT_DIR/examples/async-function-hang.ts" --deno-json "$ROOT_DIR/examples/deno.json" --supabase-path supabase || {
3436
EXIT_CODE=$?
3537
if [ $EXIT_CODE -eq 124 ]; then
3638
echo "❌ FAILURE: Compilation hung and was killed by timeout (30s)"

pkgs/cli/scripts/test-compile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Script to test pgflow CLI compile functionality
5+
# This simulates the test:e2e:compile target from project.json
6+
7+
cd "$(dirname "$0")/.."
8+
ROOT_DIR=$(pwd)
9+
10+
# Create unique temp directory for this test
11+
TEST_DIR=$(mktemp -d)
12+
trap "rm -rf $TEST_DIR" EXIT
13+
14+
echo "🧪 Testing pgflow compile functionality"
15+
echo "📁 Test directory: $TEST_DIR"
16+
17+
# Initialize a fresh Supabase project in temp dir
18+
cd "$TEST_DIR"
19+
echo "🏗️ Creating new Supabase project"
20+
pnpm --dir="$ROOT_DIR" supabase init --with-vscode-settings --with-intellij-settings
21+
22+
# Compile the flow
23+
echo "🔧 Compiling analyze_website flow"
24+
node "$ROOT_DIR/dist/index.js" compile "$ROOT_DIR/examples/analyze_website.ts" --deno-json "$ROOT_DIR/examples/deno.json" --supabase-path supabase
25+
26+
# Verify compilation succeeded
27+
echo "✅ Verifying flow compilation"
28+
"$ROOT_DIR/scripts/assert-flow-compiled"
29+
30+
# Show success message
31+
echo "✨ Compile test complete"

pkgs/cli/scripts/test-install

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

44
# Script to test pgflow CLI install functionality
55
# This simulates the test:e2e:install target from project.json
66

77
cd "$(dirname "$0")/.."
88
ROOT_DIR=$(pwd)
99

10-
echo "🧪 Testing pgflow install functionality"
10+
# Create unique temp directory for this test
11+
TEST_DIR=$(mktemp -d)
12+
trap "rm -rf $TEST_DIR" EXIT
1113

12-
# Clean up any existing supabase directory
13-
echo "🧹 Cleaning up old test directory"
14-
rm -rf supabase/
14+
echo "🧪 Testing pgflow install functionality"
15+
echo "📁 Test directory: $TEST_DIR"
1516

16-
# Initialize a fresh Supabase project
17+
# Initialize a fresh Supabase project in temp dir
18+
cd "$TEST_DIR"
1719
echo "🏗️ Creating new Supabase project"
18-
npx -y supabase@latest init --force --with-vscode-settings --with-intellij-settings
20+
pnpm --dir="$ROOT_DIR" supabase init --workdir "$TEST_DIR" --with-vscode-settings --with-intellij-settings
1921

2022
# Install pgflow with our CLI
2123
echo "📦 Installing pgflow with CLI"
22-
node dist/index.js install --supabase-path supabase/ --yes
24+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
2325

2426
# Verify installation succeeded
2527
echo "✅ Verifying pgflow installation"
@@ -31,5 +33,5 @@ echo "✨ Installation test complete"
3133
# Optional: Test for duplicates by running install again
3234
if [ "$1" == "--test-duplicates" ]; then
3335
echo "🔄 Testing duplicate installation prevention"
34-
node dist/index.js install --supabase-path supabase/ --yes
36+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
3537
fi

pkgs/cli/scripts/test-install-duplicates

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

44
# Script to test pgflow CLI install duplicate prevention
55
# This verifies that we don't create duplicate migrations
66

77
cd "$(dirname "$0")/.."
88
ROOT_DIR=$(pwd)
99

10-
echo "🧪 Testing pgflow migration duplicate prevention"
10+
# Create unique temp directory for this test
11+
TEST_DIR=$(mktemp -d)
12+
trap "rm -rf $TEST_DIR" EXIT
1113

12-
# Clean up any existing supabase directory
13-
echo "🧹 Cleaning up old test directory"
14-
rm -rf supabase/
14+
echo "🧪 Testing pgflow migration duplicate prevention"
15+
echo "📁 Test directory: $TEST_DIR"
1516

16-
# Initialize a fresh Supabase project
17+
# Initialize a fresh Supabase project in temp dir
18+
cd "$TEST_DIR"
1719
echo "🏗️ Creating new Supabase project"
18-
npx -y supabase@latest init --force --with-vscode-settings --with-intellij-settings
20+
pnpm --dir="$ROOT_DIR" supabase init --with-vscode-settings --with-intellij-settings
1921

2022
# First installation with pgflow CLI
2123
echo "📦 First pgflow installation"
22-
node dist/index.js install --supabase-path supabase/ --yes
24+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
2325

2426
# Count number of migrations after first install
2527
FIRST_COUNT=$(find supabase/migrations -name "*.sql" | wc -l)
2628
echo "🔢 Found $FIRST_COUNT migrations after first install"
2729

2830
# Second installation with pgflow CLI
2931
echo "🔄 Running second pgflow installation"
30-
node dist/index.js install --supabase-path supabase/ --yes
32+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
3133

3234
# Count number of migrations after second install
3335
SECOND_COUNT=$(find supabase/migrations -name "*.sql" | wc -l)
@@ -51,7 +53,7 @@ if [ "$1" == "--test-third-install" ]; then
5153
mv "$RANDOM_MIGRATION" "$NEW_NAME"
5254

5355
echo "🔄 Running third pgflow installation"
54-
node dist/index.js install --supabase-path supabase/ --yes
56+
node "$ROOT_DIR/dist/index.js" install --supabase-path supabase/ --yes
5557

5658
# Count number of migrations after third install
5759
THIRD_COUNT=$(find supabase/migrations -name "*.sql" | wc -l)

pkgs/client/project.json

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,6 @@
5858
"executor": "@nx/eslint:lint",
5959
"inputs": ["default", "^production"]
6060
},
61-
"supabase:ensure-started": {
62-
"executor": "nx:run-commands",
63-
"local": true,
64-
"cache": false,
65-
"options": {
66-
"cwd": "{projectRoot}",
67-
"commands": [
68-
"../../scripts/supabase-start-locked.sh ."
69-
],
70-
"parallel": false
71-
}
72-
},
7361
"supabase:start": {
7462
"executor": "nx:run-commands",
7563
"local": true,
@@ -137,6 +125,31 @@
137125
"parallel": false
138126
}
139127
},
128+
"db:ensure": {
129+
"executor": "nx:run-commands",
130+
"local": true,
131+
"dependsOn": ["supabase:prepare"],
132+
"options": {
133+
"cwd": "{projectRoot}",
134+
"commands": [
135+
"../../scripts/supabase-start-locked.sh .",
136+
"./scripts/ensure-db"
137+
],
138+
"parallel": false
139+
},
140+
"inputs": [
141+
"{projectRoot}/scripts/ensure-db",
142+
"{workspaceRoot}/pkgs/core/supabase/migrations/**/*.sql",
143+
"{workspaceRoot}/pkgs/core/supabase/seed.sql",
144+
"{projectRoot}/supabase/config.toml",
145+
"{projectRoot}/tests/helpers/db.ts",
146+
"{projectRoot}/tests/helpers/permissions.ts"
147+
],
148+
"outputs": [
149+
"{projectRoot}/.nx-inputs/db-ready.txt"
150+
],
151+
"cache": false
152+
},
140153
"test:integration": {
141154
"executor": "nx:run-commands",
142155
"local": true,
@@ -182,7 +195,15 @@
182195
"test": {
183196
"executor": "nx:noop",
184197
"inputs": ["default", "^production"],
185-
"dependsOn": ["test:vitest", "test:types"]
198+
"dependsOn": ["test:unit", "test:types"]
199+
},
200+
"test:live": {
201+
"executor": "nx:noop",
202+
"inputs": ["default", "^production"],
203+
"dependsOn": ["test:integration"],
204+
"metadata": {
205+
"description": "Tests requiring live infrastructure (Supabase)"
206+
}
186207
},
187208
"benchmark": {
188209
"executor": "nx:run-commands",

0 commit comments

Comments
 (0)