name: CMake Install Tests

on:
  workflow_dispatch:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

permissions:
  contents: read

jobs:
  windows_2022_vcpkg_submodule:
    name: Windows 2022 vcpkg submodule versions cxx17 (static libs - dll)
    runs-on: windows-2022
    env:
      # cxx17 is the default for windows-2022
      CXX_STANDARD: '17'
    steps:
      - name: Harden the runner (Audit all outbound calls)
        uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
        with:
          egress-policy: audit

      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          submodules: 'recursive'
      - name: Build dependencies with vcpkg submodule
        run: |
          ./ci/setup_windows_ci_environment.ps1
      - name: Run Tests
        run: ./ci/do_ci.ps1 cmake.install.test
      - name: Run DLL Tests
        run: ./ci/do_ci.ps1 cmake.dll.install.test

  windows_2025_vcpkg_submodule:
    name: Windows 2025 vcpkg submodule versions cxx20 (static libs)
    runs-on: windows-2025
    env:
      CXX_STANDARD: '20'
    steps:
      - name: Harden the runner (Audit all outbound calls)
        uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
        with:
          egress-policy: audit

      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          submodules: 'recursive'
      - name: Build dependencies with vcpkg submodule
        run: |
          ./ci/setup_windows_ci_environment.ps1
      - name: Run Tests
        run: ./ci/do_ci.ps1 cmake.install.test

  ubuntu_2404_system_packages:
    name: Ubuntu 24.04 apt packages cxx17 (static libs - shared libs)
    runs-on: ubuntu-24.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      # cxx17 is the default for Ubuntu 24.04
      CXX_STANDARD: '17'
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit
    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Setup CI Environment
      run: |
        sudo -E ./ci/setup_ci_environment.sh
    - name: Install Dependencies
      run: |
        sudo -E apt-get update
        sudo -E apt-get install -y libabsl-dev libcurl4-openssl-dev zlib1g-dev nlohmann-json3-dev libprotobuf-dev libgrpc++-dev protobuf-compiler protobuf-compiler-grpc
        sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release --packages "googletest;benchmark"
    - name: Run Tests (static libs)
      env:
        BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test
    - name: Run Tests (shared libs)
      env:
        BUILD_SHARED_LIBS: 'ON'
      run: ./ci/do_ci.sh cmake.install.test

  ubuntu_2404_latest:
    name: Ubuntu 24.04 latest versions cxx20 (static libs - shared libs)
    runs-on: ubuntu-24.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      CXX_STANDARD: '20'
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit
    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Setup CI Environment
      run: |
        sudo -E ./ci/setup_ci_environment.sh
    - name: Install Dependencies
      run: |
        sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_latest
    - name: Run Tests (static libs)
      env:
        BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test
    - name: Run Tests (shared libs)
      env:
        BUILD_SHARED_LIBS: 'ON'
      run: ./ci/do_ci.sh cmake.install.test

  ubuntu_2204_stable:
    name: Ubuntu 22.04 stable versions cxx17 (static libs - shared libs)
    runs-on: ubuntu-22.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      CXX_STANDARD: '17'
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit
    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Setup CI Environment
      run: |
        sudo -E ./ci/setup_ci_environment.sh
    - name: Install Dependencies
      run: |
        sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_stable
    - name: Run Tests (static libs)
      env:
        BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test
    - name: Run Tests (shared libs)
      env:
        BUILD_SHARED_LIBS: 'ON'
      run: ./ci/do_ci.sh cmake.install.test

  ubuntu_2204_minimum:
    name: Ubuntu 22.04 minimum versions cxx14 (static libs - shared libs)
    runs-on: ubuntu-22.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      # Set to the current minimum version of cmake
      CMAKE_VERSION: '3.16.0'
      # cxx14 is the default for Ubuntu 22.04
      CXX_STANDARD: '14'
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit
    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Setup CI Environment
      run: |
        sudo -E ./ci/setup_ci_environment.sh
        sudo -E ./ci/setup_cmake.sh
    - name: Install Dependencies
      run: |
        sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_minimum
    - name: Run Tests (static libs)
      env:
          BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test
    - name: Run Tests (shared libs)
      env:
          BUILD_SHARED_LIBS: 'ON'
      run: ./ci/do_ci.sh cmake.install.test

  ubuntu_2404_conan_stable:
    name: Ubuntu 24.04 conan stable versions cxx17 (static libs - opentracing shim)
    runs-on: ubuntu-24.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      CXX_STANDARD: '17'
      CMAKE_TOOLCHAIN_FILE: /home/runner/conan/build/Debug/generators/conan_toolchain.cmake
      BUILD_TYPE: 'Debug'
    steps:
      - name: Harden the runner (Audit all outbound calls)
        uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
        with:
          egress-policy: audit

      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          submodules: 'recursive'
      - name: Install Conan
        run: |
          python3 -m pip install pip==25.0.1
          pip install "conan==2.15.1"
          conan profile detect --force
      - name: Install or build all dependencies with Conan
        run: |
          conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
          conan cache clean --source --build
      - name: Run Tests (static libs)
        env:
          BUILD_SHARED_LIBS: 'OFF'
        run: ./ci/do_ci.sh cmake.install.test
      - name: verify pkgconfig packages
        run: |
          export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
          ./ci/verify_packages.sh
      - name: Run OpenTracing Shim Test
        run: ./ci/do_ci.sh cmake.opentracing_shim.install.test

  ubuntu_2404_conan_latest:
    name: Ubuntu 24.04 conan latest versions cxx17 (static libs - opentracing shim)
    runs-on: ubuntu-24.04
    env:
      INSTALL_TEST_DIR: '/home/runner/install_test'
      CXX_STANDARD: '17'
      CMAKE_TOOLCHAIN_FILE: /home/runner/conan/build/Debug/generators/conan_toolchain.cmake
      BUILD_TYPE: 'Debug'
    steps:
      - name: Harden the runner (Audit all outbound calls)
        uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
        with:
          egress-policy: audit

      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          submodules: 'recursive'
      - name: Install Conan
        run: |
          python3 -m pip install pip==25.0.1
          pip install "conan==2.15.1"
          conan profile detect --force
      - name: Install or build all dependencies with Conan
        run: |
          conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
          conan cache clean --source --build
      - name: Run Tests (static libs)
        env:
          BUILD_SHARED_LIBS: 'OFF'
        run: ./ci/do_ci.sh cmake.install.test
      - name: verify pkgconfig packages
        run: |
          export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
          ./ci/verify_packages.sh
      - name: Run OpenTracing Shim Test
        run: ./ci/do_ci.sh cmake.opentracing_shim.install.test

  macos_14_conan_stable:
    name: macOS 14 conan stable versions cxx17 (static libs)
    runs-on: macos-14
    env:
      INSTALL_TEST_DIR: '/Users/runner/install_test'
      CXX_STANDARD: '17'
      CMAKE_TOOLCHAIN_FILE: '/Users/runner/conan/build/Debug/generators/conan_toolchain.cmake'
      CMAKE_VERSION: 3.31.0 # building the conan "stable" versions requires CMake 3.x
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Install CMake
      run: |
        ./ci/setup_cmake_macos.sh
    - name: Install Conan and tools
      run: |
        brew install conan autoconf automake libtool coreutils
        conan profile detect --force
    - name: Install or build all dependencies with Conan
      run: |
        conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
        conan cache clean --source --build
    - name: Run Tests (static libs)
      env:
        BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test

  macos_14_brew_packages:
    name: macOS 14 brew latest versions cxx17 (static libs)
    runs-on: macos-14
    env:
      INSTALL_TEST_DIR: '/Users/runner/install_test'
      CXX_STANDARD: '17'
      BUILD_TYPE: 'Debug'
    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        submodules: 'recursive'
    - name: Install Dependencies with Homebrew
      run: |
        brew install coreutils
        brew install googletest
        brew install google-benchmark
        brew install zlib
        brew install abseil
        brew install protobuf
        brew install grpc
        brew install nlohmann-json
        brew install prometheus-cpp
    - name: Run Tests (static libs)
      env:
        BUILD_SHARED_LIBS: 'OFF'
      run: ./ci/do_ci.sh cmake.install.test
