GitHub Actions Cheat Sheet
Workflow files, events, expressions, and the CLI — write and debug pipelines without leaving the terminal.
Triggers
7on: pushRun on every push
on: pull_requestRun on PR activity
on: workflow_dispatchManual trigger with inputs
on: schedule: [{ cron: '0 2 * * *' }]Cron schedule
on: push: { branches: [main], paths: ['src/**'] }Filter by branch and path
on: workflow_run: { workflows: ['CI'] }Chain after another workflow
on: repository_dispatch: { types: [deploy] }Trigger from the API
Key Syntax
12jobs.build.runs-on: ubuntu-latestChoose the runner
steps.use: actions/checkout@v4Pin by major version tag
steps.with: { node-version: '20' }Inputs to an action
env: { VAR: ${{ secrets.X }} }Secrets as env vars
permissions: { contents: read }Least-privilege GITHUB_TOKEN
strategy.matrix: { node: [18, 20] }Run a matrix
if: always()Run even after a failure
${{ github.actor }}The person who triggered the run
${{ github.ref_name }}Branch or tag name
${{ github.sha }}Commit SHA
${{ steps.build.outputs.artifact }}Output of a step
needs: [build, test]Job dependency
gh CLI
11gh workflow listAll workflows in the repo
gh workflow run NAME --ref BRANCHTrigger a workflow run
gh run list --limit 10Recent runs
gh run watchWatch the latest run live
gh run view RUN_ID --logFull log for a run
gh run download RUN_ID --name artifactsDownload artifacts
gh run rerun RUN_ID --failedRe-run only failed jobs
gh pr checks --watchPR status checks
gh actions listAll runs you have access to
gh secret set NAMESet an Actions secret
gh secret listList secret names
Artifacts & Cache
4actions/upload-artifact@v4 with path: distUpload an artifact
actions/download-artifact@v4Fetch an artifact
actions/cache@v4 with key: ${{ runner.os }}-npmCache dependencies between runs
actions/setup-node@v4 with cache: npmAuto-cached package manager