Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 71 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: 'Test & Deploy'
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'src/**'
- 'e2e/**'
Expand All @@ -20,6 +22,7 @@ on:
- '!**.md'
- '!.ai/**'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'src/**'
- 'e2e/**'
Expand Down Expand Up @@ -140,7 +143,7 @@ jobs:
env:
CI: 'true'
COVERAGE: 'true'
BASE_URL: 'http://localhost:45678'
DB_FILE: 'file:./prisma-e2e/test.db'
BETTER_AUTH_SECRET: 'test-secret-key-at-least-32-characters-long-for-ci'
BETTER_AUTH_URL: 'http://localhost:45678'

Expand Down Expand Up @@ -197,6 +200,7 @@ jobs:
retention-days: 1

deploy:
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: [unit-integration-tests, e2e-tests]
env:
Expand All @@ -209,17 +213,80 @@ jobs:
- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel Environment Information
- name: Pull Vercel Environment Information (Production)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts
- name: Pull Vercel Environment Information (Preview)
if: github.event_name == 'pull_request'
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Build Project Artifacts (Production)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
- name: Build Project Artifacts (Preview)
if: github.event_name == 'pull_request'
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel (Production)
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
url="$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }})"
vercel alias --scope jcubics-projects --token=${{ secrets.VERCEL_TOKEN }} set "$url" app.snapp.md

- name: Deploy Project Artifacts to Vercel (Preview)
if: github.event_name == 'pull_request'
id: deploy-preview
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})"
echo "preview_url=$url" >> $GITHUB_OUTPUT

- name: Comment PR with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const previewUrl = '${{ steps.deploy-preview.outputs.preview_url }}';
const comment = `## 🚀 Preview Deployment

Your preview deployment is ready!

✅ **Preview URL:** ${previewUrl}

---
*This preview will be updated automatically when you push new commits to this PR.*`;

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Preview Deployment')
);

// Update or create comment
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}

merge-coverage:
runs-on: ubuntu-latest
needs: [unit-integration-tests, e2e-tests]
Expand Down
25 changes: 21 additions & 4 deletions e2e/setup-e2e-db.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
#!/usr/bin/env node

/**
* E2E Test Database Setup Script
*
* Prepares SQLite database for Playwright E2E tests.
*
* Steps:
* 1. Cleans up existing test database and .next cache
* 2. Generates Prisma Client for SQLite (prisma-e2e/types)
* 3. Creates test database using prisma db push
*
* Note: CI=true is required for prisma.config.ts to select the
* correct schema (prisma-e2e/schema.prisma)
*/

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const dbFile = path.join(__dirname, './prisma-e2e/test.db');
const dbFile = path.join(__dirname, '../prisma-e2e/test.db');
const nextDir = path.join(__dirname, '../.next');

if (fs.existsSync(dbFile)) {
Expand All @@ -20,14 +34,17 @@ if (fs.existsSync(nextDir)) {
const dbUrl = `file:${dbFile}`;

console.log('Generating Prisma client for E2E tests (SQLite)...');
// CI=true required to select prisma-e2e/schema.prisma in prisma.config.ts
execSync('npx prisma generate --schema=prisma-e2e/schema.prisma', {
stdio: 'inherit'
stdio: 'inherit',
env: { ...process.env, CI: true }
});

console.log('Creating E2E test database...');
execSync('npx prisma db push --skip-generate --schema=prisma-e2e/schema.prisma', {
// CI=true required to select prisma-e2e/schema.prisma in prisma.config.ts
execSync('npx prisma db push --schema=prisma-e2e/schema.prisma', {
stdio: 'inherit',
env: { ...process.env }
env: { ...process.env, CI: true }
});

console.log('E2E test database ready');
Loading
Loading