Skip to main content

GitHub Actions Cheatsheet

Quick reference for workflow structure, triggers, reusable workflows (workflow_call), caching, and secrets security in GitHub CI/CD.

Minimal CI Workflow (.github/workflows/ci.yml)​

name: CI

on:
pull_request:
branches: [main]
workflow_call:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build

Common Triggers (on:)​

on:
push:
branches: [main]
paths: ["docs/**", "src/**"] # Run only when matching paths change
pull_request:
types: [opened, edited, synchronize, reopened]
workflow_dispatch: # Allow manual runs from GitHub UI
inputs:
version:
description: "Version to deploy"
required: false
schedule:
- cron: "0 2 * * 1" # Scheduled run (UTC)
workflow_call: # Callable from another workflow

CI → Release → Deploy with Reusable Workflows​

Use workflow_call to chain pipelines without needing a Personal Access Token (PAT) when semantic-release pushes tags with GITHUB_TOKEN:

jobs:
ci:
uses: ./.github/workflows/ci.yml

release:
needs: ci
runs-on: ubuntu-latest
outputs:
released: ${{ steps.rel.outputs.released }}
steps:
- id: rel
run: echo "released=true" >> "$GITHUB_OUTPUT"

deploy:
needs: release
if: needs.release.outputs.released == 'true'
uses: ./.github/workflows/deploy.yml
secrets: inherit

Security & Best Practices​

  • Set least-privilege permissions at the workflow or job level.
  • Use GitHub Environments (for example, production or release) to scope deploy secrets and add branch/approval rules.
  • Cancel outdated runs on rapid pushes using concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

Watching Actions with gh​

gh run list -L 10 # List the 10 most recent runs
gh run watch <run-id> # Watch a run live in the terminal
gh run view <run-id> --log-failed # Show logs for failed steps
gh workflow run deploy.yml # Trigger workflow_dispatch manually

References​