GitHub Actions Cheat Sheet: Triggers, Matrix, Expressions and Security
Checked against GitHub Actions docs.github.com and GitHub changelog as of 28 Nov 2026 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for people who already have a workflow or two and keep looking up the same keys. It follows the GitHub Actions docs and changelog as they stood on 28 Nov 2026, including the new workflow lockfiles and the pull_request_target change. GitHub Actions is a hosted service, so the rows are checked against the docs rather than run here.
When to use what
Pick the trigger by who you trust. pull_request runs fork code without your secrets, which is what you want for CI. pull_request_target runs in the base repository with secrets and write access, so only use it for jobs that never check out the PR's code, such as labelling. workflow_dispatch gives you a manual button, and schedule covers nightly jobs.
Split work into jobs when steps can run on different machines in parallel, and use needs when one job depends on another's output. A matrix is the right tool for the same steps over several versions or operating systems; a reusable workflow (workflow_call) is better when several repositories share a pipeline. The workflow generator drafts a starting file, and our GitHub Actions guide and advanced patterns guide walk through bigger setups.
For security, set permissions at the top of every workflow, starting from contents: read, and widen it per job. Then lock your actions. GitHub's own hardening page now calls a workflow lockfile the strongest option and SHA pinning the fallback; tags are only safe if you trust the author. The security auditor flags unpinned actions and risky triggers, and the expression evaluator helps when an if: doesn't do what you think.
on: { push: { branches: [main] } }Run on pushes to main; you can't use branches and branches-ignore on the same event.
branches: ['releases/**', '!releases/**-alpha']Include then exclude with !; a negative pattern needs at least one positive pattern before it.
schedule: [{ cron: '30 5 * * 1-5', timezone: 'America/New_York' }]Run at 5:30 local time on weekdays; without timezone cron is UTC.
every 5 minutesShortest allowed schedule interval; scheduled runs use the latest commit on the default branch.
60 daysIn a public repo, scheduled workflows are disabled after 60 days without repository activity.
workflow_dispatch:Adds a Run workflow button and API trigger, with optional typed inputs.
pull_request_target:Runs with the base repo's secrets and token; never check out and run PR code from it.
needs: [build, test]Wait for these jobs to succeed before starting; their outputs become needs.<job>.outputs.
echo "name=value" >> "$GITHUB_OUTPUT"Set a step output that a job output can expose to later jobs.
strategy.matrix: { node: [20, 22], os: [ubuntu-latest, windows-latest] }Run the job once per combination; a matrix tops out at 256 jobs per workflow run.
strategy.fail-fast: falseKeep other matrix jobs running when one fails; the default true cancels them.
strategy.max-parallel: 2Cap how many matrix jobs run at the same time.
matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}Build the matrix dynamically from a JSON string produced by an earlier job.
Every if: gets an implicit success() unless it already contains a status function.
if: ${{ failure() }}Run this step only when an earlier step failed; add other conditions with &&.
if: ${{ always() }}Run even after failure or cancellation, for cleanup and uploading logs.
contains(fromJSON('["push", "pull_request"]'), github.event_name)Shorter than chaining || comparisons against a list of event names.
contains(github.event.issue.labels.*.name, 'bug')Object filter .* collects a field from every array item, here label names.
hashFiles('**/package-lock.json')Hash of matching files, used to build cache keys that change with the lockfile.
format('{0}-{1}', runner.os, github.ref_name)Fill numbered placeholders; double braces {{ print a literal brace.
Token lifetime and recursion rules are on the GITHUB_TOKEN page.
permissions: { contents: read }Least-privilege default for the whole workflow; any scope you don't list becomes none.
permissions: { id-token: write }Needed to request an OIDC token for cloud login without stored keys.
permissions: read-allRead access to every scope; write-all exists too but is rarely what you want.
${{ secrets.GITHUB_TOKEN }}Per-job token that expires when the job ends; self-hosted jobs past 24 hours need another credential.
push with GITHUB_TOKENDoesn't start new workflow runs, which prevents loops; PRs it opens create runs that need approval.
secrets: inheritPass all the caller's secrets to a reusable workflow instead of naming each one.
Concurrency rules come from the concurrency how-to.
concurrency: { group: ${{ github.workflow }}-${{ github.ref }}, cancel-in-progress: true }One run per workflow and branch; a new push cancels the one in progress.
concurrency.queue: maxKeep up to 100 pending runs instead of replacing the single pending one.
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}Exact-match cache key, max 512 characters; a cache can't be changed once saved.
restore-keys: |
${{ runner.os }}-npm-Fallback prefixes tried in order on a miss; the newest partial match is restored.
10 GB / 7 daysDefault repo cache limit, and entries unused for 7 days are evicted; admins can raise the limit.
on: workflow_call:Makes a workflow callable from others, with its own inputs and secrets.
uses: org/repo/.github/workflows/ci.yml@<sha>Call a reusable workflow at job level; pin it like an action.
secrets: { token: { required: true } }Fail the call if the caller doesn't pass the secret, instead of getting an empty string.
10 levelsMaximum nesting: the caller plus nine reusable workflows, with no loops; permissions can only shrink down the chain.
gh actions-lockGitHub CLI extension that writes .github/workflows/actions.lock with exact commits for actions and their dependencies.
uses: actions/checkout@<full 40-char SHA>Pin to a full commit SHA when you can't use a lockfile; check the SHA comes from the real repo, not a fork.
env: { TITLE: ${{ github.event.pull_request.title }} }Pass untrusted input through an env var and use "$TITLE" in the script, so it can't inject shell code.
workflow_runPreferred over pull_request_target when a privileged job must follow untrusted CI.
Worked example: A hardened CI workflow with a matrix, cache and cancel-on-push
Here is a test workflow for a Node project that runs on two Node versions, cancels stale runs on the same branch, and keeps the token read-only:
name: ci
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [20, 22]
steps:
- uses: actions/checkout@<full-commit-sha>
- uses: actions/setup-node@<full-commit-sha>
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test
- if: ${{ failure() }}
run: echo "Tests failed on Node ${{ matrix.node }}"
What each part buys you: permissions limits the token to reading code, so a compromised step can't push or open releases. The concurrency group is the workflow name plus the ref, so pushing twice to a branch cancels the older run but leaves other branches alone. fail-fast: false means a failure on Node 20 still lets Node 22 finish, which tells you whether the bug is version-specific. The last step only runs when something before it failed. Replace the SHA placeholders with real commit SHAs from each action's repository, or keep tags and generate a lockfile with gh actions-lock. I haven't run this file; in the Actions tab you should see two test jobs, one per Node version.
Common mistakes
Writing a cron for 9 AM local time and getting runs at the wrong hour.
Cron runs in UTC unless you set
timezonewith an IANA name such asEurope/Berlinnext to the cron line.Adding
if: github.ref == 'refs/heads/main'to a cleanup step and seeing it skip after a failure.The implicit
success()still applies. Writeif: ${{ always() && github.ref == 'refs/heads/main' }}.Interpolating
${{ github.event.pull_request.title }}straight into arun:script.That's script injection. Put the value in
env:and reference the shell variable in double quotes.Using
pull_request_targetwithactions/checkoutof the PR head to run tests on forks.That hands fork code your secrets. Use
pull_requestfor tests; in public repos the trigger is blocked by default from 2 Dec 2026 anyway.Expecting a commit pushed with
GITHUB_TOKENto start the next workflow.Pushes made with that token don't trigger runs. Use
workflow_dispatch,workflow_call, or a GitHub App token for chained work.Setting
permissions: { pull-requests: write }and then seeing checkout fail.Listing one scope sets all others to none. Add
contents: readalongside it.
Related cheat sheets
Sources
- https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
- https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows
- https://docs.github.com/en/actions/reference/workflows-and-actions/expressions
- https://docs.github.com/en/actions/reference/security/secure-use
- https://docs.github.com/en/actions/concepts/security/github_token
- https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching
- https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows
- https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency
- https://github.blog/changelog/2026-11-02-pull_request_target-blocked-by-default-december-2
- https://github.blog/changelog/2026-10-28-github-actions-workflow-lockfiles-are-generally-available
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.