Skip to content

Commit 163c570

Browse files
authored
Merge pull request #4 from cheatcode-ai/ci/fix-db-migrate-env-build
fix(ci): build db dep closure before db:generate (DB Migrate)
2 parents 1a23641 + 7b7e40d commit 163c570

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

.github/workflows/db-migrate.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- packages/db/src/schema/**
88
- packages/db/drizzle/**
99
- scripts/migrate.ts
10+
- .github/workflows/db-migrate.yml
1011
workflow_dispatch:
1112

1213
concurrency:
@@ -17,6 +18,10 @@ jobs:
1718
diff:
1819
if: github.event_name == 'pull_request'
1920
runs-on: ubuntu-latest
21+
env:
22+
# Empty unless the SUPABASE_MIGRATION_URL secret is configured. Gates the
23+
# connection-dependent migration-plan step below.
24+
MIGRATION_DB_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}
2025
steps:
2126
- uses: actions/checkout@v4
2227
- uses: pnpm/action-setup@v4
@@ -27,14 +32,27 @@ jobs:
2732
node-version: 22
2833
cache: pnpm
2934
- run: pnpm install --frozen-lockfile
35+
# drizzle.config.ts imports @cheatcode/env/migrate (built ./dist), so build the db
36+
# package's workspace dep closure before generate — otherwise db:generate fails with
37+
# "Cannot find module @cheatcode/env/dist/migrate.js" on a fresh runner.
38+
- run: pnpm turbo build --filter=@cheatcode/db^...
39+
# drizzle-kit generate reads the schema and never connects; a placeholder URL just
40+
# satisfies drizzle.config.ts's eager loadMigrationEnv() call.
3041
- run: pnpm --filter @cheatcode/db db:generate
42+
env:
43+
SUPABASE_MIGRATION_URL: postgres://placeholder@localhost:5432/placeholder
3144
- name: Fail if Drizzle migrations drifted
3245
run: git diff --exit-code packages/db/drizzle
46+
# The pending-plan comment needs a real DB connection, so it only runs when the
47+
# SUPABASE_MIGRATION_URL secret is configured (it is not today). The drift check
48+
# above is the gate; this stays best-effort.
3349
- name: Compute pending migration plan
50+
if: env.MIGRATION_DB_URL != ''
3451
run: pnpm tsx scripts/migrate.ts --dry-run | tee migration-plan.txt
3552
env:
36-
SUPABASE_MIGRATION_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}
53+
SUPABASE_MIGRATION_URL: ${{ env.MIGRATION_DB_URL }}
3754
- uses: marocchino/sticky-pull-request-comment@v2
55+
if: env.MIGRATION_DB_URL != ''
3856
with:
3957
header: db-migration-plan
4058
path: migration-plan.txt

0 commit comments

Comments
 (0)