Skip to content

Commit a308229

Browse files
committed
chore: setup demo deployments and small tweaks
1 parent 045ac50 commit a308229

File tree

21 files changed

+837
-139
lines changed

21 files changed

+837
-139
lines changed

.github/actions/deployment-comment/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ inputs:
77
required: true
88
preview-url:
99
description: 'The preview deployment URL'
10-
required: true
10+
required: false
1111
production-url:
1212
description: 'The production deployment URL'
1313
required: true

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ runs:
66
steps:
77
- uses: pnpm/action-setup@v4
88
with:
9-
version: '8.14.1'
9+
version: '10.20.0'
1010
run_install: false
1111

1212
- uses: actions/setup-node@v4

.github/workflows/ci.yml

Lines changed: 98 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Build all affected projects (except playground)
5454
run: pnpm nx affected -t build --configuration=production --parallel --exclude=playground --base="$NX_BASE" --head="$NX_HEAD"
5555

56+
- name: Verify exports for built packages
57+
run: pnpm nx affected -t verify-exports --base="$NX_BASE" --head="$NX_HEAD"
58+
5659

5760
# ─────────────────────────────────────── 2. EDGE-WORKER E2E ──────────────────────────────────────
5861
edge-worker-e2e:
@@ -101,49 +104,7 @@ jobs:
101104
run: pnpm nx affected -t test:e2e --parallel --base="$NX_BASE" --head="$NX_HEAD"
102105

103106

