name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  build-test:
    name: build-test (${{ matrix.compiler }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        compiler: [gcc, clang]
    steps:
      - uses: actions/checkout@v5

      - name: Install common build dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            cmake \
            ninja-build \
            qt6-base-dev \
            qt6-base-dev-tools \
            qt6-tools-dev \
            qt6-tools-dev-tools

      - name: Install GCC 14
        if: matrix.compiler == 'gcc'
        run: sudo apt-get install -y gcc-14 g++-14

      - name: Install Clang
        if: matrix.compiler == 'clang'
        run: sudo apt-get install -y clang

      - name: Configure (GCC)
        if: matrix.compiler == 'gcc'
        run: |
          cmake -S . -B build -G Ninja \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_C_COMPILER=gcc-14 \
            -DCMAKE_CXX_COMPILER=g++-14 \
            -DBUILD_TESTS=ON

      - name: Configure (Clang)
        if: matrix.compiler == 'clang'
        run: |
          cmake -S . -B build -G Ninja \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_C_COMPILER=clang \
            -DCMAKE_CXX_COMPILER=clang++ \
            -DBUILD_TESTS=ON

      - name: Build
        run: cmake --build build --parallel

      - name: Test
        env:
          QT_QPA_PLATFORM: offscreen
        run: ctest --test-dir build --output-on-failure

  debian-package-check:
    name: debian package build canary
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Install packaging dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            devscripts \
            debhelper \
            build-essential \
            cmake \
            ninja-build \
            qt6-base-dev \
            qt6-base-dev-tools \
            qt6-tools-dev \
            qt6-tools-dev-tools

      - name: Build binary package (unsigned)
        run: debuild -us -uc -b
