Cursorcursorintermediate

Add GitHub Actions CI/CD to Next.js (Cursor Prompt)

Cursor prompt to set up GitHub Actions with linting, testing, and deployment pipeline.

What you'll get

GitHub Actions CI/CD with lint, type-check, test, build, and deploy pipelines for Next.js.

The Prompt

Set up GitHub Actions CI/CD for this Next.js project.

FILES TO CREATE:
- .github/workflows/ci.yml — CI pipeline (lint, type-check, test, build)
- .github/workflows/deploy.yml — Deploy pipeline (on push to main)
- .github/workflows/preview.yml — Preview deployment (on PR)

CI PIPELINE (ci.yml):
Trigger: on push and pull_request to main
Jobs:
1. lint — Run 'npm run lint' (ESLint)
2. type-check — Run 'npx tsc --noEmit'
3. test — Run 'npm test' (unit tests with Vitest)
4. e2e — Run 'npx playwright test' with Playwright installed
5. build — Run 'npm run build' to verify production build succeeds

Configure:
- Use Node.js 20
- Cache node_modules using actions/cache with package-lock.json hash
- Cache Next.js .next/cache between builds
- Run lint, type-check, and unit tests in parallel
- Run e2e and build after unit tests pass

DEPLOY PIPELINE (deploy.yml):
Trigger: on push to main (after CI passes)
1. Build the project
2. Deploy to Vercel using vercel CLI (or your hosting provider)
3. Run post-deploy health check on the deployed URL

PREVIEW PIPELINE (preview.yml):
Trigger: on pull_request
1. Deploy a preview build
2. Comment the preview URL on the PR

DO NOT:
- Store secrets in the workflow file — use GitHub Secrets
- Skip the build step — it catches errors that lint and type-check miss
- Run tests against production databases

GITHUB SECRETS NEEDED:
- VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID (for Vercel deploy)
- Or your hosting provider's deploy credentials

Replace these variables

VariableReplace with
[HOSTING_PROVIDER]Deployment target (e.g., Vercel, Netlify, AWS)
[NODE_VERSION]Node.js version to use (e.g., 20)

Tips for best results

Cache node_modules and .next/cache to cut CI time in half.

Run lint and type-check in parallel — they're independent and save minutes on each run.

Follow-up prompts

Add release automation

Add semantic-release or changesets for automated versioning and changelog generation on merge to main.

Related prompts