name: macos-build

on:
  push:
    branches:
      - "Playerbot"
      - "test-staging"
  pull_request:
    branches:
      - "Playerbot"
      - "test-staging"

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

permissions:
  actions: write
  contents: read

jobs:
  macos-build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - macos-14
    runs-on: ${{ matrix.os }}
    name: ${{ matrix.os }}
    steps:
      - name: Checkout AzerothCore
        uses: actions/checkout@v4

      - name: Checkout Playerbot Module
        uses: actions/checkout@v4
        with:
          repository: mod-playerbots/mod-playerbots
          ref: ${{ github.ref_name == 'Playerbot' && 'master' || 'test-staging' }}
          path: modules/mod-playerbots

      - name: Cache
        uses: actions/cache@v4
        with:
          path: ~/Library/Caches/ccache
          key: ccache:${{ matrix.os }}:${{ github.ref_name }}
          restore-keys: |
            ccache:${{ matrix.os }}:${{ github.ref_name }}
            ccache:${{ matrix.os }}

      - name: reset ccache stats
        shell: bash
        run: ccache -z || true

      - name: Install latest bash
        run: brew install bash

      - name: Configure OS
        shell: bash
        run: source ./acore.sh install-deps

      - name: Build
        shell: bash
        run: source ./apps/ci/mac/ci-compile.sh

      - name: ccache stats
        shell: bash
        run: ccache -s || true