Skip to content
All Guides
🐍

Python CI/CD with GitHub Actions

Set up CI for Python projects with pytest, Ruff linting, and pip caching.

.github/workflows/ci.yml
name: Python CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.11", "3.12"]

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip

      - run: pip install -r requirements.txt

      - name: Lint with Ruff
        run: |
          pip install ruff
          ruff check .

      - name: Test with pytest
        run: |
          pip install pytest pytest-cov
          pytest --cov=src --cov-report=xml

      - name: Upload coverage
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml

Setup Steps

  1. 1Create .github/workflows/ci.yml with the workflow above
  2. 2Tests run against Python 3.11 and 3.12 in a matrix
  3. 3Pip packages are cached for faster subsequent runs
  4. 4Ruff lints your code (fast alternative to flake8 + isort + pyupgrade)
  5. 5pytest runs with coverage reporting, uploaded to Codecov
Common Pitfalls
  • Missing requirements.txt — use 'pip freeze > requirements.txt' or use pyproject.toml with pip install .
  • Python version mismatch — use the matrix to test against multiple versions
  • Virtual environments — CI runners don't need venvs, install directly
Pro Tips
  • Use Ruff instead of flake8 — it's 10-100x faster and replaces multiple tools
  • Add 'cache: pip' to setup-python for faster installs
  • Use pytest-xdist for parallel test execution: 'pytest -n auto'
Automate This

CI setup done? WarpFix watches your pipeline 24/7 and auto-fixes failures — so you can ship faster.

WarpFix monitors your GitHub repos 24/7. When CI fails, it identifies the error, generates a fix, validates it in a sandbox, and opens a PR — automatically.

Install WarpFix — Free