name: dali-tests

# never run automatically since it needs gpus
on:
  push:
    branches-ignore:
      - '**'

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

    steps:
      - uses: actions/checkout@v3

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

      - name: Cache Python dependencies
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-${{ matrix.python }}-pip-${{ hashFiles('**/setup.py') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.python }}-pip-

      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install .[dali,umap,h5] --extra-index-url https://developer.download.nvidia.com/compute/redist codecov
          pip install mypy pytest-cov black

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

      - name: pytest
        run: pytest --cov=solo tests/dali

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

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