name: tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        python: [3.8, 3.9, '3.10', 3.11]
        os: [ubuntu-latest, windows-latest]

    steps:
      - uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python }}
          cache: 'pip'

      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e .[umap,h5] codecov mypy pytest-cov black

      - name: Cache datasets
        uses: actions/cache@v3
        with:
          path: ~/datasets
          key: ${{ runner.os }}

      - name: pytest
        run: pytest --cov=solo tests/args tests/backbones tests/data tests/losses tests/methods tests/utils

      - name: Statistics
        if: success()
        run: |
          coverage report
          coverage xml

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3
        if: always()
        # see: https://github.com/actions/toolkit/issues/399
        continue-on-error: true
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          file: coverage.xml
          flags: cpu
          name: Coverage
          fail_ci_if_error: false
