GitHub Actions Cheat Sheet

Workflow files, events, expressions, and the CLI — write and debug pipelines without leaving the terminal.

CI/CD4 sections · 34 commands
⌘K

Triggers

7
on: push

Run on every push

on: pull_request

Run on PR activity

on: workflow_dispatch

Manual trigger with inputs

on: schedule: [{ cron: '0 2 * * *' }]

Cron schedule

on: push: { branches: [main], paths: ['src/**'] }

Filter by branch and path

on: workflow_run: { workflows: ['CI'] }

Chain after another workflow

on: repository_dispatch: { types: [deploy] }

Trigger from the API

Key Syntax

12
jobs.build.runs-on: ubuntu-latest

Choose the runner

steps.use: actions/checkout@v4

Pin by major version tag

steps.with: { node-version: '20' }

Inputs to an action

env: { VAR: ${{ secrets.X }} }

Secrets as env vars

permissions: { contents: read }

Least-privilege GITHUB_TOKEN

strategy.matrix: { node: [18, 20] }

Run a matrix

if: always()

Run even after a failure

${{ github.actor }}

The person who triggered the run

${{ github.ref_name }}

Branch or tag name

${{ github.sha }}

Commit SHA

${{ steps.build.outputs.artifact }}

Output of a step

needs: [build, test]

Job dependency

gh CLI

11
gh workflow list

All workflows in the repo

gh workflow run NAME --ref BRANCH

Trigger a workflow run

gh run list --limit 10

Recent runs

gh run watch

Watch the latest run live

gh run view RUN_ID --log

Full log for a run

gh run download RUN_ID --name artifacts

Download artifacts

gh run rerun RUN_ID --failed

Re-run only failed jobs

gh pr checks --watch

PR status checks

gh actions list

All runs you have access to

gh secret set NAME

Set an Actions secret

gh secret list

List secret names

Artifacts & Cache

4
actions/upload-artifact@v4 with path: dist

Upload an artifact

actions/download-artifact@v4

Fetch an artifact

actions/cache@v4 with key: ${{ runner.os }}-npm

Cache dependencies between runs

actions/setup-node@v4 with cache: npm

Auto-cached package manager