name: macOS

on: [push, pull_request]

jobs:
  build:
    name: AppleClang-C++${{matrix.std}}-${{matrix.build_type}}
    runs-on: macos-10.15
    strategy:
      fail-fast: false
      matrix:
          std: [98, 11, 14, 17, 20]
          include:
            - generator: Ninja
            - build_type: Debug

    steps:
    - uses: actions/checkout@v2

    - name: Setup Ninja
      uses: ashutoshvarma/setup-ninja@master
      with:
        version: 1.10.0

    - name: Configure
      shell: bash
      env:
        CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Werror
      run: |
        if [[ ${{matrix.std}} == 98 ]]; then
          export CXXFLAGS="-Werror=c++11-extensions ${CXXFLAGS}"
        fi
        cmake -S . -B ${{runner.workspace}}/build_${{matrix.name}}_${{matrix.build_type}} \
              -G "${{matrix.generator}}" \
              -DCMAKE_CXX_EXTENSIONS=OFF \
              -DCMAKE_CXX_FLAGS_DEBUG=-pedantic-errors  \
              -DCMAKE_CXX_FLAGS_RELEASE=-pedantic-errors \
              -DCMAKE_CXX_STANDARD=${{matrix.std}} \
              -DCMAKE_CXX_STANDARD_REQUIRED=ON
    - name: Build
      run: |
        cmake --build ${{runner.workspace}}/build_${{matrix.name}}_${{matrix.build_type}} \
              --config ${{matrix.build_type}}
    - name: Run tests
      run: |
        ctest --test-dir ${{runner.workspace}}/build_${{matrix.name}}_${{matrix.build_type}} \
              --output-on-failure
