Ravindra BagaleCourses & study guides

Chapter 9: GitHub Actions Hands-On

9.2 Minimal workflow — test on pull request

# .github/workflows/ci.yml
name: badge API CI

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"
          cache: "pip"

      - name: Install deps
        run: pip install -r requirements.txt

      - name: Run tests
        run: pytest -q
Piece Meaning
on: Which GitHub events start this workflow
jobs.test One job named test
runs-on Runner image (GitHub-hosted example)
uses: Reuse a maintained action
run: Shell commands on the runner

Node variant sketch: actions/setup-node, npm ci, npm test — same job shape.

What you see: On a PR, the Checks tab shows badge API CI green or red. Click the job to read logs.

Steps — first green check

  1. In your badge API repo on GitHub, create .github/workflows/ci.yml with checkout + language setup + test command that matches your stack.
  2. Open a small PR (for example a README typo fix plus ensure tests exist).
  3. Watch the Actions tab / PR Checks until the job finishes.
  4. If red, open the log, fix locally, push again.
  5. Merge only when the check is green (and branch protection is on if your org allows it).

Ravindra Bagale's Tip

Khup students on: [push] everywhere thevtat aani heavy build every branch var chalavtat. PR sathi test; main sathi build/push — alag jobs/conditions. Lakshat theva!