name: Tests
on:
  push:
    branches:
      - main
      - v*
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    strategy:
      matrix:
        std: ["11", "14", "17", "20"]
        precompile: ["ON", "OFF"]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Get LCov
        run: |
          wget https://github.com/linux-test-project/lcov/releases/download/v1.16/lcov-1.16.tar.gz
          tar -xzf lcov-1.16.tar.gz
          cd lcov-1.16
          sudo make install

      - name: Configure
        run: |
          cmake -S . -B build \
            -DCMAKE_CXX_STANDARD=${{matrix.std}} \
            -DCLI11_SINGLE_FILE_TESTS=OFF \
            -DCLI11_EXAMPLES=OFF \
            -DCLI11_PRECOMPILED=${{matrix.precompile}} \
            -DCMAKE_BUILD_TYPE=Coverage

      - name: Build
        run: cmake --build build -j4

      - name: Test
        run: cmake --build build --target CLI11_coverage

      - name: Prepare coverage
        run: |
          lcov --directory . --capture --output-file coverage.info
          lcov --remove coverage.info '*/tests/*' '*/examples/*' '/usr/*' --output-file coverage.info
          lcov --list coverage.info
        working-directory: build

      - uses: codecov/codecov-action@v3
        with:
          fail_ci_if_error: true
          working-directory: build

  clang-tidy:
    name: Clang-Tidy
    runs-on: ubuntu-latest
    container: silkeh/clang:14
    steps:
      - uses: actions/checkout@v3

      - name: Configure
        run: >
          cmake -S . -B build -DCMAKE_CXX_STANDARD=17
          -DCMAKE_CXX_CLANG_TIDY="$(which
          clang-tidy);--use-color;--warnings-as-errors=*"

      - name: Build
        run: cmake --build build -j4 -- --keep-going

  cuda-build:
    name: CUDA build only
    runs-on: ubuntu-latest
    container: nvidia/cuda:10.2-devel-ubuntu18.04
    steps:
      - uses: actions/checkout@v1
        with:
          submodules: true
      - name: Add wget
        run: apt-get update && apt-get install -y wget
      - name: Get cmake
        uses: jwlawson/actions-setup-cmake@v1.13
      - name: Configure
        run: cmake -S . -B build -DCLI11_CUDA_TESTS=ON
      - name: Build
        run: cmake --build build -j2

  boost-build:
    name: Boost build
    runs-on: ubuntu-latest
    container: zouzias/boost:1.76.0
    steps:
      - uses: actions/checkout@v1
        with:
          submodules: true
      - name: Add deps
        run: apt-get update && apt-get install make
      - name: Get CMake
        uses: jwlawson/actions-setup-cmake@v1.13
      - name: Configure
        run: cmake -S . -B build -DCLI11_BOOST=ON
      - name: Build
        run: cmake --build build -j2
      - name: Run tests
        run: ctest --output-on-failure
        working-directory: build

  meson-build:
    name: Meson build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Prepare commands
        run: |
          pipx install meson
          pipx install ninja

      - name: Configure
        run: meson setup build-meson . -Dtests=true

      - name: Build
        run: meson compile -C build-meson

  cmake-config:
    name: CMake config check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Check CMake 3.4
        with:
          cmake-version: "3.4"
        uses: ./.github/actions/quick_cmake

      - name: Check CMake 3.5
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.5"
        if: success() || failure()

      - name: Check CMake 3.6
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.6"
        if: success() || failure()

      - name: Check CMake 3.7
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.7"
        if: success() || failure()

      - name: Check CMake 3.8
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.8"
        if: success() || failure()

      - name: Check CMake 3.9
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.9"
        if: success() || failure()

      - name: Check CMake 3.10
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.10"
        if: success() || failure()

      - name: Check CMake 3.11 (full)
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.11"
          args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
        if: success() || failure()

      - name: Check CMake 3.12
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.12"
        if: success() || failure()

      - name: Check CMake 3.13
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.13"
        if: success() || failure()

      - name: Check CMake 3.14
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.14"
        if: success() || failure()

      - name: Check CMake 3.15
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.15"
        if: success() || failure()

      - name: Check CMake 3.16
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.16"
        if: success() || failure()

      - name: Check CMake 3.17
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.17"
        if: success() || failure()

      - name: Check CMake 3.18
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.18"
        if: success() || failure()

      - name: Check CMake 3.19
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.19"
        if: success() || failure()

      - name: Check CMake 3.20
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.20"
        if: success() || failure()

      - name: Check CMake 3.21 (full)
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.21"
          args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
        if: success() || failure()

      - name: Check CMake 3.22 (full)
        uses: ./.github/actions/quick_cmake
        with:
          cmake-version: "3.22"
          args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
        if: success() || failure()
