elefcode
← All cheat sheets

Tools

GitHub Actions Cheat Sheet — Workflow Syntax Reference

The workflow syntax for GitHub Actions in one place. Workflows live in .github/workflows/*.yml.

Put it into practice with the matching tool.

Build a cron schedule →

Advertisement

Triggers

on: pushRun on every push
on: push: branches: [main]Only pushes to main
on: pull_requestRun on pull requests
paths: ['src/**']Only when matching files change
on: schedule: - cron: '0 6 * * 1'On a schedule (UTC)
on: workflow_dispatchAdd a manual "Run workflow" button

Jobs and steps

jobs: build: runs-on: ubuntu-latestDefine a job and its runner
- uses: actions/checkout@v4Use an action
- run: npm ciRun a shell command
with: node-version: 22Pass inputs to an action
needs: buildWait for another job to finish
if: github.ref == 'refs/heads/main'Run a job or step conditionally
timeout-minutes: 15Fail a job that hangs

Matrix

strategy: matrix: node: [20, 22]Run the job once per value
${{ matrix.node }}Use the current matrix value
fail-fast: falseKeep other matrix jobs running when one fails

Secrets, env, and outputs

${{ secrets.API_KEY }}Read a repository or environment secret
env: NODE_ENV: productionEnvironment variables for a workflow, job, or step
echo "KEY=value" >> "$GITHUB_ENV"Set an env var for later steps
echo "tag=v1" >> "$GITHUB_OUTPUT"Set a step output
${{ steps.meta.outputs.tag }}Read a step output (the step needs an id)

Caching, artifacts, and safety

actions/setup-node@v4 with cache: npmBuilt-in dependency caching
actions/upload-artifact@v4Save build output from a job
permissions: contents: readLimit the GITHUB_TOKEN to what the job needs
concurrency: group: ${{ github.ref }} cancel-in-progress: trueCancel older runs on the same branch
uses: owner/action@<commit-sha>Pin third-party actions to a full commit SHA

Related guides

More cheat sheets