name: Test with sanitizers
on: [workflow_dispatch]

jobs:
  sanitizer:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        sanitizer: [address, undefined, thread]
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-depth: 0
      - name: Install Conda environment
        uses: mamba-org/setup-micromamba@v1
        with:
          environment-name: highsdev
          create-args: >-
            python==3.8
            meson
            pkgconfig
            ninja
            zlib
            catch2
            numpy
          cache-environment: true
          init-shell: >-
            bash
            zsh
      - name: Build and test
        shell: bash -l {0}
        run: |
          meson setup bddir -Duse_zlib=enabled -Dwith_tests=True -Db_sanitize=${{ matrix.sanitizer }}
          meson test -C bddir -t 10  # Time x10 for the tests
      - name: Upload log
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: log_${{ matrix.sanitizer }}_${{ matrix.os }}.txt
          path: bddir/meson-logs/testlog.txt
