name: macOS

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

permissions:
  contents: read

jobs:
  build:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: Unbreak Python in GitHub Actions
      run: |
        find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
        sudo rm -rf /Library/Frameworks/Python.framework/
        brew install --force python3 && brew unlink python3 && brew link --overwrite python3

    - name: Install Packages
      run: |
        export HOMEBREW_NO_INSTALL_FROM_API=1
        brew update
        brew install meson sdl2

    - name: Build
      run: |
        meson setup build -Dlog=true -Dexamples=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all
        ninja -C build install

  compact_test:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: Unbreak Python in GitHub Actions
      run: |
        find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
        sudo rm -rf /Library/Frameworks/Python.framework/
        brew install --force python3 && brew unlink python3 && brew link --overwrite python3

    - name: Install Packages
      run: |
        brew update
        brew install meson

    - name: Build
      run: |
        meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false
        ninja -C build install

  unit_test:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: Unbreak Python in GitHub Actions
      run: |
        find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
        sudo rm -rf /Library/Frameworks/Python.framework/
        brew install --force python3 && brew unlink python3 && brew link --overwrite python3

    - name: Install Packages
      run: |
        brew update
        brew install meson

    - name: Build
      run: |
        meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true --errorlogs
        ninja -C build install test

    - uses: actions/upload-artifact@v4
      with:
        name: UnitTestReport
        path: build/meson-logs/testlog.txt
