# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CI

on:
  push:
    branches: [ "*" ]
  pull_request:
    branches: [ master ]
  schedule:
    # Every Saturday at 4:30 AM UTC.
    - cron:  '30 4 * * 6'

jobs:
  build:

    runs-on: ubuntu-18.04
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.4, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12-dev', 'pypy3.9']

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip flake8
        if [ "${{ matrix.python-version }}" = "3.7" ]; then
          python -m pip install unicodedata2==12.0.0
        elif [ "${{ matrix.python-version }}" = "3.8" ]; then
          python -m pip install unicodedata2==14.0.0
        elif [ "${{ matrix.python-version }}" = "3.9" ]; then
          python -m pip install unicodedata2==10.0.0
        elif [ "${{ matrix.python-version }}" = "3.10" ]; then
          python -m pip install unicodedata2==15.0.0
        fi
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Run Tests
      run: |
        python -c "import unicodedata; print(unicodedata.unidata_version)"
        python -m unittest discover -v
        python -m doctest README.rst
    - name: Test source package
      run: ./tools/test_python_package.sh
    - name: Run Code Coverage (Python 3.9 only)
      if: matrix.python-version == '3.9'
      run: |
        python -m pip install codecov
        coverage run --source precis_i18n -m unittest test/test_precis.py test/test_codepointset.py test/test_codec.py test/test_factory.py
        codecov
    - name: Run mypy to check type stubs
      if: matrix.python-version != '3.4' && matrix.python-version != 'pypy3.9'
      run: |
        python -m pip install mypy
        mypy --strict precis_i18n
