name: ci/build

on:
  push:
  pull_request:
    paths-ignore: 
      - docs/**
      - "**/README.md"

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.7", "3.8", "3.9"]
        backend: ["amd", "cpu"]
        include:
          - kbackend: "plaidml.keras.backend"
            backend: "amd"
          - kbackend: "tensorflow"
            backend: "cpu"
        exclude:
          - python-version: 3.9
            backend: amd
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}      
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
          cache-dependency-path: './requirements/requirements_${{ matrix.backend }}.txt'
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8 pylint mypy pytest wheel
          pip install -r ./requirements/requirements_${{ matrix.backend }}.txt
      - name: Lint with flake8
        run: |
          # stop the build if there are Python syntax errors or undefined names
          flake8 . --select=E9,F63,F7,F82 --show-source
          # exit-zero treats all errors as warnings.
          flake8 . --exit-zero
      - name: Simple Tests
        run: |
          if [ "${{ matrix.backend }}" == "amd" ] ; then echo "{\"PLAIDML_DEVICE_IDS\":[\"llvm_cpu.0\"],\"PLAIDML_EXPERIMENTAL\":true}" > ~/.plaidml; fi ;
          echo "{\"PLAIDML_DEVICE_IDS\":[\"llvm_cpu.0\"],\"PLAIDML_EXPERIMENTAL\":true}" > ~/.plaidml;
          FACESWAP_BACKEND="${{ matrix.backend }}" KERAS_BACKEND="${{ matrix.kbackend }}" py.test -v tests/;
      - name: End to End Tests
        run: |
          FACESWAP_BACKEND="${{ matrix.backend }}" KERAS_BACKEND="${{ matrix.kbackend }}" python tests/simple_tests.py;
          if [ "${{ matrix.backend }}" == "amd" ] ; then rm -f ~/.plaidml; fi ;
 