name: CI - EigenPy for Mac OS X/Linux via Conda

on: [push,pull_request]

jobs:
  eigenpy-conda:
    name: CI on ${{ matrix.os }} via Conda
    runs-on: ${{ matrix.os }}
    env:
      CCACHE_DIR: /github/home/.ccache # Enable ccache

    strategy:
      fail-fast: false
      matrix:
        os: ["ubuntu-latest", "macos-latest"]

    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive

    - uses: conda-incubator/setup-miniconda@v2
      with:
        activate-environment: eigenpy
        auto-update-conda: true
        environment-file: .github/workflows/conda/environment.yml
        python-version: 3.8

    - uses: actions/cache@v2
      with:
        path: ${{ env.CCACHE_DIR }}
        key: ccache-${{ matrix.os }}

    - name: Install cmake and update conda
      shell: bash -l {0}
      run: |
        conda activate eigenpy
        conda install cmake -c main

    - name: Build EigenPy
      shell: bash -l {0}
      run: |
        conda activate eigenpy
        echo $CONDA_PREFIX

        mkdir build
        cd build

        cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=$(which python3) -DGENERATE_PYTHON_STUBS=ON
        make
        make build_tests
        export CTEST_OUTPUT_ON_FAILURE=1
        make test
        make install

    - name: Configure hpp-fcl
        shell: bash -l {0}
        run: |
          conda activate eigenpy
          conda install -c conda-forge octomap assimp qhull

          git clone https://github.com/humanoid-path-planner/hpp-fcl.git --recursive
          cd hpp-fcl
          mkdir build && cd build
          cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=$(which python3)

    - name: Uninstall EigenPy
      shell: bash -l {0}
      run: |
        cd build
        make uninstall