GitHub Actions Cheat Sheet: Syntax, Contexts & Commands
The GitHub Actions syntax you reach for constantly, in one place.
Quick reference for workflow triggers, contexts, expressions, and the common patterns. Bookmark it.
Triggers (on:)
| Trigger | Fires on |
|---|---|
| push | Commits pushed |
| pull_request | PR opened/updated |
| workflow_dispatch | Manual run (with inputs) |
| schedule | Cron (UTC, default branch) |
| workflow_call | Called as reusable workflow |
| release | Release published |
Common contexts
| Context | Example |
|---|---|
| github.sha | Commit SHA |
| github.ref_name | Branch/tag name |
| github.event_name | Triggering event |
| github.actor | User who triggered |
| runner.os | Linux / Windows / macOS |
| secrets.NAME | A secret |
| env.NAME | An env var |
Expressions
expressions
if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ success() }} # default
if: ${{ failure() }}
if: ${{ always() }}
key: ${{ hashFiles('**/package-lock.json') }}Caching & matrix
.github/workflows/ci.yml
strategy:
matrix:
node: [18, 20, 22]
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: npm-Workflow commands
| Command | Use |
|---|---|
| echo "X=1" >> $GITHUB_ENV | Set env var for later steps |
| echo "k=v" >> $GITHUB_OUTPUT | Set step output |
| echo "::group::Title" | Collapsible log group |
| echo "::error::msg" | Annotate an error |
Related guides
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
actions/cache: Keys, Restore Keys & Best PracticesReference for actions/cache - how cache keys and restore-keys work, what to cache per ecosystem, and how to a…
GitHub Actions Cron Schedule BuilderBuild a GitHub Actions schedule cron expression visually and copy the ready-to-paste on: schedule YAML. Runs…