name: Tests

on:
  # Trigger the workflow on push or pull request, but only for the develop branch
  push:
    branches:
      - develop
  pull_request:
    branches:
      - develop

jobs:
  test_linux:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # Test oldest and latest supported python version
        # Python 3.6 not supported in test environment after ubuntu-20.04
        python-version: ["3.6", "3.11"]
        include:
          - python-version: "3.6"
            os: ubuntu-20.04
          - python-version: "3.11"
            os: ubuntu-latest

    name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64

      - name: Install Ubuntu system dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -qq -y gir1.2-gtk-3.0 gobject-introspection libgirepository1.0-dev xvfb

      - name: Install Python dependencies
        run: |
          pip install PyGObject
          pip install pyxdg
          pip install setuptools

      - name: Configure git
        run: |
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"

      - name: Test ${{ matrix.os }}
        run: xvfb-run ./test.py


  test_macos:
    runs-on: macos-14
    name: Python 3.11 on macos-14
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Configure git
        run: |
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"

      - name: Install dependencies
        run: |
          brew install pygobject3 gtk+3 python@3.11

      # FIXME: this needs to be investigated
      - name: Disable TestPlugins() as they segfault
        run: |
          sed -i '' 's/TestPlugins(tests.TestCase)/TestPlugins()/g' tests/plugins.py

      # FIXME: What needs to be done for Python to pick Homebrew's sqlite3 that has FTS support?
      - name: Disable TestIndexedFTS() as not getting correct sqlite3 to work
        run: |
          sed -i '' 's/TestIndexedFTS(tests.TestCase)/TestIndexedFTS()/g' tests/indexed_fts.py

      - name: Run test suite
        run: |
          /opt/homebrew/opt/python@3.11/libexec/bin/python test.py



  test_windows:
    runs-on: windows-latest
    strategy:
      fail-fast: false

    name: MSYS2 Python 3.x on windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install MSYS2
        uses: msys2/setup-msys2@v2

      - name: Install system dependencies
        shell: msys2 {0}
        run: |
          pacman -S --noconfirm git mingw-w64-x86_64-gtk3 mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-gobject mingw-w64-x86_64-python-xdg mingw-w64-x86_64-python-setuptools

      - name: Configure git
        shell: msys2 {0}
        run: |
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"

      - name: Test Windows
        shell: msys2 {0}
        run: python ./test.py
