Production deployment guide using GitHub Actions for continuous integration and automated deployment to Vercel.
The SaaS boilerplate uses GitHub Actions for CI/CD with automatic deployment to Vercel:
CI/CD Pipeline
Branch Strategy
main - Production branch (protected)dev - Preview/staging branchKey Features
The deployment process is controlled by GitHub Actions workflows that prevent broken code from reaching production.
Trigger: Push to main branch
File: .github/workflows/production.yml
Pipeline Steps:
Environment Setup
--frozen-lockfileCode Quality
pnpm lint to check code styleBuild Validation
pnpm build with production environment variablesTesting
pnpm test with all unit testsDatabase Migration
pnpm db:migrate to update schemaIf any step fails, deployment is blocked.
Trigger: Push to dev branch or Pull Request to dev
File: .github/workflows/preview.yml
Same pipeline as production but:
The build process is critical and depends on proper environment configuration.
Environment Variables Required for Build:
# The build REQUIRES these environment variables to succeed
NODE_ENV=production
DATABASE_URL="postgres://..."
BETTER_AUTH_SECRET="your-secret"
BETTER_AUTH_URL="https://yourdomain.com"
NEXT_PUBLIC_APP_URL="https://yourdomain.com"
# These variables are validated at build time
RESEND_API_KEY="re_..."
SUPABASE_URL="https://..."
SUPABASE_ANON_KEY="..."
STRIPE_SECRET_KEY="sk_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_..."1. Local Build Testing
# Test build locally before pushing
pnpm build
# If build fails, fix issues before committing
# Common issues: missing env vars, type errors, import problems2. Production Environment File
# Create .env.production with all required variables
cp .env.development .env.production
# Update with production values3. Build Dependencies
Common Build Failures:
Missing Environment Variables
# Error: Environment variable X is not defined
# Solution: Add missing variables to GitHub SecretsDatabase Connection Issues
# Error: connect ECONNREFUSED
# Solution: Verify DATABASE_URL in GitHub SecretsAPI Key Validation
# Error: Invalid Stripe/Resend API key
# Solution: Check API keys are production keys, not test keysAll environment variables must be added as GitHub Secrets for the CI/CD pipeline to work:
Required Secrets (based on workflows):
# Repository Settings → Secrets and variables → Actions → New repository secret
DATABASE_URL # Production database connection
BETTER_AUTH_SECRET # Authentication secret key
RESEND_API_KEY # Email service API key
SUPABASE_ANON_KEY # Supabase anonymous key for file storage
STRIPE_SECRET_KEY # Stripe secret key for payments
STRIPE_WEBHOOK_SECRET # Stripe webhook verification
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY # Stripe public key (client-side)Additional Configuration in Workflows:
Vercel works with GitHub Actions to provide zero-downtime deployments with automatic rollbacks when CI/CD passes.
Deployment Flow:
Framework Preset: Next.js
Root Directory: ./ (leave empty for root)
Build Command: pnpm build
Output Directory: .next (automatically detected)
Install Command: pnpm install --frozen-lockfile
Development Command: pnpm dev
Node.js Version: 23.x (match GitHub Actions)
Package Manager: pnpm
Project Settings → Git:
Production Branch: main
Preview Branches: dev, feature/*
Important Settings:
Set the same variables as GitHub Secrets in Vercel Dashboard:
Project Settings → Environment Variables
Add all secrets from GitHub Actions and configure for Production, Preview, and Development environments.
Ensure Vercel environment variables match GitHub secrets exactly.
Protect the main branch to enforce CI/CD pipeline and prevent direct commits to production.
Repository Settings → Branches → Add rule for main branch:
✓ Require status checks to pass before merging
✓ Require branches to be up to date before merging
✓ Status checks: Production Deployment (or your workflow name)
✓ Restrict pushes that create new commits
This ensures:
Complete deployment process from development to production:
# Create feature branch
git checkout -b feature/new-payment-integration
# Develop and test locally
pnpm dev
pnpm test
pnpm build
# Commit and push
git add .
git commit -m "Add new payment integration"
git push origin feature/new-payment-integration# Create PR to dev branch
# GitHub Actions runs preview workflow:
# 1. Lint code
# 2. Build with preview config
# 3. Run tests
# 4. Run database migrations
# 5. Deploy to preview environment if all pass
# Merge to dev triggers preview deployment
git checkout dev
git merge feature/new-payment-integration
git push origin dev# Create PR from dev to main
# After review and approval:
git checkout main
git merge dev
git push origin main
# GitHub Actions runs production workflow:
# 1. Lint code (blocks if fails)
# 2. Build with production config (blocks if fails)
# 3. Run all tests (blocks if fails)
# 4. Run database migrations (blocks if fails)
# 5. Vercel auto-deploys if all passEssential steps that must be completed for successful deployment:
The build MUST pass with production environment variables:
# Test locally with production config
NODE_ENV=production pnpm build
# Common failures:
# - Missing environment variables
# - Database connection issues
# - Invalid API keys
# - TypeScript errorsAutomatic migration in CI/CD:
pnpm db:migrateAll checks must pass:
pnpm lint)pnpm build)pnpm test)pnpm db:migrate)If any fail, deployment is blocked.
Common issues and solutions:
Build Failures:
# Check GitHub Actions logs
# Common issues:
# - Missing secrets in repository
# - Invalid environment variable format
# - Database connection timeout
# - API key validation failuresTest Failures:
# All tests must pass in CI environment
# Check if tests work with production config
# Ensure test database is properly configuredMigration Failures:
# Database migration errors block deployment
# Verify DATABASE_URL is correct
# Check for schema conflicts
# Ensure database is accessible from GitHub ActionsEnvironment Variables:
# Ensure Vercel env vars match GitHub secrets
# Check NEXT_PUBLIC_ variables are available client-side
# Verify API endpoints are accessibleBuild Timeouts:
# Vercel build timeout on complex builds
# Optimize dependencies and build process
# Consider splitting large applicationsIf production is broken, use these emergency procedures for immediate rollback.
Via Vercel Dashboard:
Via Vercel CLI:
# Install and login
npm i -g vercel
vercel login
# List deployments and rollback
vercel ls
vercel promote [previous-deployment-url] --scope=teamAfter rollback, verify everything works:
# Check application health
curl https://yourdomain.com/api/health
# Check database connectivity
psql $DATABASE_URL -c "SELECT 1"Complete analysis of workflows, quality gates, and deployment pipeline
Drizzle ORM migration execution in CI/CD and schema management
Point-in-time recovery using included backup and restore scripts
Debugging deployment issues and emergency rollback procedures
Deployment ready! The GitHub Actions CI/CD pipeline will automatically handle all future deployments when you push to the main branch.