Skip to content

/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

bash
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

ExpressionTrue 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

ValueContains
github.sha, github.ref, github.ref_namecommit, full ref, branch or tag name
github.eventthe full webhook payload
github.actoruser who triggered the run
secrets.NAME / vars.NAMErepository 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.temprunner 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