name: Test

on:
  push:
    branches:
      - dev
      - Feat/Backend-Direct-GLES
      - Feat/Backend-Direct-Vulkan

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      # TEST_ROOT: ${{github.workspace}}/MobileGL/MG_Test
      TEST_ROOT: ${{github.workspace}}

    steps:
      - name: Set Swap Space
        uses: pierotofy/set-swap-space@master
        with:
          swap-size-gb: 32

      - name: Checkout repo
        uses: actions/checkout@v4
        with:
          submodules: true

      - name: Get CMake
        uses: lukka/get-cmake@latest

      - name: Prepare Vulkan SDK
        uses: humbletim/setup-vulkan-sdk@v1.2.1
        with:
          vulkan-query-version: 1.4.304.1
          vulkan-components: Vulkan-Headers, Vulkan-Loader
          vulkan-use-cache: true

      - name: Update glslang external sources
        working-directory: ${{env.TEST_ROOT}}/3rdparty/glslang
        run: python update_glslang_sources.py

      - name: Install clang-20
        run: |
          sudo apt-get update
          sudo apt-get install -y clang-20 clang++-20 lld-20 libc++-20-dev libc++abi-20-dev libvulkan-dev

      - name: Show installed toolchain
        run: |
          clang-20 --version
          clang++-20 --version
          ld.lld-20 --version || ld.lld --version || true
          dpkg -l 'libc++*' || true
          
      - name: Configure CMake
        working-directory: ${{env.TEST_ROOT}}
        run: |
          if [ "${{ secrets.ACTIONS_STEP_DEBUG }}" == "true" ]; then
            cmake -S . -B build-test -G Ninja -DCMAKE_C_COMPILER=clang-20 -DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_BUILD_TYPE=Debug -DMOBILEGL_BUILD_TEST=ON -DMOBILEGL_BUILD_BENCHMARK=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5
          else
            cmake -S . -B build-test -G Ninja -DCMAKE_C_COMPILER=clang-20 -DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_BUILD_TYPE=Release -DMOBILEGL_BUILD_TEST=ON -DMOBILEGL_BUILD_BENCHMARK=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5
          fi
          
      - name: Build
        working-directory: ${{env.TEST_ROOT}}/build-test
        run: cmake --build .

      - name: Test
        working-directory: ${{env.TEST_ROOT}}/build-test/MobileGL/MG_Test
        run: |
          if [ "${{ secrets.ACTIONS_STEP_DEBUG }}" == "true" ]; then
            ctest -V
          else
            ctest
          fi
