---
name: Lint scripts
on:
  push:
    paths:
      - usr/lib/python3/dist-packages/stdisplay/**
      - usr/lib/python3/dist-packages/sanitize_string/**
      - usr/lib/python3/dist-packages/strip_markup/**
      - usr/lib/python3/dist-packages/unicode_show/**
      - .github/workflows/lint.yml
      - run-tests
  pull_request:
    paths:
      - usr/lib/python3/dist-packages/stdisplay/**
      - usr/lib/python3/dist-packages/sanitize_string/**
      - usr/lib/python3/dist-packages/strip_markup/**
      - usr/lib/python3/dist-packages/unicode_show/**
      - .github/workflows/lint.yml
      - run-tests

jobs:
  lint:
    runs-on: ubuntu-24.04

    strategy:
      fail-fast: false
      matrix:
        include:
          - image: debian:stable
          - image: debian:testing
          - image: debian:unstable
          ## Disabled because ubuntu:latest is currently 24.04, which uses a
          ## version of Python that does not support the `newline` argument of
          ## Path.read_text()
          # - image: ubuntu:latest
          - image: ubuntu:rolling

    container:
      image: ${{ matrix.image }}

    steps:
      - name: Install linters
        run: |
          apt-get update --error-on=any
          apt-get dist-upgrade -y
          apt-get install -y git python3-pytest pylint mypy black ncurses-term \
            build-essential debhelper dh-python dh-apparmor
          git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - uses: actions/checkout@v4
      - name: Test build
        run: |
          dpkg-buildpackage -b -i -us -uc
          apt-get install -y ../helper-scripts*.deb
      - name: Run linters
        run: |
          set -o xtrace
          git clone https://github.com/nickboucher/trojan-source ~/trojan-source
          ./run-tests
