Technical reference
GitHub Actions Cheatsheet
Automate tests, builds, and deployments
Must Know
yaml
Node CI
name: CI
on: [push, pull_request]
jobs:
test:
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 test
- run: npm run buildyaml
Events and Filters
on:
push:
branches: [main]
pull_request:
paths:
- 'src/**'
- 'package-lock.json'Important Patterns
yaml
Least-Permission Token
Set explicit permissions at workflow or job level.
permissions:
contents: read
pull-requests: writeyaml
Concurrency
Avoid overlapping deployments for the same target.
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: trueUseful Recipes
yaml
Matrix Tests
strategy:
matrix:
node: [20, 22]
steps:
- uses: actions/setup-node@v4
with: { node-version: '${{ matrix.node }}' }yaml
Artifacts
Store reports and build outputs with short retention.
- uses: actions/upload-artifact@v4
with:
name: test-report
path: reports/
retention-days: 7Pitfalls & Production
Supply-Chain Safety
Workflow changes can execute privileged code.
pin third-party actions to a commit SHA
protect deployment environments
use OIDC instead of long-lived cloud keysSecrets
Environment approvals can protect production secrets.
${{ secrets.API_TOKEN }}
# Never print secrets or pass them to untrusted PR code.