name: CI

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
      - ci-*

env:
  HF_ALLOW_CODE_EVAL: 1

jobs:

  check_code_quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.8"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install .[quality]
      - name: Check quality
        run: |
          black --check --line-length 119 --target-version py36 tests src metrics comparisons measurements
          isort --check-only tests src metrics comparisons measurements
          flake8 tests src metrics

  test:
    needs: check_code_quality
    strategy:
      fail-fast: false
      matrix:
        test: ['unit', 'parity']
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: "3.8"
      - name: Upgrade pip
        run: python -m pip install --upgrade pip
      - name: Install dependencies
        run: |
          pip install .[tests]
          pip install -r additional-tests-requirements.txt --no-deps
      - name: Test with pytest
        if: ${{ matrix.test == 'unit' }}
        run: |
          python -m pytest -n 2 --dist loadfile -sv ./tests/ --ignore=./tests/test_trainer_evaluator_parity.py
      - name: Integration test with transformers
        if: ${{ matrix.test == 'parity' }}
        run: |
          python -m pytest -n 2 --dist loadfile -sv ./tests/test_trainer_evaluator_parity.py
