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

permissions: {}

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
    build:
        name: "${{ matrix.os }} Qt ${{ matrix.qt_version }}"
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            qt_version: [6.8.3]
            os: [windows-latest, ubuntu-latest, macos-latest]
        steps:
            - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
              with:
                persist-credentials: false

            - name: install qt 6.x
              uses: jurplel/install-qt-action@48d3ad6db93f3627c8ee7a0454bc6f3744f7e730 # v4.3.1
              with:
                version: ${{ matrix.qt_version }}
                modules: 'qt5compat'

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

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

            - 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"
                  cmake -S . -B build
                  cmake --build 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"
                  ctest --test-dir build
