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 pushon:
push:
branches: [main]Only pushes to mainon: pull_requestRun on pull requestspaths: ['src/**']Only when matching files changeon:
schedule:
- cron: '0 6 * * 1'On a schedule (UTC)on: workflow_dispatchAdd a manual "Run workflow" buttonJobs and steps
jobs:
build:
runs-on: ubuntu-latestDefine a job and its runner- uses: actions/checkout@v4Use an action- run: npm ciRun a shell commandwith:
node-version: 22Pass inputs to an actionneeds: buildWait for another job to finishif: github.ref == 'refs/heads/main'Run a job or step conditionallytimeout-minutes: 15Fail a job that hangsMatrix
strategy:
matrix:
node: [20, 22]Run the job once per value${{ matrix.node }}Use the current matrix valuefail-fast: falseKeep other matrix jobs running when one failsSecrets, env, and outputs
${{ secrets.API_KEY }}Read a repository or environment secretenv:
NODE_ENV: productionEnvironment variables for a workflow, job, or stepecho "KEY=value" >> "$GITHUB_ENV"Set an env var for later stepsecho "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 cachingactions/upload-artifact@v4Save build output from a jobpermissions:
contents: readLimit the GITHUB_TOKEN to what the job needsconcurrency:
group: ${{ github.ref }}
cancel-in-progress: trueCancel older runs on the same branchuses: owner/action@<commit-sha>Pin third-party actions to a full commit SHA