name: Testing

on:
  push:
    branches:
      - main
    tags:
      - "v*"
  pull_request:
    branches:
      - main

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.11"]

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: "pip"
          cache-dependency-path: "**/pyproject.toml"
      - name: Install webdriver
        run: sudo apt-get update && sudo apt-get install chromium-chromedriver
      - name: Install dependencies
        run: |
          python${{ matrix.python-version }} -m pip install --upgrade pip packaging wheel cython setuptools
          python${{ matrix.python-version }} -m pip install `grep numpy== requirements/ubuntu-latest_py${{ matrix.python-version }}_extras.txt`
          python${{ matrix.python-version }} -m pip install -r requirements/ubuntu-latest_py${{ matrix.python-version }}_extras.txt
          python${{ matrix.python-version }} -m pip install --upgrade pip
          python${{ matrix.python-version }} -m pip install --no-deps .[server,test]
      - name: Test modules
        run: python${{ matrix.python-version }} -m pytest --cov=crystal_toolkit --cov-report=xml tests
      - name: Test example apps
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
        run: python${{ matrix.python-version }} -m pytest --cov=crystal_toolkit --cov-report=xml --color=yes --webdriver Chrome --headless crystal_toolkit/apps/examples/tests/
      - uses: codecov/codecov-action@v1
        if: matrix.python-version == 3.11
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          file: ./coverage.xml