104-
# ────────────────────────────────── 3. DEPLOY PLAYGROUND ───────────────────────────
105-
deploy-playground:
106-
needs: [build-and-test, edge-worker-e2e]
107-
if: false # Disabled
108-
# if: >-
109-
# ${{
110-
# (github.event_name == 'pull_request') ||
111-
# (github.ref == 'refs/heads/main' && github.event_name == 'push')
112-
# }}
113-
runs-on: ubuntu-latest
114-
environment: ${{ github.event_name == 'pull_request' && 'preview' || 'production' }}
115-
env:
116-
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
117-
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
118-
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_PLAYGROUND_SITE_ID }}
119-
NEXT_PUBLIC_SUPABASE_URL: ${{ github.event_name == 'pull_request' && secrets.DEMO_PREVIEW_SUPABASE_URL || secrets.DEMO_PRODUCTION_SUPABASE_URL }}
120-
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ github.event_name == 'pull_request' && secrets.DEMO_PREVIEW_SUPABASE_ANON_KEY || secrets.DEMO_PRODUCTION_SUPABASE_ANON_KEY }}
121-
steps:
122-
- uses: actions/checkout@v4
123-
with:
124-
fetch-depth: 0
125-
126-
- uses: ./.github/actions/setup
127-
128-
# Build the workspace libraries that the app imports
129-
- run: pnpm nx run-many -t build --projects client,dsl --configuration=production
130-
131-
- name: Build & deploy to Netlify
132-
id: deploy
133-
run: |
134-
pnpm netlify deploy --build --filter=playground \
135-
--context ${{ github.event_name == 'pull_request' && 'deploy-preview' || 'production' }} \
136-
${{ github.event_name == 'pull_request' && format('--alias=pr-{0}', github.event.pull_request.number) || '--prod' }}
137-
138-
- name: Post deployment comment
139-
if: always()
140-
uses: ./.github/actions/deployment-comment
141-
with:
142-
project-name: Playground
143-
preview-url: https://pr-${{ github.event.pull_request.number }}--pgflow-demo.netlify.app
144-
production-url: https://playground.pgflow.dev
145-
146-
# ────────────────────────────────── 4. DEPLOY WEBSITE ───────────────────────────
107+
# ────────────────────────────────── 3. DEPLOY WEBSITE ───────────────────────────
147108
deploy-website:
148109
needs: [build-and-test, edge-worker-e2e]
149110
runs-on: ubuntu-latest
@@ -179,7 +140,27 @@ jobs:
179140
echo "affected=false" >> $GITHUB_OUTPUT
180141
echo "Website is not affected by changes - skipping deployment"
181142
fi
182-
143+
144+
- name: Validate Supabase environment variables
145+
if: steps.check-affected.outputs.affected == 'true'
146+
run: |
147+
if [ -z "$VITE_SUPABASE_URL" ]; then
148+
echo "❌ Error: VITE_SUPABASE_URL is not set"
149+
echo "Required GitHub secret missing: WEBSITE_${{ github.event_name == 'pull_request' && 'PREVIEW' || 'PRODUCTION' }}_SUPABASE_URL"
150+
exit 1
151+
fi
152+
if [ -z "$VITE_SUPABASE_ANON_KEY" ]; then
153+
echo "❌ Error: VITE_SUPABASE_ANON_KEY is not set"
154+
echo "Required GitHub secret missing: WEBSITE_${{ github.event_name == 'pull_request' && 'PREVIEW' || 'PRODUCTION' }}_SUPABASE_ANON_KEY"
155+
exit 1
156+
fi
157+
if [[ ! "$VITE_SUPABASE_URL" =~ ^https:// ]]; then
158+
echo "❌ Error: VITE_SUPABASE_URL must use https:// (not http://)"
159+
echo "Current value: $VITE_SUPABASE_URL"
160+
exit 1
161+
fi
162+
echo "✅ Supabase environment variables are valid"
163+
183164
- name: Deploy website
184165
id: deploy-website
185166
if: steps.check-affected.outputs.affected == 'true'
@@ -200,3 +181,76 @@ jobs:
200181
preview-url: https://pr-${{ github.event.pull_request.number }}.pgflow.pages.dev
201182
production-url: https://pgflow.dev
202183

184+
# ────────────────────────────────── 4. DEPLOY DEMO ───────────────────────────
185+
deploy-demo:
186+
needs: [build-and-test, edge-worker-e2e]
187+
runs-on: ubuntu-latest
188+
# Only run on main branch pushes (production) - skip PRs for now
189+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
190+
environment: production
191+
env:
192+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
193+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
194+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
195+
# Hardcoded for testing - these are public values
196+
VITE_SUPABASE_URL: https://bsgbmmbmlmcmdnheuwmt.supabase.co
197+
VITE_SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJzZ2JtbWJtbG1jbWRuaGV1d210Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjIzNDA2NzIsImV4cCI6MjA3NzkxNjY3Mn0.Uoy8iqxycrqd4b6LPMMXWWSYrP1BDRMrJVgM2_vtl6o
198+
steps:
199+
- uses: actions/checkout@v4
200+
with:
201+
fetch-depth: 0
202+
203+
- uses: ./.github/actions/setup
204+
205+
- name: Set Nx SHAs for affected commands
206+
uses: nrwl/nx-set-shas@v4
207+
208+
- name: Verify NX_BASE and NX_HEAD are set
209+
run: echo "BASE=$NX_BASE HEAD=$NX_HEAD"
210+
211+
- name: Check if demo is affected
212+
id: check-affected
213+
run: |
214+
if pnpm nx show projects --affected -t build --base="$NX_BASE" --head="$NX_HEAD" | grep -q "^demo$"; then
215+
echo "affected=true" >> $GITHUB_OUTPUT
216+
echo "Demo is affected by changes"
217+
else
218+
echo "affected=false" >> $GITHUB_OUTPUT
219+
echo "Demo is not affected by changes - skipping deployment"
220+
fi
221+
222+
- name: Validate Supabase environment variables
223+
if: steps.check-affected.outputs.affected == 'true'
224+
run: |
225+
if [ -z "$VITE_SUPABASE_URL" ]; then
226+
echo "❌ Error: VITE_SUPABASE_URL is not set"
227+
echo "Required GitHub secret missing: DEMO_${{ github.event_name == 'pull_request' && 'PREVIEW' || 'PRODUCTION' }}_SUPABASE_URL"
228+
exit 1
229+
fi
230+
if [ -z "$VITE_SUPABASE_ANON_KEY" ]; then
231+
echo "❌ Error: VITE_SUPABASE_ANON_KEY is not set"
232+
echo "Required GitHub secret missing: DEMO_${{ github.event_name == 'pull_request' && 'PREVIEW' || 'PRODUCTION' }}_SUPABASE_ANON_KEY"
233+
exit 1
234+
fi
235+
if [[ ! "$VITE_SUPABASE_URL" =~ ^https:// ]]; then
236+
echo "❌ Error: VITE_SUPABASE_URL must use https:// (not http://)"
237+
echo "Current value: $VITE_SUPABASE_URL"
238+
exit 1
239+
fi
240+
echo "✅ Supabase environment variables are valid"
241+
242+
- name: Deploy demo to production
243+
id: deploy-demo
244+
if: steps.check-affected.outputs.affected == 'true'
245+
run: |
246+
echo "Deploying demo to production (demo.pgflow.dev)..."
247+
pnpm nx run demo:deploy --skip-nx-cache
248+
249+
- name: Post deployment comment
250+
if: always()
251+
uses: ./.github/actions/deployment-comment
252+
with:
253+
project-name: Demo
254+
production-url: https://demo.pgflow.dev
255+
# No preview URL - we only deploy production from main branch
256+

apps/demo/DEPLOYMENT.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Demo App Deployment Guide
2+
3+
## Prerequisites
4+
5+
- Node.js 20+, pnpm
6+
- Supabase account (Pro Plan for branching)
7+
- Cloudflare account
8+
- Groq or OpenAI API key
9+
10+
## Initial Setup
11+
12+
### 1. Supabase Projects
13+
14+
Create two Supabase projects:
15+
- **Production**: `pgflow-demo-prod`
16+
- **Preview**: `pgflow-demo-preview`
17+
18+
Note the project refs from dashboard URLs: `https://supabase.com/dashboard/project/<project-ref>`
19+
20+
### 2. Database Setup
21+
22+
For each project (production and preview):
23+
24+
```bash
25+
cd apps/demo
26+
27+
# Link to project
28+
supabase link --project-ref <PROJECT_REF>
29+
30+
# Reset database (applies migrations + seed data)
31+
supabase db reset --linked
32+
33+
# Deploy Edge Functions
34+
supabase functions deploy --project-ref <PROJECT_REF>
35+
```
36+
37+
### 3. Edge Function Secrets
38+
39+
Set environment variables for Edge Functions:
40+
41+
```bash
42+
# Set LLM API key (choose Groq or OpenAI)
43+
supabase secrets set GROQ_API_KEY=your_groq_key_here
44+
# OR
45+
supabase secrets set OPENAI_API_KEY=your_openai_key_here
46+
47+
# Verify secrets are set
48+
supabase secrets list
49+
```
50+
51+
Repeat for both production and preview projects.
52+
53+
### 4. Cloudflare Setup
54+
55+
```bash
56+
# Authenticate with Cloudflare
57+
pnpm wrangler login
58+
59+
# Deploy production (from repo root)
60+
pnpm nx deploy demo
61+
62+
# Deploy preview
63+
pnpm nx deploy:preview demo
64+
```
65+
66+
### 5. GitHub Secrets
67+
68+
Add these secrets to your GitHub repository (Settings → Secrets):
69+
70+
**Supabase (Production):**
71+
- `SUPABASE_ACCESS_TOKEN` - Personal access token from https://supabase.com/dashboard/account/tokens
72+
- `PRODUCTION_PROJECT_ID` - Production project ref
73+
- `PRODUCTION_DB_PASSWORD` - Production database password
74+
75+
**Supabase (Preview):**
76+
- `PREVIEW_PROJECT_ID` - Preview project ref
77+
- `PREVIEW_DB_PASSWORD` - Preview database password
78+
79+
**Cloudflare:**
80+
- `CLOUDFLARE_API_TOKEN` - API token from Cloudflare dashboard
81+
- `CLOUDFLARE_ACCOUNT_ID` - Account ID from Cloudflare dashboard
82+
83+
### 6. Enable Supabase Branching (Optional)
84+
85+
For automatic per-PR preview databases:
86+
87+
1. Go to Supabase project → Settings → Integrations → GitHub
88+
2. Enable Branching
89+
3. Configure branch triggers (e.g., `feat-demo-*`)
90+
91+
## Deployment URLs
92+
93+
- **Production**: https://demo.pgflow.dev
94+
- **Preview**: https://pr-{number}.pgflow-demo.workers.dev
95+
96+
## Manual Deployments
97+
98+
### Production
99+
```bash
100+
pnpm nx deploy demo
101+
```
102+
103+
### Preview
104+
```bash
105+
# With custom name (using script directly)
106+
cd apps/demo
107+
./scripts/deploy-preview.sh my-feature
108+
109+
# With custom name (using nx)
110+
PREVIEW_NAME=my-feature pnpm nx deploy:preview demo
111+
112+
# With PR number (CI)
113+
PR_NUMBER=123 pnpm nx deploy:preview demo
114+
115+
# Default local preview
116+
pnpm nx deploy:preview demo
117+
```
118+
119+
### Reset Database
120+
```bash
121+
cd apps/demo
122+
supabase link --project-ref <PROJECT_REF>
123+
supabase db reset --linked
124+
```
125+
126+
## Troubleshooting
127+
128+
**Edge Functions failing:**
129+
- Check secrets are set: `supabase secrets list`
130+
- Verify you're linked to correct project: `cat supabase/.branches/_current_branch`
131+
132+
**Database out of sync:**
133+
- Run `supabase db reset --linked` to reapply all migrations
134+
135+
**Cloudflare deployment fails:**
136+
- Ensure you're authenticated: `pnpm wrangler whoami`
137+
- Check wrangler.toml routes match your domain

apps/demo/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"postcss": "8.4.49",
3333
"prettier": "^3.6.2",
3434
"prettier-plugin-svelte": "^3.4.0",
35+
"supabase": "^2.34.3",
3536
"svelte": "^5.41.0",
3637
"svelte-check": "^4.3.3",
3738
"tailwind-merge": "^3.3.1",
@@ -40,7 +41,8 @@
4041
"tw-animate-css": "^1.4.0",
4142
"typescript": "^5.9.3",
4243
"typescript-eslint": "^8.46.1",
43-
"vite": "^7.1.10"
44+
"vite": "^7.1.10",
45+
"wrangler": "^4.20.3"
4446
},
4547
"dependencies": {
4648
"@pgflow/client": "workspace:*",

apps/demo/project.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@
5050
"command": "deno test --allow-env --allow-net tests/",
5151
"cwd": "apps/demo/supabase/functions/article_flow_worker"
5252
}
53+
},
54+
"ensure-ci-environment": {
55+
"executor": "nx:run-commands",
56+
"options": {
57+
"command": "node -e \"if (!process.env.CI) throw new Error('This target must run in CI environment')\""
58+
}
59+
},
60+
"deploy": {
61+
"executor": "nx:run-commands",
62+
"cache": false,
63+
"local": true,
64+
"dependsOn": ["build", "ensure-ci-environment"],
65+
"inputs": ["{projectRoot}/wrangler.toml"],
66+
"options": {
67+
"cwd": "apps/demo",
68+
"command": "wrangler deploy --env production"
69+
}
70+
},
71+
"deploy:preview": {
72+
"executor": "nx:run-commands",
73+
"cache": false,
74+
"local": true,
75+
"dependsOn": ["build"],
76+
"inputs": ["{projectRoot}/wrangler.toml"],
77+
"options": {
78+
"cwd": "apps/demo",
79+
"command": "./scripts/deploy-preview.sh ${PREVIEW_NAME:-pr-${PR_NUMBER:-preview}}"
80+
}
5381
}
5482
}
5583
}

0 commit comments

Comments
 (0)