Intermediate Reading #github-actions #yaml #ci-cd #devops

🐙 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 run
  • jobs: → run in parallel unless linked by needs:
  • uses: → a reusable action · run: → a shell command
  • strategy.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?