name: ubuntu-build

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:
    strategy:
      # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
      fail-fast: false
      matrix:
        # the result of the matrix will be the combination of all attributes, so we get os*compiler builds
        include:
          - os: ubuntu-20.04
            c_compiler: clang
            cpp_compiler: clang++
            build_type: Release
          - os: ubuntu-20.04
            c_compiler: gcc
            cpp_compiler: g++
            build_type: Release
          - os: ubuntu-latest
            c_compiler: gcc
            cpp_compiler: g++
            build_type: Release
            
    runs-on: ${{ matrix.os }}
    name: ${{ matrix.os }}-${{ matrix.cpp_compiler }}

    steps:
      - name: Checkout AzerothCore
        uses: actions/checkout@v3
        with:
          repository: 'liyunfan1223/azerothcore-wotlk'
          ref: 'Playerbot'

      - name: Set reusable strings
        id: strings
        shell: bash
        run: |
          echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
          
      - name: Checkout Playerbot Module
        uses: actions/checkout@v3
        with:
          repository: 'liyunfan1223/mod-playerbots'
          path: 'modules/mod-playerbots'
      
      - name: Cache
        uses: actions/cache@v3
        with:
          path: |
            /var/cache/apt
            /var/lib/apt
          key: ccache:${{ matrix.os }}:${{ github.ref }}:${{ github.sha }}
          restore-keys: |
            ccache:${{ matrix.os }}:${{ github.ref }}
            ccache:${{ matrix.os }}

      - name: Install Requirements
        run: sudo apt-get update && sudo apt-get install git cmake make gcc g++ clang libmysqlclient-dev libssl-dev libbz2-dev libreadline-dev libncurses-dev mysql-server libboost-all-dev

      - name: Configure CMake
        run: >
          cmake -B ${{ steps.strings.outputs.build-output-dir }}
          -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
          -DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
          -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
          -S ${{ github.workspace }}

      - name: Build
        run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
