name: pr-type-lint-spell

on:
  pull_request:
    branches:
      - master
      - 2.3.X

jobs:

  check-typing:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        python-version: [ '3.6', '3.10' ]

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install typing dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install mypy==0.971
        python -m pip install -U types-requests types-pkg_resources types-setuptools

    - name: Run typing check with mypy
      run: |
        mypy

  code-linting:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version:  ['3.10']
    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Get pip cache dir
      id: pip-cache
      run: |
        echo "::set-output name=dir::$(pip cache dir)"
    - name: pip cache
      uses: actions/cache@v2
      with:
        path: ${{ steps.pip-cache.outputs.dir }}
        key: py${{ matrix.python-version }}-${{ matrix.os }}-pip

    - name: Get files changed
      id: diff-files
      uses: trilom/file-changes-action@v1.2.4
      with:
        output: '\n'
        fileOutput: '\n'

    - name: Get .py files changed
      id: pydiff
      run: >
        echo "::set-output name=pyfiles::$(echo -e
        '${{ steps.diff-files.outputs.files_added }}\n${{ steps.diff-files.outputs.files_modified }}'
        | grep '\.py' | tr '\n' ' '
        )"

    - name: Install linter
      run: python -m pip install flake8

    - name: Syntax errors check
      run: python -m flake8 --select=E901,E999,F821,F822,F823 ${{ steps.pydiff.outputs.pyfiles }}

    - name: Style warnings
      run: python -m flake8 --exit-zero ${{ steps.pydiff.outputs.pyfiles }}

  check-spelling:
    name: Check for spelling errors
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: codespell-project/actions-codespell@master
