Content
GitHub Actions CI
Automate testing, building, and deploying with GitHub Actions workflows.
Workflow anatomy
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm test
- run: pnpm lint
Caching
- Cache node_modules with
actions/setup-nodecache option - Cache build outputs (.next, dist) between runs
- Use
actions/cachefor custom cache keys - Hash lockfile for cache invalidation
Best practices
- Run tests on every PR and push to main
- Fail fast — lint and type-check before running tests
- Matrix builds for multiple Node versions or OS targets
- Reusable workflows for shared CI logic across repos
- Branch protection rules requiring CI to pass
Deployment
- Deploy preview environments on PR open
- Deploy to production on merge to main
- Use environment secrets for deployment credentials
- Require manual approval for production deploys (optional)
- Rollback strategy for failed deployments
Security
- Pin action versions to SHA hashes