How I set up automated testing and deployment for my Next.js portfolio using GitHub Actions — no external CI tools required.
CI/CD sounds intimidating but GitHub Actions makes it surprisingly accessible. Here's exactly how I set up automated deployment for this portfolio.
Every time I push to main:
Create .github/workflows/ci.yml:
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run linting
run: npm run lint
- name: Build project
run: npm run build
For anything sensitive (API keys, tokens), use GitHub Repository Secrets:
MONGO_URI, VERCEL_TOKENThen reference them in the workflow:
env:
MONGO_URI: ${{ secrets.MONGO_URI }}
If you connect your GitHub repo directly to Vercel, it handles deployment automatically on every push to main. No workflow step needed.
For a custom deploy step:
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: "--prod"
npm ci is faster and more reliable than npm install in CI environmentscache: 'npm' to speed up subsequent runs significantly