GitHub Actions
GitHub Actions automate workflows directly in your repository.
Basic Workflow
Create a file at .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 install
- run: npm test
Key Concepts
| Concept | Description |
|---|---|
| Workflow | Automated process defined in YAML |
| Event | Trigger that starts a workflow (push, pull_request, schedule) |
| Job | Set of steps that run on the same runner |
| Step | Individual task - runs a command or an action |
| Action | Reusable unit of code (actions/checkout@v4) |
Workflow Diagram
graph LR
A[Push to main] --> B[Checkout code]
B --> C[Install deps]
C --> D[Run tests]
D --> E{Pass?}
E -->|Yes| F[Deploy]
E -->|No| G[Notify]
Useful Actions
# Cache dependencies
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
# Upload artifacts
- uses: actions/upload-artifact@v4
with:
name: build
path: dist/
Browse the GitHub Marketplace for thousands of community actions.