TL;DR
What: GitHub’s built-in CI/CD and automation platform.
Why: Native GitHub integration, free for public repos, marketplace of actions, matrix builds.
Quick Start
Create .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
Push to trigger the workflow.
Cheatsheet
| Trigger | Syntax |
|---|---|
| Push | on: push |
| Pull request | on: pull_request |
| Schedule | on: schedule: - cron: '0 0 * * *' |
| Manual | on: workflow_dispatch |
| Other workflow | on: workflow_call |
Gotchas
Matrix builds
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
Secrets and environment variables
jobs:
deploy:
runs-on: ubuntu-latest
env:
NODE_ENV: production
steps:
- run: echo ${{ secrets.API_KEY }}
- run: echo $NODE_ENV
Caching dependencies
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Conditional steps
- name: Deploy
if: github.ref == 'refs/heads/main'
run: ./deploy.sh
Artifacts
- uses: actions/upload-artifact@v4
with:
name: build
path: dist/
Next Steps
- GitHub Actions Documentation - Official docs
- Actions Marketplace - Pre-built actions
- Workflow Syntax - Reference
- GitHub Actions Patterns - Examples