Skip to content

Commit cf9bb82

Browse files
committed
Refactor workflows for clarity, and add test container Supabase migrations push
1 parent 95f347d commit cf9bb82

6 files changed

Lines changed: 221 additions & 113 deletions

File tree

.env.example

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ KV_REST_API_TOKEN="local-dev-token"
3434
KV_REST_API_READ_ONLY_TOKEN="local-dev-token"
3535
REDIS_URL="redis://default:local-dev-token@127.0.0.1:6380"
3636

37-
# Supabase (API + Postgres stack started via `npm run containers:supabase:start`)
38-
# These are local keys and for GitHub Actions, use production keys on Vercel
39-
# - SUPABASE_URL: REST endpoint the app and tests call (PostgREST) for the Supabase Docker container
40-
# - SUPABASE_DB_URL: direct Postgres connection string to the production database used by `supabase db push`
41-
# - SUPABASE_DB_PASSWORD: password for the linked hosted project; also used by the CLI when linking
37+
# Supabase configuration
38+
# - SUPABASE_URL / SUPABASE_KEY: client + server runtime credentials used in Astro and API routes.
39+
# - SUPABASE_SERVICE_ROLE_KEY: server-side key for tests and cron endpoints (never expose to browser).
40+
# - SUPABASE_HEALTH_TIMEOUT: controls how long we wait for the local Supabase container to become healthy.
41+
# - SUPABASE_DB_PASSWORD / SUPABASE_PROJECT_REF / SUPABASE_ACCESS_TOKEN: only needed when pushing
42+
# migrations to the hosted project (GitHub "build" workflow). Leave them empty locally unless you
43+
# have production access.
4244
SUPABASE_HEALTH_TIMEOUT="240"
4345
SUPABASE_URL="http://127.0.0.1:54321"
4446
SUPABASE_KEY="sb_publishable_example"
4547
SUPABASE_SERVICE_ROLE_KEY="sb_secret_example"
46-
SUPABASE_DB_URL="postgresql://postgres:postgres@127.0.0.1:54322/postgres"
4748
SUPABASE_DB_PASSWORD="example-db-password"
4849
SUPABASE_PROJECT_REF="exampleprojectref"
4950
SUPABASE_ACCESS_TOKEN="sbp_example_personal_access_token"

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Test
7+
types:
8+
- completed
9+
10+
jobs:
11+
push-supabase-migrations:
12+
name: Push Supabase Production Migrations
13+
runs-on: ubuntu-latest
14+
if: >-
15+
github.event.workflow_run.conclusion == 'success' &&
16+
github.event.workflow_run.event == 'push' &&
17+
github.event.workflow_run.head_branch == 'main'
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
ref: ${{ github.event.workflow_run.head_sha }}
24+
25+
- name: Install Supabase CLI
26+
uses: supabase/setup-cli@v1.6.0
27+
with:
28+
version: latest
29+
30+
- name: Link Supabase project
31+
run: supabase link --project-ref ${{ secrets.SUPABASE_PROJECT_REF }} --password "${{ secrets.SUPABASE_DB_PASSWORD }}" --workdir suprabase
32+
env:
33+
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
34+
35+
- name: Push migrations to production
36+
run: supabase db push --workdir suprabase

.github/workflows/deployment.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Test
7+
types:
8+
- completed
9+
10+
jobs:
11+
deploy-preview:
12+
name: Deploy Preview to Vercel
13+
runs-on: ubuntu-latest
14+
if: >-
15+
github.event.workflow_run.conclusion == 'success' &&
16+
github.event.workflow_run.event == 'pull_request'
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.workflow_run.head_sha }}
23+
24+
- name: Deploy to Vercel (Preview)
25+
uses: amondnet/vercel-action@v41.1.4
26+
id: vercel-preview
27+
with:
28+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
29+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
30+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
31+
github-comment: true
32+
env:
33+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
34+
35+
- name: Comment preview URL on PR
36+
uses: actions/github-script@v8
37+
with:
38+
script: |
39+
const previewUrl = '${{ steps.vercel-preview.outputs.preview-url }}';
40+
const pr = context.payload.workflow_run.pull_requests && context.payload.workflow_run.pull_requests[0];
41+
if (!pr) {
42+
core.warning('No pull request metadata available; skipping preview comment.');
43+
return;
44+
}
45+
await github.rest.issues.createComment({
46+
issue_number: pr.number,
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
body: `✅ Tests passed! Preview deployment ready:\n\n🔗 ${previewUrl}`
50+
});
51+
52+
deploy-production:
53+
name: Deploy to Production (Vercel)
54+
runs-on: ubuntu-latest
55+
if: >-
56+
github.event.workflow_run.conclusion == 'success' &&
57+
github.event.workflow_run.event == 'push' &&
58+
github.event.workflow_run.head_branch == 'main'
59+
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v4
63+
with:
64+
ref: ${{ github.event.workflow_run.head_sha }}
65+
66+
- name: Deploy to Vercel (Production)
67+
uses: amondnet/vercel-action@v41.1.4
68+
id: vercel-production
69+
with:
70+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
71+
vercel-args: '--prod'
72+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
73+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
74+
env:
75+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
76+
77+
- name: Log production deployment
78+
run: |
79+
echo "🚀 Production deployment completed"
80+
echo "Production URL: ${{ steps.vercel-production.outputs.preview-url }}"

0 commit comments

Comments
 (0)