name: Windows(msys2) Experimental Tests

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:
    inputs:
      debug_enabled:
        type: boolean
        description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
        required: false
        default: false

jobs:
  build:
    strategy:
      matrix:
        qt: [ qt5, qt6 ]
    runs-on: windows-latest
    name: windows-latest ${{ matrix.qt }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup (detached) tmate session if enabled
        uses: mxschmitt/action-tmate@v3
        if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
        with:
          detached: true
      - name: Setup MSYS2 Environment
        uses: msys2/setup-msys2@v2
        with:
          msystem: UCRT64
          update: true
      - name: Install MSYS2 Dependencies
        run: |
          pwd
          ./scripts/msys2-install-dependencies.sh ${{ matrix.qt }}
      - name: Install Mesa
        uses: ssciwr/setup-mesa-dist-win@v2
        with:
          version: '22.1.7'
          build-type: 'release-mingw'
      - name: Build OpenSCAD
        run: |
          git submodule update --init --recursive
          mkdir build && cd build
          cmake .. -G"Ninja" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=ON -DSNAPSHOT=ON -DUSE_QT6=${{ matrix.qt == 'qt6' && 'ON' || 'OFF' }}
          cmake --build . -j4
          cmake --install . --prefix=.
      - name: Run Test Suite
        run: |
          cd build
          ctest -j4
      - name: Setup (detached) tmate session if enabled
        uses: mxschmitt/action-tmate@v3
        if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
      - name: Upload Test Result Report
        uses: actions/upload-artifact@v4
        if: ${{ always() }}
        with:
          name: Test Result Report (Windows ${{ matrix.qt }})
          path: |
            build/Testing/Temporary/*_report.html
            build/Testing/Temporary/LastTest.log
