name: CMake

on: [push, pull_request]

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release

jobs:
  build-library:

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        python-version: ["3.8", "3.9", "3.10", "3.11"]
    defaults:
      run:
        shell: bash -l {0}
    env:
      SSPICE_DEBUG: y
    steps:
    - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
    - uses: conda-incubator/setup-miniconda@3b0f2504dd76ef23b6d31f291f4913fb60ab5ff3
      with:
          miniconda-version: "latest"
          activate-environment: csmswig
          environment-file: environment.yml
          python-version: ${{ matrix.python-version }}
          auto-activate-base: false
          auto-update-conda: true

    - name: Conda info
      run: |
          conda info
          conda list

    - name: Create Build Environment
      # Some projects don't allow in-source building, so createa  separate build directory
      # we'll use it as our working directory for subsequent commands.
      run: cmake -E make_directory ${{github.workspace}}/build

    - name: Configure CMake
      working-directory: ${{github.workspace}}/build
      run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

    - name: Build wrapper
      working-directory: ${{github.workspace}}/build
      # Execute the build.  You can specify a specific target with "--target <NAME>"
      run: cmake --build . --config $BUILD_TYPE

    - name: Install wrapper
      working-directory: ${{github.workspace}}/build/python
      # Execute the build.  You can specify a specific target with "--target <NAME>"
      run: python setup.py install

    - name: Test
      working-directory: ${{github.workspace}}/build/python
      # Execute tests defined by the CMake configuration.
      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
      run: ctest -VV -C $BUILD_TYPE
