🐙 Reading GitHub Actions YAML
5 exercises — read a real GitHub Actions workflow. Understand on triggers, jobs, steps, uses vs run, the build matrix, needs and env scope.
GitHub Actions quick reference
on:→ events that trigger the runjobs:→ run in parallel unless linked byneeds:uses:→ a reusable action ·run:→ a shell commandstrategy.matrix→ fans one job out into many parallel runs${{ ... }}→ expression / variable interpolation
0 / 5 completed
1 / 5
.github/workflows/tests.yml
name: Tests
on:
push:
branches: [main]
pull_request:
env:
CI: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- name: Set up Node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh What does the
on: block at the top of the workflow define?on: declares the triggers.It lists the events that cause GitHub Actions to start this workflow. Here there are two:
pushto themainbranch- any
pull_request(no branch filter, so PRs targeting any branch)
schedule (cron), workflow_dispatch (manual "Run workflow" button), release, and issues.Don't confuse it with:
jobs: (the work to do), runs-on: (the runner OS), and env: (variables). Each answers a different question — when vs what vs where vs with which values.Collocations: "trigger the workflow on push", "the workflow is triggered by a pull request", "a scheduled trigger", "manually dispatch the workflow".
Next up: Reading JSON Config →