How to deploy to Vercel
Vercel Deployment Guide
This template ships with first-class Vercel support for Preview and Production deployments, plus PR cleanup. Use this when your project selects Vercel as the provider.
Overview
- Preview:
deploy-preview.yml(on PR open/sync) → creates Neon DB branch, runs migrations, deploys to Vercel, comments Preview URL on PR - Production:
deploy-production.yml(onmain) → runs CI checks, applies migrations, deploys to Vercel Prod - Cleanup:
cleanup-preview.yml(on PR close) → deletes Neon DB branch; Vercel cleanup step is scaffolded
Prerequisites
- Vercel account and project linked to this GitHub repo
- Repo Secrets/Variables
- Secrets
VERCEL_TOKEN: Vercel personal tokenNEON_API_KEY: Neon API key
- Variables
NEON_PROJECT_ID: Neon project ID- (Optional) Any public env variables for Next.js (e.g.,
NEXT_PUBLIC_*)
- Secrets
Preview Deployments (PRs)
Workflow: .github/workflows/deploy-preview.yml
prepare_dbjob- Creates a Neon branch named
preview/pr-<PR_NUMBER>-<branch> - Exposes outputs:
neon_branch_id,neon_branch_name,neon_db_url,pr_branch_name - Runs
pnpm run db:migrateagainst the preview DB URL
- Creates a Neon branch named
deploy_verceljob- Uses composite action
.github/workflows/cd/vercel/deploy-preview - Pulls Vercel envs, builds, and deploys prebuilt artifacts
- Outputs
preview_url
- Uses composite action
comment_prjob- Posts the Vercel Preview URL and Neon branch link on the PR
Required Secrets/Vars
VERCEL_TOKEN(Secret)NEON_API_KEY(Secret)NEON_PROJECT_ID(Variable)
Notes
- The composite action already pulls Vercel envs for the Preview environment using the CLI (
vercel env pullandvercel pull). - Ensure any required runtime/build envs are configured in your Vercel project settings.
Production Deployments (main)
Workflow: .github/workflows/deploy-production.yml
ci_checksjob reuses.github/workflows/ci.yml(lint/typecheck/format)apply_migrationsrunspnpm run db:migrateagainstsecrets.DATABASE_URLdeploy_vercel_productionuses composite action.github/workflows/cd/vercel/deploy-production
Required Secrets
VERCEL_TOKENDATABASE_URL
Branch Protection (Recommended)
- In GitHub → Settings → Branches → Branch protection rules
- Protect
main - Require status checks to pass: add the workflow name
CI - Optionally require PRs before merging
- Protect
Cleanup on PR Close
Workflow: .github/workflows/cleanup-preview.yml
- Deletes the Neon branch associated with the PR
- Vercel cleanup composite is scaffolded (currently logs TODO)
Troubleshooting
- Preview URL missing in PR: verify
VERCEL_TOKENis set and the deploy job completed successfully - Migrations failing: confirm Neon credentials and that
pnpm run db:migrateruns locally with the same version - Env variable not present at runtime: verify it exists in Vercel Project Settings for the correct environment (Preview/Production)