name: 🍎 MacOS Builds

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '**/*.bat'
      - '**/*.cmd'
      - '**/*.props'
      - '**/*.sln'
      - '.clang-format'
      - '.codacy.yaml'
      - '.github/*'
      - '.github/workflows/lint-gamedb.yml'
      - '.github/workflows/linux-workflow.yml'
      - '.github/workflows/pr-triage.yml'
      - '.github/workflows/scripts/windows/**'
      - '.github/workflows/scripts/validation/**'
      - '.github/workflows/windows-workflow.yml'
      - '.gitignore'
      - 'bin/PCSX2_keys.ini.default'
      - 'build.sh'
      - 'buildbot.xml'
      - 'pcsx2/CDVD/Windows/**'
      - 'pcsx2/DEV9/Win32/**'
      - 'pcsx2/PAD/Windows/**'
      - 'pcsx2/SPU2/Windows/**'
      - 'pcsx2/USB/Win32/**'
      - 'pcsx2/windows/**'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '**/*.bat'
      - '**/*.cmd'
      - '**/*.props'
      - '**/*.sln'
      - '.clang-format'
      - '.codacy.yaml'
      - '.github/*'
      - '.github/workflows/lint-gamedb.yml'
      - '.github/workflows/linux-workflow.yml'
      - '.github/workflows/pr-triage.yml'
      - '.github/workflows/scripts/windows/**'
      - '.github/workflows/scripts/validation/**'
      - '.github/workflows/windows-workflow.yml'
      - '.gitignore'
      - 'bin/PCSX2_keys.ini.default'
      - 'build.sh'
      - 'buildbot.xml'
      - 'pcsx2/CDVD/Windows/**'
      - 'pcsx2/DEV9/Win32/**'
      - 'pcsx2/PAD/Windows/**'
      - 'pcsx2/SPU2/Windows/**'
      - 'pcsx2/USB/Win32/**'
      - 'pcsx2/windows/**'

jobs:
  build:
    strategy:
      # Prevent one build from failing everything (although maybe those should be included as experimental builds instead)
      fail-fast: false
      matrix:
        os: [macos-11.0]
        platform: [x64]
        experimental: [false]

    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.experimental }}
    # Set some sort of timeout in the event of run-away builds.  We are limited on concurrent jobs so, get rid of them.
    timeout-minutes: 30

    steps:
      # NOTE - useful for debugging
      # - name: Dump GitHub context
      #   env:
      #     GITHUB_CONTEXT: ${{ toJson(github) }}
      #   run: |
      #     echo "$GITHUB_CONTEXT"
      #     echo ${{ github.event.pull_request.title }}

      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Checkout Submodules
        run: git submodule update --init --recursive -j $(getconf _NPROCESSORS_ONLN)

      - name: Install Packages
        env:
          PLATFORM: ${{ matrix.platform }}
          HOMEBREW_NO_INSTALL_CLEANUP: 1
          HOMEBREW_NO_ANALYTICS: 1
        run: |
          # To save time, only brew update if running the install without it fails
          function do-install() {
            brew install sound-touch portaudio wxwidgets sdl2 libsamplerate
          }
          if ! do-install; then
            brew update
            do-install
          fi

      - name: Generate CMake Files
        run: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_PO=FALSE -DLTO_PCSX2_CORE=ON -B build .

      - name: Build PCSX2
        working-directory: build
        run: make -j$(getconf _NPROCESSORS_ONLN) # macOS doesn't use make install

      - name: Run Tests
        working-directory: build
        run: make -j$(getconf _NPROCESSORS_ONLN) unittests
