name: CI - Build

on:
  pull_request:
  push:
    branches:
    - master

env:
  CTEST_OUTPUT_ON_FAILURE: 1

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
  emscripten:
    name: Emscripten

    uses: ./.github/workflows/ci-emscripten.yml
    secrets: inherit

  linux:
    strategy:
      fail-fast: false
      matrix:
        include:
        - name: Clang
          compiler: clang
          cxxcompiler: clang++
          libraries: libsdl2-dev
        - name: GCC - SDL2
          compiler: gcc
          cxxcompiler: g++
          libraries: libsdl2-dev
        - name: GCC - Dedicated
          compiler: gcc
          cxxcompiler: g++
          libraries: grfcodec
          extra-cmake-parameters: -DOPTION_DEDICATED=ON -DCMAKE_CXX_FLAGS_INIT="-DRANDOM_DEBUG" -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON
          # Compile without SDL / SDL2, as that should compile fine too.

    name: Linux (${{ matrix.name }})

    uses: ./.github/workflows/ci-linux.yml
    secrets: inherit

    with:
      compiler: ${{ matrix.compiler }}
      cxxcompiler: ${{ matrix.cxxcompiler }}
      libraries: ${{ matrix.libraries }}
      extra-cmake-parameters: ${{ matrix.extra-cmake-parameters }}

  macos:
    strategy:
      fail-fast: false
      matrix:
        include:
        - name: arm64 - Debug
          arch: arm64
          full_arch: arm64
          extra-cmake-parameters: -DCMAKE_BUILD_TYPE=Debug
        - name: arm64 - Release
          arch: arm64
          full_arch: arm64
          extra-cmake-parameters: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF

    name: Mac OS (${{ matrix.name }})

    uses: ./.github/workflows/ci-macos.yml
    secrets: inherit

    with:
      arch: ${{ matrix.arch }}
      full_arch: ${{ matrix.full_arch }}
      extra-cmake-parameters: ${{ matrix.extra-cmake-parameters }}

  windows:
    strategy:
      fail-fast: false
      matrix:
        include:
        - arch: x86
        - arch: x64

    name: Windows (${{ matrix.arch }})

    uses: ./.github/workflows/ci-windows.yml
    secrets: inherit

    with:
      arch: ${{ matrix.arch }}

  check_annotations:
    name: Check Annotations
    needs:
    - emscripten
    - linux
    - macos
    - windows

    if: always() && github.event_name == 'pull_request'

    runs-on: ubuntu-latest

    steps:
    - name: Check annotations
      uses: OpenTTD/actions/annotation-check@v5
