GitHub Actions Workflow & CI/CD Cheat Sheet
Production GitHub Actions cheat sheet: push/pull_request triggers, matrix builds, encrypted secrets, actions/cache@v4, and artifact uploads with 1-click copy.
Triggers & Events (4 commands)
on: [push, pull_request]
Triggers workflow execution on any Git push or pull request to the repository.
on:
workflow_dispatch:
inputs:
env: { description: "Target environment", required: true, default: "staging" }
Enables manual workflow triggering from GitHub Actions web UI with dropdown inputs.
on:
schedule:
- cron: "0 2 * * 1-5"
Runs workflow automatically on a scheduled crontab expression in UTC time.
on:
push:
paths:
- "src/**"
- "!src/**/*.test.ts"
Triggers workflow only when committed files match specific glob patterns.
Matrix & Runners (3 commands)
runs-on: ubuntu-latest
Executes job steps on GitHub-hosted Ubuntu Linux virtual machine runner.
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
os: [ubuntu-latest, windows-latest]
Spawns a multi-dimensional matrix of parallel runner combinations.
environment:
name: production
url: https://example.com
Binds workflow to a protected GitHub Environment requiring reviewer approval.
Steps & Caching (3 commands)
- uses: actions/checkout@v4
with:
fetch-depth: 0
Clones repository code into runner. fetch-depth: 0 retrieves full git commit history.
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
Provisions Node.js runtime and automatically restores ~/.npm dependency cache.
- uses: actions/cache@v4
with:
path: ~/.cache
key: ${{ runner.os }}-cache-${{ hashFiles("**/lock.json") }}
Caches custom directories across workflow runs using cryptographic file hash keys.
Secrets & Contexts (3 commands)
env:
API_KEY: ${{ secrets.PROD_API_KEY }}
APP_ENV: ${{ vars.DEPLOY_ENV }}
Injects encrypted repository secrets and plain configuration variables into environment.
if: github.ref == "refs/heads/main" && success()
Conditional step execution based on git branch and previous step exit statuses.
- uses: actions/upload-artifact@v4
with:
name: release-build
path: dist/
Uploads build artifacts (bundles, zip files, test reports) downloadable from the UI.