name: Build

on:
  push:
    branches:
      - main
      - master
  pull_request:

jobs:
  arch-build:
    runs-on: ubuntu-24.04

    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Build in Arch Linux container
        run: |
          docker run --rm \
            -v "${GITHUB_WORKSPACE}:/workspace" \
            -w /workspace \
            archlinux:latest \
            bash -lc '
              set -euo pipefail
              pacman -Syu --noconfirm
              pacman -S --noconfirm --needed \
                base-devel \
                cmake \
                git \
                qt6-base \
                qt6-declarative \
                qt6-tools \
                qt6-multimedia \
                qt6-multimedia-ffmpeg
              cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
              cmake --build build -j"$(nproc)"
              export QT_QPA_PLATFORM=offscreen
              export QT_MEDIA_BACKEND=ffmpeg
              ctest --test-dir build --output-on-failure
              "$(/usr/lib/qt6/bin/qtpaths6 --query QT_INSTALL_BINS)/qmllint" src/qml/Main.qml src/qml/components/*.qml src/qml/theme/BearTheme.qml
            '

  flatpak-build:
    runs-on: ubuntu-24.04

    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Build Flatpak manifest
        run: |
          set -euo pipefail
          sudo apt-get update
          sudo apt-get install -y flatpak flatpak-builder
          flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
          flatpak install --user -y flathub org.kde.Sdk//6.10 org.kde.Platform//6.10
          flatpak-builder --user --force-clean flatpak_build de.nerdbear.bearwave.json
          grep -q '"runtime-version" : "6.10"' flatpak_build/files/manifest.json
          test "$(grep '^runtime=' flatpak_build/metadata)" = "runtime=org.kde.Platform/x86_64/6.10"
