name: Setup Linux dependencies
description: Install and setup dependencies for building Prism Launcher

runs:
  using: composite

  steps:
    - name: Install host dependencies
      shell: bash
      run: |
        sudo apt-get -y update
        sudo apt-get -y install \
          dpkg-dev \
          ninja-build extra-cmake-modules pkg-config scdoc \
          cmark gamemode-dev libarchive-dev libcmark-dev libqrencode-dev zlib1g-dev \
          libxcb-cursor-dev libtomlplusplus-dev

    - name: Setup AppImage tooling
      shell: bash
      env:
        GH_TOKEN: ${{ github.token }}
      run: |
        # Determinate AppImage architecture to use
        dpkg_arch="$(dpkg-architecture -q DEB_HOST_ARCH_CPU)"
        case "$dpkg_arch" in
          "amd64")
            APPIMAGE_ARCH="x86_64"
            ;;
          "arm64")
            APPIMAGE_ARCH="aarch64"
            ;;
          *)
            echo "# 🚨 The Debian architecture \"$deb_arch\" is not recognized!" >> "$GITHUB_STEP_SUMMARY"
            exit 1
            ;;
        esac

        gh release download \
          --repo VHSgunzo/sharun \
          --pattern "sharun-$APPIMAGE_ARCH-aio" \
          --output ~/bin/sharun

        # FIXME!: revert this to probonopd/go-appimage once https://github.com/probonopd/go-appimage/pull/377 is merged!
        gh release download continuous \
          --repo DioEgizio/go-appimage \
          --pattern "mkappimage-*-$APPIMAGE_ARCH.AppImage" \
          --output ~/bin/mkappimage

        gh release download \
          --repo AppImageCommunity/AppImageUpdate \
          --pattern "AppImageUpdate-$APPIMAGE_ARCH.AppImage" \
          --output ~/bin/AppImageUpdate.AppImage
        chmod +x ~/bin/*
        echo "$HOME/bin" >> "$GITHUB_PATH"
