AI Hints
Home›CI/CD with GitHub Actions Tutorial›Projects: CI and Delivery
CI/CD with GitHub Actions · Lesson 118 of 138

Project: Python CI

Putting it together.

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

Welcome to the projects. Each one combines what you've learned into a pipeline you could use for real. First, a complete CI pipeline for our Python shop.

Project: Python CI
From the video: Project: Python CI
  • Projects section
  • Combine everything
  • A real Python pipeline

The full workflow

It runs on pushes to main, and on pull requests. Concurrency cancels out of date runs for the same branch. A timeout stops stuck jobs. The matrix tests two Python versions, with pip caching. And four gates, install, lint, format, and tests with coverage.

.github/workflows/ci.ymlyaml
name: Python CI
on:
  push: { branches: [main] }
  pull_request:
concurrency: { group: "ci-${{ github.ref }}", cancel-in-progress: true }
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    strategy:
      matrix: { python: ["3.11", "3.12"] }
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "${{ matrix.python }}", cache: pip }
      - run: pip install -q -r requirements.txt
      - run: flake8
      - run: black --check -q .
      - run: pytest -q --cov=app --cov-fail-under=90

Green, then red

Our helper runs both matrix jobs, and both succeed. Now a teammate adds an unused import. The lint step fails in both jobs, with the exact line, and the later steps never run. That's the pipeline doing its job.

Terminal
run-steps .github/workflows/ci.yml | grep -E "^Job|succeeded|failed"
Job: test (3.11)
  Job succeeded
Job: test (3.12)
  Job succeeded
sed -i '1i import os' app.py
run-steps .github/workflows/ci.yml | grep -E "^Job|✗|F401|failed"
Job: test (3.11)
  ✗ Run flake8
      ./app.py:1:1: F401 'os' imported but unused
  Job failed
Job: test (3.12)
  ✗ Run flake8
      ./app.py:1:1: F401 'os' imported but unused
  Job failed

Summary

A full Python pipeline has triggers, concurrency, timeouts, a matrix, caching, and four quality gates. Next, the same for Node.

Key takeaways
  • Matrix + cache
  • Lint, format, test
  • Concurrency + timeout
Next up: Project: Node CI — the JavaScript version