name: tests

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

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        os: [ubuntu-20.04]

    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v3
    - name: Setup Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    - name: Create and start a virtual environment
      run: |
        python -m venv general_venv --clear 
        source general_venv/bin/activate
    - name: Install dependencies
      run: |
        source general_venv/bin/activate
        pip install --upgrade pip
        export SDK_PATH=/opt/gc/poplar_sdk-ubuntu_20_04-3.3*
        pip install ${SDK_PATH}/poptorch-*.whl
        pip install .[testing]
    - name: Test with Pytest
      env:
        POPTORCH_WAIT_FOR_IPU: 1
      run: |
        source general_venv/bin/activate
        export SDK_PATH=/opt/gc/poplar_sdk-ubuntu_20_04-3.3*
        . ${SDK_PATH}/poplar-ubuntu_20_04*/enable.sh
        . ${SDK_PATH}/popart-ubuntu_20_04*/enable.sh
        pytest tests/ -v -n 16 --ignore=tests/pipelines/ --ignore=tests/test_examples_match_transformers.py
        pytest tests/test_examples_match_transformers.py -v
    - name: Upload PopTorch error log if present
      if: always()
      uses: actions/upload-artifact@v3
      with:
        name: poptorch_error
        path: poptorch_error.log
        if-no-files-found: ignore
