name: multi platform test

on:
  push:
    branches: [ "trunk", "develop" ]
  pull_request:
    branches: [ "trunk" ]

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

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

    strategy:
      fail-fast: false

      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-version: [ 3.13 ]
        include:
          - os: windows-latest
            cpp_compiler: cl
            try_python: OFF
          - os: ubuntu-latest
            cpp_compiler: g++
            try_python: ON
          - os: macos-latest
            cpp_compiler: clang++
            try_python: OFF

    steps:
    - uses: actions/checkout@v6

    - name: Set reusable strings
      id: strings
      shell: bash
      run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

    - name: Install Catch2 Ubuntu
      if: matrix.os == 'ubuntu-latest'
      run: >
        sudo apt-get update && sudo apt-get install catch2 libpython3-all-dev

    - name: setup python
      if: matrix.os == 'ubuntu-latest'
      uses: actions/setup-python@v6
      with:
        python-version: ${{ matrix.python-version }}
        pip-install: numpy

    - name: Install Catch2 macOS
      if: matrix.os == 'macos-latest'
      run: >
        brew install catch2 fast_float
        brew install catch2 fast_float

    - name: Install dependencies Windows
      if: matrix.os == 'windows-latest'
      run: ./tools/depends.cmd
      shell: cmd

    - name: Install boost
      if: matrix.os == 'ubuntu-latest'
      uses: MarkusJx/install-boost@v2
      id: install-boost
      with:
        boost_version: 1.86.0

    - name: Configure CMake
      run: >
        cmake -B ${{ steps.strings.outputs.build-output-dir }}
        -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
        -DCMAKE_BUILD_TYPE=Release
        -DBUILD_TESTING=ON
        -DBUILD_PYTHON_MODULE=${{ matrix.try_python }}
        -S ${{ github.workspace }}
        -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local
        -DCMAKE_PREFIX_PATH=${{ steps.install-boost.outputs.BOOST_ROOT }}

    - name: Build
      run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release

    - name: Test
      working-directory: ${{ steps.strings.outputs.build-output-dir }}
      run: ctest --build-config Release --output-on-failure
      env:
        LIBCIFPP_DATA_DIR: ${{ steps.strings.outputs.build-output-dir }}/_deps/cifpp-src/rsrc

