name: C/Fortran

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-24.04, macos-15]
        compiler: [gcc, clang]
        include:
          - os: macos-15
            compiler: apple-clang

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

    steps:
    - name: Environment setup
      uses: actions/checkout@v4
    - name: Set compiler
      run: |
        case "${{ matrix.compiler }}" in
          gcc)
            if [[ "${{ matrix.os }}" == macos-* ]]; then
              echo "CC=gcc-15" >> $GITHUB_ENV
            else
              echo "CC=gcc" >> $GITHUB_ENV
            fi
            ;;
          clang)
            if [[ "${{ matrix.os }}" == macos-* ]]; then
              echo "CC=$(brew --prefix llvm@18)/bin/clang" >> $GITHUB_ENV
            else
              echo "CC=clang" >> $GITHUB_ENV
            fi
            ;;
          apple-clang)
            echo "CC=clang" >> $GITHUB_ENV
            ;;
        esac
    - name: Show compiler version
      run: $CC --version | head -1
    - name: Build and test libCEED
      env:
        FC: gfortran-14
      run: |
        make info
        make -j
        make prove -j2
