name: Processing Tools
on: [push]

jobs:

  pip:

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        python-version: ['3.8', '3.9', '3.10']
        os: [ubuntu-latest, macos-latest, windows-latest]
      fail-fast: false

    steps:
      - uses: actions/checkout@v3

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

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pytest pandas scipy h5py vtk matplotlib pyyaml build

      - name: Strip git hash (Unix)
        if: runner.os != 'Windows'
        run: |
          export VERSION=$(cat VERSION)
          echo ${VERSION%-*} > VERSION

      - name: Strip git hash (Windows)
        if: runner.os == 'Windows'
        run: |
          $VERSION = Get-Content VERSION -first 1
          $VERSION,$_ = $VERSION -Split '-g',2,"simplematch"
          $VERSION | Out-File VERSION

      - name: Build and Install
        run: |
          cd python
          python -m build
          python -m pip install dist/*.whl
          python -c 'import damask;print(damask.__version__)'

      - name: Install and run unit tests (Unix)
        if: runner.os != 'Windows'
        run: |
          python -m pip install ./python --no-deps -vv
          COLUMNS=256 pytest python

      - name: Install and run unit tests (Windows)
        if: runner.os == 'Windows'
        run: |
          python -m pip install ./python --no-deps -vv
          pytest python -k 'not XDMF'

  apt:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Install pytest
        run: |
          python -m pip install --upgrade pip
          pip install pytest

      - name: Install dependencies
        # https://github.com/actions/virtual-environments/issues/4790
        run: >
          sudo apt-get update &&
          sudo apt-get remove mysql* &&
          sudo apt-get install python3-pandas python3-scipy python3-h5py python3-vtk7 python3-matplotlib python3-yaml -y

      - name: Run unit tests
        run: |
          export PYTHONPATH=${PWD}/python
          COLUMNS=256 pytest python