name: PyDev.Debugger TESTS

on:
  - push
  - pull_request

env:
    DISPLAY: ":99"
    
jobs:
  build:
    runs-on: ${{ matrix.os }}
    
    strategy:
      fail-fast: false
      matrix:
        name: [
          "ubuntu-pypy3",
#           "macos-py37-cython", -- misbehaving on github actions
          "ubuntu-py38-cython-checkbin",
          "windows-py39-cython",
          "windows-py310-cython-checkbin",
          "windows-py311-cython",
          "ubuntu-py311-cython",
          "ubuntu-py312-cython-checkbin",
          "windows-py312-cython-checkbin",
          "ubuntu-py313-cython", 
          "windows-py313-cython",
          "ubuntu-py314-cython",
          "windows-py314-cython",
        ]
        
        include:
          - name: "ubuntu-pypy3"
            python: "pypy3.10"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: NO
#           - name: "macos-py37-cython"
#             python: "3.7"
#             os: macos-latest
#             PYDEVD_USE_CYTHON: YES
          - name: "ubuntu-py38-cython-checkbin"
            python: "3.8"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: YES
          - name: "windows-py39-cython"
            python: "3.9"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES
          - name: "windows-py310-cython-checkbin"
            python: "3.10"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES
          # See: https://github.com/actions/python-versions/releases
          - name: "windows-py311-cython"
            python: "3.11.0"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES
          - name: "ubuntu-py311-cython"
            python: "3.11.0"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: YES
          - name: "ubuntu-py312-cython-checkbin"
            python: "3.12.0"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: YES
          - name: "windows-py312-cython-checkbin"
            python: "3.12"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES
          - name: "ubuntu-py313-cython"
            python: "3.13"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: YES
          - name: "windows-py313-cython"
            python: "3.13"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES
          - name: "ubuntu-py314-cython"
            python: "3.14-dev"
            os: ubuntu-latest
            PYDEVD_USE_CYTHON: YES
          - name: "windows-py314-cython"
            python: "3.14-dev"
            os: windows-latest
            PYDEVD_USE_CYTHON: YES

    steps:
    - uses: actions/checkout@v1
    - name: Set up Python ${{ matrix.python }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python }}
    - name: Install gdb/xvfb/ptrace_scope
      run: |
        sudo apt-get update
        sudo apt-get install gdb
        sudo sysctl kernel.yama.ptrace_scope=0
        sudo apt-get install xvfb
        sudo apt-get install libqt5x11extras5
        Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &
      if: contains(matrix.name, 'ubuntu')
    - name: Install common Python deps
      run: |
        pip install --upgrade pip
        pip install setuptools --no-warn-script-location
        pip install wheel --no-warn-script-location
        pip install "cython>3" --no-warn-script-location
        pip install psutil --no-warn-script-location
        pip install numpy --no-warn-script-location
        pip install pytest --no-warn-script-location
        pip install pytest-xdist --no-warn-script-location
        pip install psutil --no-warn-script-location
        pip install ipython --no-warn-script-location
        pip install untangle --no-warn-script-location
        pip install importlib-metadata --no-warn-script-location
    - name: Install Python 3.x deps
      if: contains(matrix.name, 'py3') && !contains(matrix.name, 'pypy') && !contains(matrix.name, 'py312') && !contains(matrix.name, 'py311') && !contains(matrix.name, 'py313') && !contains(matrix.name, 'py314')
      run: |
        pip install PySide2 --no-warn-script-location
        pip install "numpy<2" --force --no-warn-script-location
        pip install cherrypy --no-warn-script-location
        pip install gevent==23.9.1 greenlet
        
    - name: Install django
      if: "!contains(matrix.name, 'py38')"
      run: pip install "django<=4.2" --no-warn-script-location
      
    - name: Install Pandas
      if: contains(matrix.name, 'py310') && !contains(matrix.name, 'pypy')
      # The pandas Styler also requires jinja2. 
      run: pip install pandas pyarrow jinja2 --no-warn-script-location
    - name: Install Pypy 3 deps
      if: contains(matrix.name, 'py3')
      run: |
        pip install trio
        
    - name: Check that wheels can be built
      if: contains(matrix.name, 'checkbin') && contains(matrix.name, 'ubuntu')
      run: |
        python -m pip install setuptools --no-warn-script-location
        python -m pip install cibuildwheel==2.21.3
        # Remove these .so files (will be rebuilt)
        rm pydevd_attach_to_process/*.so
        python -m cibuildwheel --output-dir wheelhouse
      env:
        CIBW_BUILD: cp310-*manylinux*x86_64 cp311-*manylinux*x86_64 cp312-*manylinux*x86_64 cp313-*manylinux*x86_64
        CIBW_BUILD_VERBOSITY: 3
        
    - name: Rebuild .so
      if: contains(matrix.name, 'checkbin') && contains(matrix.name, 'ubuntu')
      run: |
        pydevd_attach_to_process/linux_and_mac/compile_linux.sh
        
    - name: Check cython unchanged
      if: contains(matrix.name, 'checkbin')
      env:
        PYTHONPATH: .
      run: |
        python build_tools/build.py
        python build_tools/check_no_git_modifications.py

    - name: Create cython binaries
      if: contains(matrix.name, 'cython')
      run: |
        python setup_pydevd_cython.py build_ext --inplace
    - name: Check debug
      if: contains(matrix.name, 'checkdebug')
      run: |
        ./.github/install_and_run_debug_py.sh
    - name: Run Python 3.x tests
      env:
        # QT_DEBUG_PLUGINS: 1
        PYTHONPATH: .
        PYDEVD_USE_CYTHON: ${{matrix.PYDEVD_USE_CYTHON }}
      run: |
        python -m pytest -n auto -rfE

