name: Build

on:
  push:
    branches-ignore:
      - "debian/**"
    paths-ignore:
      - "README.md"
      - "**/README.md"
      - "**/index.html"
  pull_request:
    branches-ignore:
      - "debian/**"
    paths-ignore:
      - "README.md"
      - "**/README.md"
      - "**/index.html"
  workflow_dispatch:

env:
  CMAKE_INSTALL_PARALLEL_LEVEL: 4

jobs:
  amd64:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        name: [Ubuntu-22, Ubuntu-24, Ubuntu-26, Debian-13, Debian-12, Debian-Testing, Debian-Experimental]
        cpp_compiler: [g++]
        include:
          - name: Ubuntu-22
            # Uses gcc 12.2.0, cmake 3.24.2
            image: "ubuntu:22.04"
            ubuntu: 22
            deps: cmake g++ libusb-1.0-0-dev qtbase5-dev qttools5-dev pkgconf udev
          - name: Ubuntu-24
            image: "ubuntu:24.04"
            ubuntu: 24
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Ubuntu-26
            image: "ubuntu:26.04"
            ubuntu: 26
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-13
            image: "debian:trixie"
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-13
            image: "debian:trixie"
            c_compiler: clang
            cpp_compiler: clang++
            deps: cmake clang libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-12
            # Uses gcc 12.2.0, clang 15.0.6, cmake 3.25.1
            image: "debian:bookworm"
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools udev
          - name: Debian-12
            image: "debian:bookworm"
            c_compiler: clang
            cpp_compiler: clang++
            deps: cmake clang libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools udev
          - name: Debian-Testing
            image: "debian:testing"
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-Testing
            image: "debian:testing"
            c_compiler: clang
            cpp_compiler: clang++
            deps: cmake clang libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-Experimental
            image: "debian:experimental"
            deps: cmake g++ libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
          - name: Debian-Experimental
            image: "debian:experimental"
            c_compiler: clang
            cpp_compiler: clang++
            deps: cmake clang libusb-1.0-0-dev pkgconf qt6-base-dev qt6-tools-dev linguist-qt6 qt6-l10n-tools qt6-base-dev-tools qt6-tools-dev-tools systemd-dev
    container:
      image: ${{ matrix.image }}
      env:
        LANG: en_US.UTF-8
        BUILD_TYPE: ${{ matrix.build_type }}
        CC: ${{ matrix.c_compiler }}
        CXX: ${{ matrix.cpp_compiler }}
        WITH_PROJ: ON
        APT_LISTCHANGES_FRONTEND: none
        DEBIAN_FRONTEND: noninteractive
    steps:
      - name: Install packages required
        shell: bash
        run: |
          echo "Installing dependencies for ${{ matrix.item }}"
          apt-get update -qq
          apt-get install -yq ${{ matrix.deps }}
      - uses: actions/checkout@v6
      - name: Build
        working-directory: .
        run: |
          cmake -S . -B build/
          cmake --build build/ --parallel
          cmake --install build/

# ... (your existing amd64 job remains unchanged)

  fedora-rpm:
    runs-on: ubuntu-latest
    container:
      image: fedora:44
    steps:
      - name: Checkout source code
        uses: actions/checkout@v6

      - name: Install build dependencies
        run: |
          # Install development tools, linters, and spellcheck dictionaries
          dnf install -y dnf-plugins-core rpm-build rpmlint rpmdevtools wget \
                         hunspell-es hunspell-it hunspell-pt
          # Automatically install all BuildRequires listed in your spec file
          dnf builddep -y rpm/*.spec

      - name: Prepare build environment
        run: |
          # Create the required directory structure for rpmbuild
          mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
          
          # Copy the spec file to the dedicated SPECS directory
          cp rpm/*.spec ~/rpmbuild/SPECS/
          
          # Download the actual source tarball from the URL specified in Source0 of the spec file
          spectool -g -R ~/rpmbuild/SPECS/*.spec

      - name: Build RPM package
        run: |
          rpmbuild -ba ~/rpmbuild/SPECS/*.spec

      - name: Check RPM with rpmlint
        run: |
          # Run rpmlint, but add || true just in case to prevent CI from breaking 
          # on pedantic environment-specific style warnings
          rpmlint ~/rpmbuild/RPMS/*/*.rpm || true

      - name: Upload RPM Artifacts
        uses: actions/upload-artifact@main
        with:
          name: fedora-44-rpm
          path: ~/rpmbuild/RPMS/*/*.rpm
