/cheatsheets/github-actions/github-actions-cheat-sheet
GitHub Actions cheat sheet: triggers, jobs, matrix, outputs and caching
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · 1.7.12updated 2026-10-20
- tool
- GitHub Actions
- versions
- GitHub Actions
- os
- any
The workflow syntax used most, in one file. Every snippet below is part of a workflow that passes actionlint.
A complete workflow
mkdir -p .github/workflows
cat > .github/workflows/ci.yml <<'EOF'
name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
workflow_dispatch:
inputs:
debug:
type: boolean
default: false
schedule:
- cron: "0 3 * * 1"
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
node: [22, 24]
outputs:
version: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test
- id: meta
run: echo "version=$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
if: failure()
with:
name: logs-${{ matrix.os }}-${{ matrix.node }}
path: logs/
release:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- run: echo "releasing ${{ needs.test.outputs.version }}"
env:
GH_TOKEN: ${{ github.token }}
EOF
actionlint -no-color .github/workflows/ci.yml && echo "actionlint: no problems"Output
actionlint: no problems
Conditions
| Expression | True when |
|---|---|
| if: github.event_name == 'pull_request' | the run was triggered by a PR |
| if: github.ref == 'refs/heads/main' | on the main branch |
| if: success() / failure() / always() / cancelled() | status of earlier steps or needed jobs |
| if: contains(github.event.head_commit.message, '[skip e2e]') | commit message contains a marker |
| if: runner.os == 'Windows' | on a Windows runner |
Contexts
| Value | Contains |
|---|---|
| github.sha, github.ref, github.ref_name | commit, full ref, branch or tag name |
| github.event | the full webhook payload |
| github.actor | user who triggered the run |
| secrets.NAME / vars.NAME | repository or environment secrets and variables |
| steps.<id>.outputs.<name> | output of an earlier step in the same job |
| needs.<job>.outputs.<name> | output of a job this job needs |
| matrix.<key> | the current matrix values |
| runner.os, runner.temp | runner OS and temp directory |
Files the runner provides
$GITHUB_OUTPUT (step outputs), $GITHUB_ENV (variables for later steps), $GITHUB_PATH (PATH entries), $GITHUB_STEP_SUMMARY (Markdown shown on the run page).
Sources
- docs.github.comdocs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions
- docs.github.comdocs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs
- docs.github.comdocs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions
Related pages
commands · github-actionsactionlint: lint GitHub Actions workflows before you pushactionlint checks .github/workflows files for syntax errors, bad expressions, untrusted input in run scripts, deprecated commands and outdated actions.config · github-actionsGitHub Actions concurrency: cancel-in-progress for older runsconcurrency with a group per workflow and branch plus cancel-in-progress: true cancels the older run when a new commit is pushed to the same branch or PR.flags · github-actionsGitHub Actions shell: bash vs the default: -e and pipefailWithout shell:, Linux run steps use bash -e and miss failures inside pipelines. shell: bash runs bash --noprofile --norc -eo pipefail and catches them.