name: Wasm

on:
  push:
    branches: [ "main" ]
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '18'

    - name: Install Qt
      uses: jurplel/install-qt-action@v4
      with:
        version: '6.5.3'
        host: 'linux'
        arch: 'wasm_multithread'
        modules: 'qtwebsockets'

    - name: Setup emsdk
      uses: mymindstorm/setup-emsdk@v14
      with:
        version: '3.1.25'

    - name: Configure and Build
      shell: bash
      run: |
        source $EMSDK/emsdk_env.sh
        $QT_ROOT_DIR/bin/qt-cmake -S . -B build \
          -DBUILD_WITH_QT6=ON \
          -DBUILD_TESTING=ON \
          -DCMAKE_BUILD_TYPE=Release \
          -DQT_HOST_PATH=$QT_HOST_PATH
        cmake --build build --parallel

    - name: Run tests
      shell: bash
      run: |
        source $EMSDK/emsdk_env.sh
        cd build
        ctest -V --no-compress-output
