Code Quality
GitHub Workflows

GitHub Workflows

As well as the pre-commit hooks, it's useful to also check the linting rules have been followed on GitHub.


Setup

Add file to the GitHub workflows directory at the root of the repo.

.github/workflows/linterys.yml

Example File

linters.yml
name: Linters
 
on:
  pull_request:
    paths-ignore:
      - 'docs/**'
  push:
    branches:
      - main
      - develop
    paths-ignore:
      - 'docs/**'
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
permissions:
  contents: read
 
jobs:
 
  isort:
    name: Check isort
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'
          cache: 'pip' # caching pip dependencies will speed up builds
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Install isort
        run: pip install isort
      - name: Run isort
        run: isort . --check-only --diff --profile black
 
  black:
    name: Check black
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: black
        uses: psf/black@stable
Last updated on 16 December 2023