Skip to content
Latchkey

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:)

TriggerFires on
pushCommits pushed
pull_requestPR opened/updated
workflow_dispatchManual run (with inputs)
scheduleCron (UTC, default branch)
workflow_callCalled as reusable workflow
releaseRelease published

Common contexts

ContextExample
github.shaCommit SHA
github.ref_nameBranch/tag name
github.event_nameTriggering event
github.actorUser who triggered
runner.osLinux / Windows / macOS
secrets.NAMEA secret
env.NAMEAn 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

CommandUse
echo "X=1" >> $GITHUB_ENVSet env var for later steps
echo "k=v" >> $GITHUB_OUTPUTSet step output
echo "::group::Title"Collapsible log group
echo "::error::msg"Annotate an error

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →