GitHub Actions workflow
Before writing
Detect the stack and the real commands from the repo (manifest scripts, Makefile, tox/nox, existing CI). Use the same commands developers run locally.
Template (adapt, do not paste blindly)
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read # least privilege by default; widen per job only if needed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # stop superseded runs on the same branch/PR
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
node: [22, 24]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test
Check the latest major versions of actions/checkout, actions/setup-node, actions/setup-python etc. on their GitHub release pages before writing; do not guess.
Rules
- Permissions: set
permissionsat the top level to the minimum. Jobs that comment on PRs needpull-requests: write; publishing needscontents: writeorid-token: writefor OIDC. - Pin third-party actions to a full commit SHA (with the version in a comment). First-party
actions/*on a major tag is a common, acceptable trade-off. - Never echo secrets, and never pass secrets to workflows triggered by
pull_request_targetthat check out untrusted PR code. - Untrusted input: do not interpolate
${{ github.event.issue.title }}or other user-controlled fields directly intorun:scripts; pass them throughenv:and quote them, to avoid script injection. - Caching: use the setup action's built-in
cache:option before reaching foractions/cache. - Speed: split lint/typecheck/test into parallel jobs only when each takes more than a minute; otherwise the setup overhead dominates.
- Timeouts: always set
timeout-minutesso hung jobs do not burn minutes.
When fixing a failing workflow
- Get the logs:
gh run list --limit 5, thengh run view <id> --log-failed. - Reproduce the failing command locally if possible.
- Fix the cause, not the symptom (do not add
continue-on-errorto make it green). - Validate syntax with
actionlintif available.