name: Build

on:
  push:
    branches:
      - "*"
  pull_request:
    branches:
      - "*"
    types: [opened, synchronize, reopened]

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

env:
  PREMAKE_VERSION: "5.0.0-beta2"

jobs:
  build:
    name: Build binaries
    runs-on: windows-2022
    strategy:
      matrix:
        configuration:
          - debug
          - release
        compiler:
          - msvc
          - clang
    steps:
      - name: Check out files
        uses: actions/checkout@main
        with:
          submodules: true
          fetch-depth: 0
          # NOTE - If LFS ever starts getting used during builds, switch this to true!
          lfs: false

      - name: Add msbuild to PATH
        uses: microsoft/setup-msbuild@main

      - name: Install Premake5
        uses: diamante0018/setup-premake@master
        with:
          version: ${{ env.PREMAKE_VERSION }}

      - name: Generate project files (clang)
        if: matrix.compiler == 'clang'
        run: premake5 --cc=${{matrix.compiler}} vs2022

      - name: Generate project files (msvc)
        if: matrix.compiler == 'msvc'
        run: premake5 vs2022

      - name: Set up problem matching
        uses: ammaraskar/msvc-problem-matcher@master

      - name: Build ${{matrix.configuration}} binaries
        run: msbuild /m /p:Configuration=${{matrix.configuration}} /p:Platform=Win32 build/mw3-server-freezer.sln

      - name: Upload ${{matrix.configuration}} binaries
        uses: actions/upload-artifact@main
        with:
          name: windows-${{matrix.compiler}}-${{matrix.configuration}}
          path: |
            build/bin/Win32/${{matrix.configuration}}/mw3-server-freezer.dll
            build/bin/Win32/${{matrix.configuration}}/mw3-server-freezer.pdb