# This workflow targets stable released dependencies from EDM.
# Note that some packages may not actually be installed from EDM but from
# PyPI, see etstool.py implementations.

name: Test with EDM

on: [pull_request, workflow_dispatch]

env:
  INSTALL_EDM_VERSION: 3.4.0
  QT_MAC_WANTS_LAYER: 1

jobs:

  # Test against EDM packages
  test-with-edm:
    strategy:
      matrix:
        os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
        runtime: ['3.8']
        toolkit: ['null', 'pyside6']

    runs-on: ${{ matrix.os }}
    steps:
      - name: Clone the Envisage source
        uses: actions/checkout@v4
      - name: Install packages for Qt support
        uses: ./.github/actions/install-qt-support
      - name: Cache EDM packages
        uses: actions/cache@v4
        with:
          path: ~/.cache
          key: ${{ runner.os }}-${{ matrix.runtime }}-${{ matrix.toolkit }}-${{ hashFiles('etstool.py') }}
      - name: Set up EDM
        uses: enthought/setup-edm-action@v4
        with:
          edm-version: ${{ env.INSTALL_EDM_VERSION }}
      - name: Set up bootstrap Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'
          cache: 'pip'
          cache-dependency-path: '.github/workflows/bootstrap-requirements.txt'
      - name: Install click to the bootstrap environment
        run: python -m pip install -r .github/workflows/bootstrap-requirements.txt
      - name: Install test environment
        run: python etstool.py install --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }}
      - name: Run tests (Ubuntu)
        if: matrix.os == 'ubuntu-latest'
        run: xvfb-run -a python etstool.py test --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }}
      - name: Run tests (not Ubuntu)
        if: matrix.os != 'ubuntu-latest'
        run: python etstool.py test --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }}
