name: CI

on:
  push:
    paths-ignore:
      - .circleci/
      - .appveyor.yml
      - .cirrus.yml
      - .editorconfig
      - .gitignore
      - LICENSE
      - plog.nuspec
      - plog.targets
      - README.md
  pull_request:
    paths-ignore:
      - .circleci/
      - .appveyor.yml
      - .cirrus.yml
      - .editorconfig
      - .gitignore
      - LICENSE
      - plog.nuspec
      - plog.targets
      - README.md

permissions:
  contents: read

jobs:
  build:
    name: ${{ matrix.cxx }}, ${{ matrix.os }}

    strategy:
      fail-fast: true
      matrix:
        include: [
          # You can access the following values via ${{ matrix.??? }}
          #
          #   pkgs         : apt-get package names separated by space
          #   cxx          : C++ compiler executable
          #   os           : GitHub Actions YAML workflow label.  See https://github.com/actions/virtual-environments#available-environments

          # linux: gcc
          { os: ubuntu-24.04,   cxx: g++-14,      pkgs: '' }, # (default on Noble 24.04)
          { os: ubuntu-22.04,   cxx: g++-11,      pkgs: '' }, # (default on Jammy 22.04)
          { os: ubuntu-22.04,   cxx: g++-9,       pkgs: '' }, # (default on Focal 20.04)
          { os: ubuntu-20.04,   cxx: g++-7,       pkgs: 'g++-7' }, # (default on Bionic 18.04)
          { os: ubuntu-20.04,   cxx: g++-5,       pkgs: 'g++-5',   repo: 'xenial' }, # (default on Xenial 16.04)
          { os: ubuntu-20.04,   cxx: g++-4.8,     pkgs: 'g++-4.8', repo: 'trusty' }, # (default on Trusty 14.04)
          # linux: clang
          { os: ubuntu-22.04,   cxx: clang++-14,  pkgs: '' },
          { os: ubuntu-20.04,   cxx: clang++-10,  pkgs: '' },
          { os: ubuntu-20.04,   cxx: clang++-6.0, pkgs: 'clang-6.0' },
          # windows: msvc
          { os: windows-2019,   cxx: 'vs2019' },
          { os: windows-2022,   cxx: 'vs2022' },
          # macos: clang
          { os: macos-13,       cxx: 'clang++' }
        ]

    runs-on: ${{ matrix.os }}

    env:
      CXX: ${{ matrix.cxx }}

    steps:
    - name: checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 0

    # workaround for broken clang on ubuntu runner until https://github.com/actions/runner-images/issues/8659 get fixed
    - uses: mjp41/workaround8649@c8550b715ccdc17f89c8d5c28d7a48eeff9c94a8
      with:
        os: ${{ matrix.os }}

    - name: apt/sources.list.d
      if: ${{ matrix.repo != '' }}
      run: |
        echo "deb http://archive.ubuntu.com/ubuntu ${{ matrix.repo }} main" | sudo tee /etc/apt/sources.list.d/${{ matrix.repo }}.list

    - name: apt-get install
      if: ${{ matrix.pkgs != '' }}
      run: |
        sudo apt-get update
        sudo apt-get install ${{ matrix.pkgs }}

    - name: build
      run: |
        cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DPLOG_BUILD_TESTS=1 .
        cmake --build build --parallel

    - name: test
      run: cd build && ctest -V
