name: CI

on: [push, pull_request, release]

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        config:
        - {
            name: linux-x64-gcc,
            os: ubuntu-latest,
            cxx: g++,
            cmake-build-type: Release
          }
        - {
            name: linux-x64-gcc-no-exceptions,
            os: ubuntu-latest,
            cxx: g++,
            cxx-flags: -fno-exceptions,
            cmake-build-type: Release
          }
        - {
            name: linux-x64-clang,
            os: ubuntu-latest,
            cxx: clang++,
            cmake-build-type: Release
          }
        - {
            name: macos-x64-gcc,
            os:  macos-latest,
            cxx: g++,
            cmake-build-type: Release
          }
        - {
            name: macos-x64-clang,
            os:  macos-latest,
            cxx: clang++,
            cmake-build-type: Release
          }
        - {
            name: linux-x64-clang-sanitize,
            os: ubuntu-latest,
            cxx: clang++,
            cxx-flags: "-fsanitize=address,undefined",
            cmake-build-type: Release
          }
        - {
            name: linux-x64-gcc-coverage,
            os: ubuntu-latest,
            cxx: g++,
            cxx-flags: --coverage,
            gcov-tool: gcov,
            cmake-build-type: Debug
          }
        - {
            name: windows-x64-vs-2025,
            os: windows-2025,
            cmake-build-type: Release,
            cmake-generator: Visual Studio 17 2022,
            cmake-platform: x64,
            vcpkg-triplet: x64-windows-static-md
          }
        - {
            name: windows-x86-vs-2025,
            os: windows-2025,
            cmake-build-type: Release,
            cmake-generator: Visual Studio 17 2022,
            cmake-platform: Win32,
            vcpkg-triplet: x86-windows-static-md
          }
    name: ${{matrix.config.name}}
    runs-on: ${{matrix.config.os}}
    steps:
    - uses: actions/checkout@v2

    # Windows
    - name: Install boost (Windows)
      run: vcpkg install boost-test:${{matrix.config.vcpkg-triplet}}
      if: runner.os == 'Windows'

    - name: Configure CMake (Windows)
      run: cmake -G "${{matrix.config.cmake-generator}}" -A ${{matrix.config.cmake-platform}} -DCMAKE_BUILD_TYPE=${{matrix.config.cmake-build-type}} -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=${{matrix.config.vcpkg-triplet}} -S ${{github.workspace}}/tests -B ${{github.workspace}}/build
      if: runner.os == 'Windows'

    - name: Build (Windows)
      run: cmake --build ${{github.workspace}}/build --config ${{matrix.config.cmake-build-type}} --verbose
      if: runner.os == 'Windows'

    - name: Test (Windows)
      run: ${{github.workspace}}/build/${{matrix.config.cmake-build-type}}/tsl_ordered_map_tests.exe
      if: runner.os == 'Windows'

    # Linux or macOS
    - name: Install boost (Linux or macOS)
      run: vcpkg install boost-test
      if: runner.os == 'Linux' || runner.os == 'macOS'

    - name: Configure CMake (Linux or macOS)
      run: cmake -DCMAKE_BUILD_TYPE=${{matrix.config.cmake-build-type}} -DCMAKE_TOOLCHAIN_FILE="$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" -S ${{github.workspace}}/tests -B ${{github.workspace}}/build
      env:
        CXX: ${{matrix.config.cxx}}
        CXXFLAGS: ${{matrix.config.cxx-flags}}
      if: runner.os == 'Linux' || runner.os == 'macOS'

    - name: Build (Linux or macOS)
      run: cmake --build ${{github.workspace}}/build --verbose
      if: runner.os == 'Linux' || runner.os == 'macOS'

    - name: Test (Linux or macOS)
      run: ${{github.workspace}}/build/tsl_ordered_map_tests
      if: runner.os == 'Linux' || runner.os == 'macOS'

    - name: Coverage
      run: |
        sudo apt-get install -y lcov
        lcov -c -b ${{github.workspace}}/include -d ${{github.workspace}}/build -o ${{github.workspace}}/coverage.info --no-external --gcov-tool ${{matrix.config.gcov-tool}}
        bash <(curl -s https://codecov.io/bash) -f ${{github.workspace}}/coverage.info
      if: ${{matrix.config.name == 'linux-x64-gcc-coverage'}}
