AI Hints
Home›CI/CD with GitHub Actions Tutorial›Reviews, Flaky Tests, and Gates
CI/CD with GitHub Actions · Lesson 75 of 138

Practice: A Quality Gate

Lint, format, test.

⏱ 2 min read▶ Video at 1:25:55🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Practice time. Build a quality gate workflow. One job lints. Another checks formatting and runs the tests with coverage. And a final gate job runs only when both pass, so branch protection can require just that one check.

Practice: A Quality Gate
From the video: Practice: A Quality Gate
  • Lint job
  • Test job
  • One gate job

One answer

The lint job runs flake8. The test job checks formatting with black, then runs pytest with a coverage minimum of ninety percent. The gate job needs both, so it only runs if both succeed. In the repository rules, you'd mark gate as the required check.

.github/workflows/gate.ymlyaml
name: Quality gate
on: [push, pull_request]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: flake8
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: black --check -q .
      - run: pytest -q --cov=app --cov-fail-under=90
  gate:
    needs: [lint, test]
    runs-on: ubuntu-latest
    steps:
      - run: echo "All quality checks passed"

Running it

Our helper runs lint and test, and then the gate. Flake8 and black are quiet, and the three tests pass with enough coverage. Every job succeeds, and the gate prints its message.

Terminal
run-steps .github/workflows/gate.yml | grep -E "^Job|✓|✗|passed|succeeded|failed"
Job: lint
  ✓ Run flake8
  Job succeeded
Job: test
  ✓ Run black --check -q .
  ✓ Run pytest -q --cov=app --cov-fail-under=90
      3 passed in 0.02s
  Job succeeded
Job: gate
  ✓ Run echo "All quality checks passed"
      All quality checks passed
  Job succeeded

Summary

A gate job that needs all the others gives branch protection one stable check to require. Next, practice fixing a red build.

Key takeaways
  • Separate jobs
  • needs: [lint, test]
  • Require only the gate
Next up: Practice: Fix the Red Build — read, find, fix