GitHub Actions — Node.js CI Pipeline
Complete CI workflow for Node.js: install, lint, test, build on every push and PR with caching.
name: Node.js CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test -- --coverage
- run: npm run build
- name: Upload coverage
if: matrix.node-version == 20
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/Sponsored
GitHub
Use Cases
- Automated testing on every push and PR
- Matrix testing across Node.js versions
- CI pipeline for open-source Node.js projects
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
GitHub Actions — Reusable Workflow Pattern
Create reusable workflows called from other workflows with inputs, secrets, and output passing.
Best for: DRY deployment workflows across environments
GitHub Actions CI/CD Pipeline
Complete GitHub Actions workflow with test, build, and deploy stages for a Node.js application.
Best for: Automated testing and deployment on push
GitHub Actions Docker Build and Push
GitHub Actions workflow to build a Docker image and push it to GitHub Container Registry on release.
Best for: Automated Docker image publishing on release
GitHub Actions Test Matrix Strategy
GitHub Actions workflow with matrix strategy to test across multiple Node versions and OS platforms.
Best for: Cross-platform compatibility testing