name: "Continuous build (Linux)"

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - 'continuous*'

jobs:
  build:
    strategy:
      matrix:
        include:
          - os: ubuntu-22.04
            arch: x86_64
            host: x86_64-linux-gnu
            pkgarch: amd64
            dependencies: g++-multilib meson nasm wget wine64-tools yasm

          - os: ubuntu-22.04
            arch: i686
            host: i386-linux-gnu
            pkgarch: i386
            dependencies: g++-multilib meson nasm wget wine32-tools yasm

          - os: ubuntu-22.04
            arch: armhf
            host: arm-linux-gnueabihf
            pkgarch: armhf
            dependencies: g++-arm-linux-gnueabihf meson nasm qemu qemu-user-static wget yasm

          - os: ubuntu-22.04
            arch: aarch64
            host: aarch64-linux-gnu
            pkgarch: arm64
            dependencies: g++-aarch64-linux-gnu meson nasm qemu qemu-user-static wget yasm

          - os: ubuntu-22.04
            arch: riscv64
            host: riscv64-linux-gnu
            pkgarch: riscv64
            dependencies: g++-riscv64-linux-gnu meson nasm qemu qemu-user-static wget yasm

          - os: ubuntu-22.04
            arch: ppc64el
            host: powerpc64le-linux-gnu
            pkgarch: ppc64el
            dependencies: g++-powerpc64le-linux-gnu meson nasm qemu qemu-user-static wget yasm

      fail-fast: false

    runs-on: ${{ matrix.os }}

    steps:
      - name: Add architectures
        run: |
          if [ ${{ matrix.arch }} = x86_64 ]; then
            sudo dpkg --add-architecture i386
          else
            sudo dpkg --add-architecture ${{ matrix.pkgarch }}
          fi

      - name: Prepare sources
        if: ${{ matrix.arch != 'i686' && matrix.arch != 'x86_64' }}
        run: |
          echo "deb [arch=${{ matrix.pkgarch }}] http://ports.ubuntu.com/ubuntu-ports jammy main restricted" | sudo tee --append /etc/apt/sources.list > /dev/null
          echo "deb [arch=${{ matrix.pkgarch }}] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted" | sudo tee --append /etc/apt/sources.list > /dev/null
          echo "deb [arch=${{ matrix.pkgarch }}] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted" | sudo tee --append /etc/apt/sources.list > /dev/null
          sudo sed -i 's/deb http/deb \[arch=amd64,i386\] http/g' /etc/apt/sources.list
          sudo sed -i 's/deb mirror/deb \[arch=amd64,i386\] mirror/g' /etc/apt/sources.list

      - name: Install dependencies
        run: |
          sudo apt update
          sudo apt install -y ${{ matrix.dependencies }}
          sudo apt install -y adwaita-icon-theme gnome-icon-theme libasound2-dev:${{ matrix.pkgarch }} libgdk-pixbuf2.0-dev:${{ matrix.pkgarch }} libgtk-3-dev:${{ matrix.pkgarch }} liblzma-dev:${{ matrix.pkgarch }} libncurses-dev:${{ matrix.pkgarch }} libpulse-dev:${{ matrix.pkgarch }} libssl-dev:${{ matrix.pkgarch }} libudev-dev:${{ matrix.pkgarch }} libzstd-dev:${{ matrix.pkgarch }}

      - name: Prepare toolchain
        if: ${{ matrix.arch != 'i686' && matrix.arch != 'x86_64' }}
        run: |
          sudo rm -f /usr/bin/gcc /usr/bin/g++ /usr/bin/cpp /usr/bin/ld /usr/bin/strip
          sudo ln -s ${{ matrix.host }}-gcc /usr/bin/gcc
          sudo ln -s ${{ matrix.host }}-g++ /usr/bin/g++
          sudo ln -s ${{ matrix.host }}-cpp /usr/bin/cpp
          sudo ln -s ${{ matrix.host }}-ld /usr/bin/ld
          sudo ln -s ${{ matrix.host }}-strip /usr/bin/strip

      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          submodules: recursive

      - name: Build AppImage
        env:
          AppImageArch: ${{ matrix.arch }}
          RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
        run: |
          .github/workflows/tools/build-appimage
