How to use Ruff, Mypy, Black, Isort and Pytest in GitHub Actions?


Python’s not the strictest language, so to have any confidence in your code it needs to be hit with a barrage of checks to ensure it meets some level of quality.

I use the following code quality checks:

The following Github Actions workflow will check your code when a pull request is created, catching problems before they’re merged.

How to add the Github Actions workflow

Add the following to your repository in .github/workflows/code-quality.yml.

name: Code Quality
on: [pull_request]

    runs-on: ubuntu-latest
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
        python-version: "3.7"
    - run: pip install --upgrade pip
    - run: pip install "ruff<1" "mypy<2" "black<23" "isort<6" pytest
    - run: ruff check .
    - run: mypy --strict .
    - run: black --check .
    - run: isort --check --profile black .
    - run: pytest .


See also: How to use Ruff, Mypy, Black and Isort in Pre-commit?