name: macOS CI

on:
  push:
    branches: [master, develop]
    paths-ignore:
      - '*.md'
      - 'docs/**'
  pull_request:
    types: [opened, synchronize]
    paths-ignore:
      - '*.md'
      - 'docs/**'
  workflow_dispatch:

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

jobs:
  cmake:
    name: CMake - ${{ matrix.runs-on }} - ${{ matrix.name }}

    strategy:
      matrix:
        runs-on:
          - macos-13
          - macos-latest
        include:
          - compiler: gcc
            name: GCC
            coverage: true
          - compiler: clang
            name: Clang
            coverage: false

    runs-on: ${{ matrix.runs-on }}
    steps:
      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0

      - name: Setup Compiler
        run: |
          if [ "${{ matrix.compiler }}" = "gcc" ]; then
            echo "CC=gcc" >> $GITHUB_ENV
            echo "CXX=g++" >> $GITHUB_ENV
          else
            echo "CC=clang" >> $GITHUB_ENV
            echo "CXX=clang++" >> $GITHUB_ENV
          fi

      - name: Build in Release Mode
        continue-on-error: true
        run: |
          cmake -S . -B build-release -DENABLE_NATIVE_CODE=ON
          cmake --build build-release -j $(getconf _NPROCESSORS_ONLN)

      - name: Build in Debug Mode
        run: |
          cmake -S. -B build-debug \
            -DENABLE_NATIVE_CODE=ON \
            -DENABLE_ASAN=ON \
            -DENABLE_UBSAN=ON \
            -DCMAKE_BUILD_TYPE=Debug
          cmake --build build-debug -j $(getconf _NPROCESSORS_ONLN)

      - name: Run Tests (Debug)
        run: ctest --test-dir build-debug --output-on-failure -j $(getconf _NPROCESSORS_ONLN)
