GitHub Actions Syntax Cheat Sheet: Workflows, Jobs, Matrix and Secrets
· Editorial team · 2 min read
cheatsheetgithub-actionsci-cddevops
A complete example
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- run: ./deploy.sh
env:
API_TOKEN: ${{ secrets.API_TOKEN }}Key sections
| Key | Purpose | |---|---| | `on` | Triggers: `push`, `pull_request`, `schedule` (cron), `workflow_dispatch`, `workflow_call` | | `permissions` | Limit the `GITHUB_TOKEN`; start with `contents: read` | | `jobs.<id>.runs-on` | Runner label such as `ubuntu-latest`, `windows-latest` | | `needs` | Job dependencies | | `if` | Conditional job or step | | `strategy.matrix` | Run the job across combinations | | `env` | Environment variables (workflow, job or step level) | | `environment` | Deployment target with protection rules and secrets | | `concurrency` | Prevent overlapping runs | | `timeout-minutes` | Stop hung jobs |
Expressions and contexts
| Expression | Value | |---|---| | `${{ github.sha }}` | Commit SHA | | `${{ github.ref_name }}` | Branch or tag name | | `${{ github.event_name }}` | Trigger event | | `${{ secrets.NAME }}` | Secret value (masked in logs) | | `${{ vars.NAME }}` | Repository or org variable | | `${{ runner.os }}` | Runner OS | | `${{ steps.id.outputs.key }}` | Output of an earlier step |
Step outputs and caching
- id: ver
run: echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT"
- run: echo "Building ${{ steps.ver.outputs.version }}"
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('**/requirements.txt') }}Reusable workflow
Stop spending an hour tailoring each resume — get a tailored resume and cover letter for this job in seconds.
Tailor my resumeEditorial team
Writes practical guides for Indian job seekers. Part of the HireStraight editorial team. Subscribe via RSS.