name: build cutechess
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
    build:
        name: "${{ matrix.os }} Qt ${{ matrix.qt_version }}"
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            qt_version: [5.15.2, 6.5.2]
            os: [windows-latest, ubuntu-latest, macos-latest]
        steps:
            - uses: actions/checkout@v3

            - name: install qt 5.x
              uses: jurplel/install-qt-action@v3
              if: startsWith(matrix.qt_version, '5.')
              with:
                version: ${{ matrix.qt_version }}

            - name: install qt 6.x
              uses: jurplel/install-qt-action@v3
              if: startsWith(matrix.qt_version, '6.')
              with:
                version: ${{ matrix.qt_version }}
                modules: 'qt5compat'

            - name: build cute chess
              if: matrix.os != 'windows-latest'
              run: |
                  mkdir build
                  cd build
                  cmake ..
                  cmake --build .

            - name: run unit tests
              if: matrix.os != 'windows-latest'
              run: |
                  cd build
                  make test

            - name: check manual pages
              if: matrix.os == 'ubuntu-latest'
              run: |
                  sudo apt install mandoc
                  cd ${GITHUB_WORKSPACE}/docs/
                  mandoc -T lint cutechess-cli.6
                  mandoc -T lint cutechess-engines.json.5

            - name: build cute chess
              if: matrix.os == 'windows-latest'
              shell: cmd
              run: |
                  call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
                  mkdir build
                  cd build
                  cmake ..
                  cmake --build . --config release

            - name: run unit tests
              if: matrix.os == 'windows-latest'
              shell: cmd
              run: |
                  call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
                  cd build
                  ctest -C release
