name: CI

on: [ push, pull_request ]

jobs:
  linux:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        image:
          - "ubuntu:18.04"        # gcc  7.5.0, clang  6.0.0, cmake 3.10.2
          - "ubuntu:20.04"        # gcc  9.3.0, clang 10.0.0, cmake 3.16.3
          - "ubuntu:22.04"        # gcc 11.2.0, clang 14.0.0, cmake 3.22.1
          - "debian:stretch"      # gcc  6.3.0, clang  3.8.1, cmake 3.7.2
          - "debian:buster"       # gcc  8.3.0, clang  7.0.1, cmake 3.13.4
          - "debian:bullseye"     # gcc 10.2.1, clang 11.0.1, cmake 3.18.4
          - "debian:testing"
          - "debian:experimental"
          - "fedora:35"           # gcc 11.2.1, clang 13.0.0, cmake 3.22.0
          - "fedora:36"           # gcc 12.2.0, clang 14.0.5, cmake 3.24.2
        build_type: [Dev]
        cpp_compiler: [g++]
        cpp_version: [c++14]
        include:
          - image: "debian:bullseye"
            cpp_version: c++17
          - image: "debian:bullseye"
            cpp_version: c++20
          - image: "debian:bullseye"
            c_compiler: clang
            cpp_compiler: clang++
            cpp_version: c++17
          - image: "debian:bullseye"
            c_compiler: clang
            cpp_compiler: clang++
            cpp_version: c++20
          - image: "debian:bullseye"
            build_type: RelWithDebInfo
          - image: "debian:bullseye"
            c_compiler: clang
            cpp_compiler: clang++
          - image: "debian:testing"
            CXXFLAGS: -Wno-stringop-overread -Wno-array-bounds
          - image: "debian:testing"
            c_compiler: clang
            cpp_compiler: clang++
          - image: "debian:experimental"
            CXXFLAGS: -Wno-stringop-overread -Wno-array-bounds
          - image: "debian:experimental"
            c_compiler: clang-14
            cpp_compiler: clang++-14
          - image: "fedora:35"
            CXXFLAGS: -Wno-stringop-overread
          - image: "fedora:36"
            CXXFLAGS: -Wno-stringop-overread -Wno-array-bounds
    container:
      image: ${{ matrix.image }}
      env:
        BUILD_TYPE: ${{ matrix.build_type }}
        CC: ${{ matrix.c_compiler }}
        CXX: ${{ matrix.cpp_compiler }}
        CXXFLAGS: ${{ matrix.CXXFLAGS }}
        LDFLAGS: ${{ matrix.LDFLAGS }}
        CPP_VERSION: ${{ matrix.cpp_version }}
        APT_LISTCHANGES_FRONTEND: none
        DEBIAN_FRONTEND: noninteractive
    steps:
      - name: Prepare container (apt)
        shell: bash
        if: startsWith(matrix.image, 'debian:') || startsWith(matrix.image, 'ubuntu:')
        run: |
          apt-get update -qq
          apt-get install -yq \
            clang \
            cmake \
            g++ \
            git \
            libboost-dev \
            libboost-program-options-dev \
            libbz2-dev \
            libexpat1-dev \
            liblz4-dev \
            make \
            pandoc \
            zlib1g-dev
      - name: Install compiler
        shell: bash
        if: matrix.cpp_compiler == 'clang++-14'
        run: apt-get install -yq --no-install-suggests --no-install-recommends clang-14
      - name: Prepare container (dnf)
        shell: bash
        if: startsWith(matrix.image, 'fedora:')
        run: |
          dnf install --quiet --assumeyes \
              boost-devel \
              bzip2-devel \
              cmake \
              expat-devel \
              gcc-c++ \
              git \
              lz4-devel \
              make \
              pandoc \
              zlib-devel
      - uses: actions/checkout@v3
      - uses: ./.github/actions/install-from-git
      - uses: ./.github/actions/cmake
      - uses: ./.github/actions/build
      - uses: ./.github/actions/ctest

  ubuntu-latest:
    runs-on: ubuntu-22.04
    env:
      CC: clang-15
      CXX: clang++-15
      BUILD_TYPE: Dev
    steps:
      - name: Install new clang
        run: |
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm-snapshot.asc
          sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
          sudo apt-get update -qq
          sudo apt-get install -yq clang-15
        shell: bash
      - uses: actions/checkout@v3
      - uses: ./.github/actions/install-ubuntu
      - uses: ./.github/actions/install-from-git
      - uses: ./.github/actions/cmake
      - uses: ./.github/actions/build
      - uses: ./.github/actions/ctest

  macos:
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        os:
          - "macos-11"
        build_type: [Dev]
        include:
          - os: "macos-11"
            build_type: Release
    runs-on: ${{ matrix.os }}
    env:
      CC: clang
      CXX: clang++
      BUILD_TYPE: ${{ matrix.build_type }}
    steps:
      - run: brew install boost
      - uses: actions/checkout@v3
      - uses: ./.github/actions/install-from-git
      - uses: ./.github/actions/cmake
      - uses: ./.github/actions/build
      - uses: ./.github/actions/ctest

  windows:
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2019
          - windows-2022
    runs-on: ${{ matrix.os }}
    steps:
      - run: |
          vcpkg install \
            boost-iterator:x64-windows \
            boost-program-options:x64-windows \
            boost-variant:x64-windows \
            bzip2:x64-windows \
            expat:x64-windows \
            lz4:x64-windows \
            zlib:x64-windows
        shell: bash
      - uses: actions/checkout@v3
      - uses: ./.github/actions/install-from-git
      - uses: ./.github/actions/cmake-windows
      - uses: ./.github/actions/build-windows
      - uses: ./.github/actions/ctest-windows

