name: Build Artifacts (DEB)
on:
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'
        required: true
        default: 'warning'
        type: choice
        options:
        - info
        - warning
        - debug
      tags:
        description: 'Test scenario tags'
        required: false
        type: boolean
  pull_request:
    branches: [master, develop]
    paths-ignore:
    - '**/*.md'
    - '.circleci/**'
    - '.cirrus.yml'
  push:
    branches: [master, develop]
    paths-ignore:
    - '**/*.md'
    - '.circleci/**'
    - '.cirrus.yml'
  release:
    types: [published]
  schedule:
    - cron: '0 16 * * *'
concurrency:
  group: ${{ github.workflow }} / ${{ startsWith(github.event_name, 'pull') && github.ref_name || github.run_id }}
  cancel-in-progress: ${{ startsWith(github.event_name, 'pull') }}
env:
  CACHE_EPOCH: 148-2
  GOPROXY: direct
  DH_QUIET: 1
jobs:
  deb-release:
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        distro: [xenial]
        arch: [amd64, i386]
        gui_variant: [gtk3, qt5]
        include:
          - distro: bionic
            arch: arm64
            gui_variant: gtk3
          - distro: trixie
            arch: riscv64
            gui_variant: gtk3
          - distro: sid
            arch: loong64
            gui_variant: gtk3
          - distro: jammy
            arch: amd64
            gui_variant: gtk4
            use_cet: true
          - distro: jammy
            arch: amd64
            gui_variant: qt6
            use_cet: true
        # XFAIL stretch
        # XFAIL focal-i386,jammy-i386,noble-i386
        # distro: [trusty, xenial, bionic, focal, jammy, noble, stretch, buster, bullseye, bookworm]
        # arch: [i386, amd64, armhf, arm64]
        # include:
        #   - distro: stretch
        #     arch: armel
        #   - distro: stretch
        #     arch: mipsel
        #   - distro: stretch
        #     arch: mips64el
    env:
      DEBIAN_FRONTEND: 'noninteractive'
      HOST_ARCH: '${{ matrix.arch }}'
      HOST_DISTRO: '${{ matrix.distro }}'
    steps:
      - uses: actions/checkout@v5
      - name: Checkout with shallow submodules
        run: |
          # unshallow must come first otherwise submodule may be get unshallowed
          git fetch --tags --unshallow
          git submodule update --init --depth 1
      - name: Patch libcxxabi for both of armel and armhf
        if: ${{ matrix.arch == 'armel' || matrix.arch == 'armhf' }}
        run: |
          cd third_party/libc++abi
          patch -p1 < v8-6.7.17-fix-gcc-unwind-header.patch
      - name: Cache toolchain
        id: toolchain-cache
        uses: actions/cache@v5
        with:
          path: |
            third_party/llvm-build/Release+Asserts
          key: ${{ runner.os }}-toolchain-${{ hashFiles('CLANG_REVISION') }}-v${{ env.CACHE_EPOCH }}
      - name: Cache cmake
        id: cmake-cache
        uses: actions/cache@v5
        with:
          path: |
            cmake*.tar.gz
          key: ${{ runner.os }}-cmake-3-29-8
      - name: "Install dependency: prebuilt clang and clang-tidy binaries"
        if: ${{ steps.toolchain-cache.outputs.cache-hit != 'true' }}
        run: |
          ./scripts/download-clang-prebuilt-binaries.py
          rm -f third_party/llvm-build/Release+Asserts/*.tgz
      - name: "Install dependency: cmake cache"
        if: ${{ steps.cmake-cache.outputs.cache-hit != 'true' }}
        run: |
          wget https://github.com/Kitware/CMake/releases/download/v3.29.8/cmake-3.29.8-linux-x86_64.tar.gz
      - name: Change ubuntu mirror
        run: |
          sudo sed -i 's/azure.archive.ubuntu.com/azure.archive.ubuntu.com/g' /etc/apt/sources.list
          sudo apt-get update -qq
      - name: Populate dependencies (debian keyring, for debian distributions)
        run: |
          curl -O http://ftp.us.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2025.1_all.deb
          sudo apt-get update -qq && sudo apt-get install -f -y $PWD/debian*.deb
          rm -f *.deb
      - name: Populate dependencies (sbuild, debhelper, schroot, debootstrap and ubuntu-dev-tools)
        run: |
          sudo apt-get update -qq
          sudo apt-get install -y sbuild debhelper schroot debootstrap ubuntu-dev-tools qemu-user-static
      - name: Copy sbuilrc
        run: |
          cp -fv sbuildrc ~/.sbuildrc
          sudo usermod -aG sudo "$USER"
          sudo usermod -aG sbuild "$USER"
          sudo chown -R sbuild:sbuild /var/lib/sbuild/
          sudo chmod g+rws /var/lib/sbuild/
      - name: Pre-Populate sysroot (distro option)
        if: ${{ matrix.distro == 'stretch' || matrix.distro == 'buster' || matrix.distro == 'bullseye' || matrix.distro == 'bookworm' || matrix.distro == 'trixie' || matrix.distro == 'forky' || matrix.distro == 'sid' }}
        run: |
          echo "mksbuild_distro_opts=--distro=debian" >> $GITHUB_ENV
      - name: Pre-Populate BUILD_ARCH (i386)
        if: ${{ matrix.arch == 'i386' }}
        run: |
          echo "mksbuild_arch_opts=--arch=i386" >> $GITHUB_ENV
          echo "BUILD_ARCH=i386" >> $GITHUB_ENV
      - name: Pre-Populate BUILD_ARCH (amd64)
        if: ${{ matrix.arch != 'i386' }}
        run: |
          echo "mksbuild_arch_opts=--arch=amd64" >> $GITHUB_ENV
          echo "BUILD_ARCH=$(dpkg-architecture -q DEB_BUILD_ARCH)" >> $GITHUB_ENV
      - name: Set check build profile
        if: ${{ matrix.arch == 'i386' || matrix.arch == 'amd64' }}
        run: |
          echo "DEB_BUILD_PROFILES=check ${{ env.DEB_BUILD_PROFILES }}" >> $GITHUB_ENV
      - name: Set cross build profile
        if: ${{ matrix.arch != 'i386' && matrix.arch != 'amd64' }}
        run: |
          echo "DEB_BUILD_PROFILES=nocheck cross ${{ env.DEB_BUILD_PROFILES }}" >> $GITHUB_ENV
      - name: Set gui build profile (none of armel/mipsel/mips64el)
        if: ${{ matrix.gui_variant != 'none' }}
        run: |
          echo "DEB_BUILD_PROFILES=${{ matrix.gui_variant }} ${{ env.DEB_BUILD_PROFILES }}" >> $GITHUB_ENV
          echo "APT_DEB_BUILD_PROFILES=-o Apt::Build-Profiles=${{ matrix.gui_variant }}" >> $GITHUB_ENV
      - name: Set clang build profile
        run: |
          echo "DEB_BUILD_PROFILES=clang ${{ env.DEB_BUILD_PROFILES }}" >> $GITHUB_ENV
          echo "CC=${{ github.workspace }}/third_party/llvm-build/Release+Asserts/bin/clang" >> $GITHUB_ENV
          echo "CXX=${{ github.workspace }}/third_party/llvm-build/Release+Asserts/bin/clang++" >> $GITHUB_ENV
          echo "AR=${{ github.workspace }}/third_party/llvm-build/Release+Asserts/bin/llvm-ar" >> $GITHUB_ENV
          echo "RANLIB=${{ github.workspace }}/third_party/llvm-build/Release+Asserts/bin/llvm-ranlib" >> $GITHUB_ENV
      - name: Set cet build profile
        if: ${{ matrix.use_cet == true }}
        run: |
          echo "DEB_BUILD_PROFILES=cet ${{ env.DEB_BUILD_PROFILES }}" >> $GITHUB_ENV
      - name: Fix schroot permissions (set store permissions for restore)
        run: |
          sudo mkdir -p /etc/schroot/chroot.d /var/lib/schroot/chroots
          sudo chown -R $USER:sbuild /etc/schroot/chroot.d /var/lib/schroot/chroots
      - name: Cache schroot
        id: schroot-cache
        uses: actions/cache@v5
        with:
          path: |
            /etc/schroot/chroot.d
            /var/lib/schroot/chroots
          key: ${{ runner.os }}-24.04-schroot-${{ matrix.distro }}-${{ matrix.arch }}-v2-loong64-gtk3
      - name: Fix schroot permissions (restore root permissions)
        run: |
          sudo chown -R root:root /etc/schroot/chroot.d /var/lib/schroot/chroots
      # mk-sbuild may fail due to the missing pkg-config-<gnu-type>, but it
      # should be fine, will create pkg-config shim in next step
      - name: Populate sysroot
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo -n sudo -u "$USER" -g sbuild mk-sbuild ${{ env.mksbuild_arch_opts }} ${{ matrix.distro }} --target=${{ matrix.arch }} ${{ env.mksbuild_distro_opts }} || true
          sudo sed -i '/profile/d' /etc/schroot/chroot.d/*
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get clean
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get update -qq
      - name: Populate sysroot (crosscompile toolchain)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch != 'i386' && matrix.arch != 'amd64' }}
        run: |
          export HOST_GNU_TYPE=$(dpkg-architecture -a ${{ matrix.arch }} -q DEB_HOST_GNU_TYPE)
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            dpkg --add-architecture ${{ matrix.arch }}
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get update -qq
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y dpkg-cross pkg-config gcc-$HOST_GNU_TYPE g++-$HOST_GNU_TYPE libc6:${{ matrix.arch }} libstdc++6:${{ matrix.arch }} linux-libc-dev:${{ matrix.arch }}
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            ln -sf /usr/share/pkg-config-crosswrapper /usr/bin/${HOST_GNU_TYPE}-pkg-config
      - name: Populate sysroot (crosscompile toolchain, for bookworm and later distro)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch != 'i386' && matrix.arch != 'amd64' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "[ ! -f /usr/share/pkg-config-crosswrapper ] && cp -v $PWD/debian/pkg-config-crosswrapper /usr/share/pkg-config-crosswrapper || :"
      - name: Populate sysroot (standard toolchain)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y fakeroot advancecomp apt-utils file build-essential pkg-config debhelper lockfile-progs optipng tzdata ucf
      - name: Populate sysroot (amd64 runtime for clang)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch == 'i386' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            cp -f /etc/apt/sources.list /etc/apt/sources.list.amd64
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            sed -i s/i386/amd64/g /etc/apt/sources.list.amd64
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "cat /etc/apt/sources.list /etc/apt/sources.list.amd64 | tee /tmp/sources.list"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            mv -f /tmp/sources.list /etc/apt/sources.list
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            dpkg --add-architecture amd64
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get update -qq
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y libc6:amd64 libstdc++6:amd64 zlib1g:amd64
      - name: Populate sysroot (ca-certificates, git)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y ca-certificates git
      - name: Populate sysroot (golang, new distro)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.distro != 'trusty' && matrix.distro != 'xenial' && matrix.distro != 'bionic' && matrix.distro != 'stretch' && matrix.distro != 'buster' && matrix.distro != 'bullseye' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y golang
      - name: Populate sysroot (golang, old distro)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && (matrix.distro == 'trusty' || matrix.distro == 'xenial' || matrix.distro == 'bionic' || matrix.distro == 'stretch' || matrix.distro == 'buster' || matrix.distro == 'bullseye') }}
        run: |
          # shipped with debian bullseye
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-defaults/golang_1.15~1_${{ env.BUILD_ARCH }}.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-defaults/golang-go_1.15~1_${{ env.BUILD_ARCH }}.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-defaults/golang-src_1.15~1_${{ env.BUILD_ARCH }}.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-defaults/golang-doc_1.15~1_all.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-1.15/golang-1.15_1.15.15-1~deb11u4_all.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-1.15/golang-1.15-go_1.15.15-1~deb11u4_${{ env.BUILD_ARCH }}.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-1.15/golang-1.15-src_1.15.15-1~deb11u4_${{ env.BUILD_ARCH }}.deb
          curl -O http://ftp.us.debian.org/debian/pool/main/g/golang-1.15/golang-1.15-doc_1.15.15-1~deb11u4_all.deb
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            dpkg --force-depends -i $PWD/*.deb || true
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y -f
          rm -f *.deb
      - name: Populate dependencie (cmake)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y cmake ninja-build
      - name: Populate dependencie (cmake, overwrite)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            tar -C /usr/local --strip-components=1 -xf cmake-3.29.8-linux-x86_64.tar.gz
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            cmake --version
      - name: Populate dependencie (base)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y perl gcc g++ ninja-build
      - name: Populate dependencie (zlib)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get install -y zlib1g-dev:${{ matrix.arch }}
      - name: Populate dependencie (qt6, x86 only, jammy only)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && (matrix.arch == 'i386' || matrix.arch == 'amd64') && matrix.distro == 'jammy' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get -o DPkg::Options::="--force-confnew" install -y qt6-base-dev:${{ matrix.arch }}
      - name: Populate dependencie (qt5, x86 only)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && (matrix.arch == 'i386' || matrix.arch == 'amd64') }}
        run: |
          export HOST_GNU_TYPE=$(dpkg-architecture -a ${{ matrix.arch }} -q DEB_HOST_GNU_TYPE)
          # DEB_HOST_GNU_TYPE produces i686-linux-gnu which is wrong
          [ "${{ matrix.arch }}" = "i386" ] && export HOST_GNU_TYPE=i386-linux-gnu
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get -o DPkg::Options::="--force-confnew" install -y qtbase5-dev:${{ matrix.arch }}
          # for qt 5.5 or before
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            sed -i 's#Q_DECL_CONSTEXPR inline QFlags(Zero = 0) Q_DECL_NOTHROW : i(0) {}#Q_DECL_CONSTEXPR inline QFlags() Q_DECL_NOTHROW : i(0) {}\n    Q_DECL_CONSTEXPR inline QFlags(Zero) Q_DECL_NOTHROW : i(0) {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtCore/qflags.h
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::WindowFlags f = 0#Qt::WindowFlags f = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::Alignment = 0#Qt::Alignment = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::Alignment alignment = 0#Qt::Alignment alignment = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::WindowFlags f=0#Qt::WindowFlags f = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::WindowFlags flags = 0#Qt::WindowFlags flags = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::WindowFlags flags=0#Qt::WindowFlags flags = {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtWidgets/*.h"
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            bash -c "sed -i 's#Qt::ItemFlags(0)#Qt::ItemFlags()#g' /usr/include/$HOST_GNU_TYPE/qt5/QtCore/*.h"
          # for qt 5.6 or before
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            sed -i 's#Q_DECL_CONSTEXPR inline QFlags(Zero = Q_NULLPTR) Q_DECL_NOTHROW : i(0) {}#Q_DECL_CONSTEXPR inline QFlags() Q_DECL_NOTHROW : i(0) {}\n    Q_DECL_CONSTEXPR inline QFlags(Zero) Q_DECL_NOTHROW : i(0) {}#g' /usr/include/$HOST_GNU_TYPE/qt5/QtCore/qflags.h
          # fix clang after 3847
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            sed -i 's#: integral_constant<bool, (T(0) < T(-1))> {};#: integral_constant<bool, __is_unsigned(T)> {};#g' /usr/include/$HOST_GNU_TYPE/qt5/QtCore/qtypetraits.h
      - name: Populate dependencie (gtk4, jammy only)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch != 'armel' && matrix.arch != 'mipsel' && matrix.arch != 'mips64el' && matrix.arch != 'loong64' && matrix.distro == 'jammy' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get -o DPkg::Options::="--force-confnew" install -y libglib2.0-dev:${{ matrix.arch }} libgtk-4-dev:${{ matrix.arch }}
      - name: Populate dependencie (gtk3, none of armel/mipsel/mips64el)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch != 'armel' && matrix.arch != 'mipsel' && matrix.arch != 'mips64el' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get -o DPkg::Options::="--force-confnew" -o Dpkg::Options::="--force-overwrite" install -y libglib2.0-dev:${{ matrix.arch }} libgtk-3-dev:${{ matrix.arch }}
      - name: Populate dependencie (curl, for test purpose, exclude armel/mipsel/mips64el)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' && matrix.arch != 'armel' && matrix.arch != 'mipsel' && matrix.arch != 'mips64el' }}
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt-get -o DPkg::Options::="--force-confnew" -o Dpkg::Options::="--force-overwrite" install -y libcurl4-openssl-dev:${{ matrix.arch }}
      - name: Populate dependencie (list upgradable packages)
        run: |
          sudo schroot --chroot "source:${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}" --user root -- \
            apt list --upgradeable || true
      - name: Build deb package
        run: |
          export DEB_BUILD_PROFILES
          export DH_QUIET
          sudo -E sudo -E -u "$USER" -g sbuild ./scripts/build-deb.sh
      - uses: actions/upload-artifact@v6
        with:
          name: deb-release-${{ matrix.distro }}-${{ matrix.arch }}-${{ matrix.gui_variant }}-${{ github.run_id }}
          path: |
            yass*.deb
          compression-level: 0 # no compression
      - name: Upload dist tarball (including debuginfo)
        if: ${{ github.event_name == 'release' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release upload --clobber ${{ github.event.release.tag_name }} yass*.deb
      - name: Shutdown schroot sessions
        run: |
          sudo schroot --end-session --all-sessions
      - name: Fix schroot dev nodes permissions
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo rm -rf /var/lib/schroot/chroots/${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}/dev
          sudo rm -rf /var/lib/schroot/chroots/${{ matrix.distro }}-${{ env.BUILD_ARCH }}-${{ matrix.arch }}/run/systemd/dissect-root
      - name: Fix schroot permissions (restore store permissions)
        if: ${{ steps.schroot-cache.outputs.cache-hit != 'true' }}
        run: |
          sudo chown -R $USER /etc/schroot/chroot.d /var/lib/schroot/chroots
