GitHub Actions Workflow Cheat Sheet
Quick reference guide for GitHub Actions: Workflow YAML syntax, matrix builds, custom secrets, and triggers.
CI/CD & DevOps
github-actions
cicd
yaml
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipelines.
Workflow File Location & Triggers (`on`)
Workflows are stored in .github/workflows/*.yml files.
yaml
name: CI & Test Suite
on:
push:
branches: [ main, "feature/*" ]
pull_request:
branches: [ main ]
workflow_dispatch: # Manual trigger button in GitHub UI
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Run Unit Tests
run: pnpm test
env:
API_KEY: ${{ secrets.API_KEY }}
Matrix Build Strategy
Run jobs concurrently across multiple Node.js versions or OS environments.
yaml
jobs:
matrix-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: pnpm test
Essential Context Expressions
Table
| Context Expression | Contains / Description |
|---|---|
${{ secrets.MY_TOKEN }} | Access encrypted repository or organization secret |
${{ env.MY_VARIABLE }} | Access environment variable defined in workflow |
${{ github.sha }} | Commit SHA that triggered the workflow run |
${{ github.ref }} | Branch or tag ref that triggered workflow (refs/heads/main) |
${{ runner.os }} | Operating system of runner executing job (Linux, Windows, macOS) |
Common Pitfalls & Tips
[!WARNING] Forked pull requests cannot access encrypted
${{ secrets.* }}by default for security protection against malicious PR code execution.
[!TIP] Use
actions/cache@v4or package-manager-native caching inactions/setup-nodeto speed up dependency installation times significantly.