name: Packaging(Linux)

on:
  push:
    branches:
      - master
    paths-ignore:
      - 'README.md'
      - 'LICENSE'

  pull_request:
    paths-ignore:
      - 'README.md'
      - 'LICENSE'

env:
  PRODUCT: flameshot
  RELEASE: 1
  # dockerfiles, see https://github.com/flameshot-org/flameshot-dockerfiles
  # docker images, see https://hub.docker.com/r/flameshotorg/ci-building-images
  # flameshotorg/ci-building-images or packpack/packpack
  DOCKER_REPO: flameshotorg/ci-building-images
  PACKPACK_REPO: flameshot-org/packpack
  # available upload services: wetransfer.com, file.io, 0x0.st
  UPLOAD_SERVICE: wetransfer.com

jobs:
  deb-pack:
    name: Build deb on ${{ matrix.dist.name }} ${{ matrix.dist.arch }}
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        dist:
          - {
              name: debian-10,
              os: debian,
              symbol: buster,
              arch: amd64
            }
          - {
              name: debian-10,
              os: debian,
              symbol: buster,
              arch: arm64
            }
          - {
              name: debian-10,
              os: debian,
              symbol: buster,
              arch: armhf
            }
          - {
              name: debian-11,
              os: debian,
              symbol: bullseye,
              arch: amd64
            }
          - {
              name: debian-11,
              os: debian,
              symbol: bullseye,
              arch: arm64
            }
          - {
              name: debian-11,
              os: debian,
              symbol: bullseye,
              arch: armhf
            }
          - {
              name: ubuntu-20.04,
              os: ubuntu,
              symbol: focal,
              arch: amd64
            }
          - {
              name: ubuntu-22.04,
              os: ubuntu,
              symbol: jammy,
              arch: amd64
            }
 
    steps:
      - name: Enable Docker Experimental Features
        run: |
          echo $'{\n  "experimental": true\n}' | sudo tee /etc/docker/daemon.json
          mkdir -p ~/.docker
          echo $'{\n  "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
          sudo service docker restart
          docker version -f '{{.Client.Experimental}}'
          docker version -f '{{.Server.Experimental}}'
          docker buildx version
      - name: Support for ARM via QEMU's user-mode emulation
        # Register binfmt_misc entry for qemu-user-static
        # https://github.com/multiarch/qemu-user-static
        env:
          DOCKER_ARCH: ${{ matrix.dist.arch }}
        run: |
          case ${DOCKER_ARCH} in
            amd64|i386)
              QEMU_ARCH=
              ;;
            arm32*)
              QEMU_ARCH=arm
              ;;
            armhf)
              QEMU_ARCH=arm
              ;;
            arm64*)
              QEMU_ARCH=aarch64
              ;;
            *)
              QEMU_ARCH=${DOCKER_ARCH}
              ;;
          esac
          if [ -n "${QEMU_ARCH}" ]; then
            sudo apt-get -y -qq update
            sudo apt-get -y install qemu binfmt-support qemu-user-static
            docker run --rm --privileged multiarch/qemu-user-static --reset --persistent yes --credential yes
            cat /proc/sys/fs/binfmt_misc/qemu-${QEMU_ARCH}
          fi
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set env & Print flameshot version
        shell: bash
        run: |
          last_committed_tag=$(git tag -l --sort=-v:refname | head -1)
          git_revno=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
          git_hash=$(git rev-parse --short HEAD)
          echo "=======FLAMESHOT VERSION========"
          echo ${last_committed_tag:1}
          echo "Details: ${last_committed_tag}+git${git_revno}.${git_hash}"
          echo "================================"
          echo "VERSION=${last_committed_tag:1}" >> $GITHUB_ENV
      - name: Get packpack tool
        uses: actions/checkout@v3
        with:
          repository: ${{ env.PACKPACK_REPO }}
          path: tools
          ref: multiarch
      - name: Packaging on ${{ matrix.dist.name }} ${{ matrix.dist.arch }}
        env:
          OS: ${{ matrix.dist.os }}
          DIST: ${{ matrix.dist.symbol }}
          DOCKER_ARCH: ${{ matrix.dist.arch }}
        run: |
          case ${DOCKER_ARCH} in
            arm32v7)
              export ARCH=arm/v7
              ;;
            armhf)
              export ARCH=arm/v7
              ;;
            arm64*)
              export ARCH=arm64
              ;;
            *)
              export ARCH=${DOCKER_ARCH}
              ;;
          esac
          cp -r $GITHUB_WORKSPACE/packaging/debian $GITHUB_WORKSPACE
          bash $GITHUB_WORKSPACE/tools/packpack
          mv $GITHUB_WORKSPACE/build/${PRODUCT}_${VERSION}-${RELEASE}_${{ matrix.dist.arch }}.deb $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb
      - name: In order to unset the registered formats, and unload the binaries
        env:
          DOCKER_ARCH: ${{ matrix.dist.arch }}
        run: |
          case ${DOCKER_ARCH} in
            amd64|i386)
              QEMU_ARCH=
              ;;
            arm32*)
              QEMU_ARCH=arm
              ;;
            arm64*)
              QEMU_ARCH=aarch64
              ;;
            *)
              QEMU_ARCH=${DOCKER_ARCH}
              ;;
          esac
          if [ -n "${QEMU_ARCH}" ]; then
            docker run --rm --privileged --volume qemu-user-static:/usr/bin:ro multiarch/qemu-user-static:register --reset
          fi
      - name: SHA256Sum of ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb.sha256sum
          echo "=============${{ matrix.dist.name }} ${{ matrix.dist.arch }} sha256sum download link============"
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb.sha256sum)
          echo "========no operation for you can see link in the log console======="
      - name: Upload ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        run: |
          echo "================${{ matrix.dist.name }} ${{ matrix.dist.arch }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.${{ matrix.dist.name }}.${{ matrix.dist.arch }}.deb.sha256sum

  rpm-pack:
    name: Build rpm on ${{ matrix.dist.name }} ${{ matrix.dist.arch }}
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        dist:
          - {
              name: fedora-35,
              os: fedora,
              symbol: 35,
              arch: x86_64
            }
          - {
              name: fedora-36,
              os: fedora,
              symbol: 36,
              arch: x86_64
            }
          - {
              name: opensuse-leap-15.2,
              os: opensuse-leap,
              symbol: 15.2,
              arch: x86_64
            }
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set env & Print flameshot version
        shell: bash
        run: |
          last_committed_tag=$(git tag -l --sort=-v:refname | head -1)
          git_revno=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
          git_hash=$(git rev-parse --short HEAD)
          echo "=======FLAMESHOT VERSION========"
          echo ${last_committed_tag:1}
          echo "Details: ${last_committed_tag}+git${git_revno}.${git_hash}"
          echo "================================"
          echo "VERSION=${last_committed_tag:1}" >> $GITHUB_ENV
      - name: Get packpack tool
        uses: actions/checkout@v3
        with:
          repository: ${{ env.PACKPACK_REPO }}
          path: tools
          ref: master
      - name: Packaging on ${{ matrix.dist.name }} ${{ matrix.dist.arch }}
        run: |
          cp -r $GITHUB_WORKSPACE/packaging/rpm $GITHUB_WORKSPACE
          bash $GITHUB_WORKSPACE/tools/packpack
        env:
          OS: ${{ matrix.dist.os }}
          DIST: ${{ matrix.dist.symbol }}
      - name: Package Clean
        if: matrix.dist.os == 'fedora'
        run: |
          rm -f ${{ github.workspace }}/build/${{ env.PRODUCT }}-debuginfo-*.rpm
          rm -f ${{ github.workspace }}/build/${{ env.PRODUCT }}-debugsource-*.rpm
          rm -f ${{ github.workspace }}/build/${{ env.PRODUCT }}-*.src.rpm
          rm -f ${{ github.workspace }}/build/build.log
      - name: SHA256Sum of ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        if: matrix.dist.os == 'fedora'
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${{ matrix.dist.arch }}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${{ matrix.dist.arch }}.rpm > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm.sha256sum
          echo "============${{ matrix.dist.name }} ${{ matrix.dist.arch }} sha256sum download link============"
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${{ matrix.dist.arch }}.rpm.sha256sum)
          echo "=======no operation for you can see link in the log console======="
      - name: SHA256Sum of ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        if: matrix.dist.os == 'opensuse-leap'
        run: |
          mv $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-lp*.${{ matrix.dist.arch }}.rpm $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm.sha256sum
          echo "============${{ matrix.dist.name }} ${{ matrix.dist.arch }} sha256sum download link==========="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm.sha256sum)
          echo "=======no operation for you can see link in the log console======"
      - name: Upload ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        if: matrix.dist.os == 'fedora'
        run: |
          echo "================${{ matrix.dist.name }} ${{ matrix.dist.arch }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${{ matrix.dist.arch }}.rpm)
          echo "======no operation for you can see link in the log console====="
      - name: Upload ${{ matrix.dist.name }} ${{ matrix.dist.arch }} package(daily build)
        if: matrix.dist.os == 'opensuse-leap'
        run: |
          echo "================${{ matrix.dist.name }} ${{ matrix.dist.arch }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        if: matrix.dist.os == 'fedora'
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/

      - name: Artifact Upload
        if: matrix.dist.os == 'opensuse-leap'
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-lp${{ matrix.dist.symbol }}.${{ matrix.dist.arch }}.rpm.sha256sum

  appimage-pack:
    name: Build appimage on ${{ matrix.config.name }}
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        config:
          - {
              name: ubuntu-20.04,
              os: ubuntu,
              symbol: focal,
              arch: amd64,
              image_repo: flameshotorg/ci-building-images
            }
    container:
      image: ${{ matrix.config.image_repo }}:${{ matrix.config.os }}-${{ matrix.config.symbol }}
      options: --cap-add SYS_ADMIN --device /dev/fuse --security-opt apparmor:unconfined
    steps:
      - name:
        shell: bash
        run: |
          git config --global --add safe.directory "$GITHUB_WORKSPACE"

      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set env & Print flameshot version
        shell: bash
        run: |
          last_committed_tag=$(git tag -l --sort=-v:refname | head -1)
          git_revno=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
          git_hash=$(git rev-parse --short HEAD)
          echo "=======FLAMESHOT VERSION========"
          echo ${last_committed_tag:1}
          echo "Details: ${last_committed_tag}+git${git_revno}.${git_hash}"
          echo "================================"
          echo "VERSION=${last_committed_tag:1}" >> $GITHUB_ENV
      - name: Install Dependencies
        run: |
          sudo apt-get -y -qq update
          sudo apt-get -y --no-install-recommends install \
            python3 \
            python3-pip \
            fuse \
            patchelf \
            cmake \
            extra-cmake-modules \
            build-essential \
            qt5-default \
            qttools5-dev-tools \
            qttools5-dev \
            libqt5dbus5 \
            libqt5network5 \
            libqt5core5a \
            libqt5widgets5 \
            libqt5gui5 \
            libqt5svg5-dev \
            appstream \
            hicolor-icon-theme \
            fcitx-frontend-qt5 \
            openssl \
            ca-certificates \
            jq


      - name: Get go-appimage tool
      # Will not use linuxdeployqt anymore, because it suopprts currently still-supported mainstream distribution,
      # which is glibc 2.23. For more information, please see https://github.com/probonopd/linuxdeployqt/issues/340.
      # Will try new tool https://github.com/probonopd/go-appimage written in golang by probonopd.
        run: |
          wget $(curl https://api.github.com/repos/probonopd/go-appimage/releases | jq -r '.[] | select(.tag_name == "continuous") | .assets[] | select((.name | endswith("x86_64.AppImage")) and (.name | contains("appimagetool"))) | .browser_download_url') -O appimagetool

          chmod +x appimagetool
        env:
          APPIMAGETOOL_ARCH: x86_64
      - name: Packaging appimage
        run: |
          APPIMAGE_DST_PATH=$GITHUB_WORKSPACE/${PRODUCT}.AppDir
          mkdir -p ${APPIMAGE_DST_PATH}

          cd $GITHUB_WORKSPACE
          cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DUSE_LAUNCHER_ABSOLUTE_PATH:BOOL=OFF
          make -j$(nproc) DESTDIR=${APPIMAGE_DST_PATH} install

          $GITHUB_WORKSPACE/appimagetool -s deploy ${APPIMAGE_DST_PATH}/usr/share/applications/org.flameshot.Flameshot.desktop

          mkdir -p ${APPIMAGE_DST_PATH}/usr/plugins/platforminputcontexts
          cp \
            /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so \
            ${APPIMAGE_DST_PATH}/usr/plugins/platforminputcontexts/

          cp \
            $GITHUB_WORKSPACE/data/img/app/org.flameshot.Flameshot.png \
            ${APPIMAGE_DST_PATH}/

          if [ -f "${APPIMAGE_DST_PATH}/lib/x86_64-linux-gnu/libxcb-glx.so.0" ]; then
            rm ${APPIMAGE_DST_PATH}/lib/x86_64-linux-gnu/libxcb-glx.so.0
          fi

          chmod +x ${APPIMAGE_DST_PATH}/usr/lib64/ld-*.so.*

          VERSION=${VERSION} $GITHUB_WORKSPACE/appimagetool ${APPIMAGE_DST_PATH}
          mv $GITHUB_WORKSPACE/Flameshot-${VERSION}-x86_64.AppImage $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage
      - name: SHA256Sum of appimage package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage
          sha256sum $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage > $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage.sha256sum
          echo "================appimage sha256sum download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage.sha256sum)
          echo "======no operation for you can see link in the log console====="
      - name: Upload appimage package for daily build
        run: |
          echo "====================appimage download link====================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/Flameshot-${VERSION}.x86_64.AppImage)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/Flameshot-*.x86_64.AppImage
            ${{ github.workspace }}/Flameshot-*.x86_64.AppImage.sha256sum

  flatpak-pack:
    name: Build flatpak on ubuntu-20.04
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set env & Print flameshot version
        shell: bash
        run: |
          last_committed_tag=$(git tag -l --sort=-v:refname | head -1)
          git_revno=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
          git_hash=$(git rev-parse --short HEAD)
          echo "=======FLAMESHOT VERSION========"
          echo ${last_committed_tag:1}
          echo "Details: ${last_committed_tag}+git${git_revno}.${git_hash}"
          echo "================================"
          echo "VERSION=${last_committed_tag:1}" >> $GITHUB_ENV
      - name: Setup flatpak
        run: |
          sudo apt-get -y -qq update
          sudo apt-get install -y flatpak flatpak-builder
      - name: Setup Flathub
        run: |
          flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
          flatpak install -y --noninteractive flathub org.kde.Sdk//5.15 org.kde.Platform//5.15
      - name: Packaging flatpak
        run: |
          BUNDLE="org.flameshot.Flameshot_${VERSION}_x86_64.flatpak"
          MANIFEST_PATH=$GITHUB_WORKSPACE/packaging/flatpak/org.flameshot.Flameshot.yml
          RUNTIME_REPO="https://flathub.org/repo/flathub.flatpakrepo"
          APP_ID="org.flameshot.Flameshot"
          BRANCH="master"

          flatpak-builder --user --disable-rofiles-fuse --repo=repo --force-clean flatpak_app ${MANIFEST_PATH} --install-deps-from=flathub
          flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${APP_ID} ${BRANCH}
          mv $GITHUB_WORKSPACE/org.flameshot.Flameshot_${VERSION}_x86_64.flatpak $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak
      - name: SHA256Sum of flatpak package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak
          sha256sum $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak > $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak.sha256sum
          echo "================flatpak sha256sum download link===================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak.sha256sum)
          echo "========no operation for you can see link in the log console======="
      - name: Upload flatpak package(daily build)
        run: |
          echo "=====================flatpak download link====================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.x86_64.flatpak)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/org.flameshot.Flameshot-*.x86_64.flatpak
            ${{ github.workspace }}/org.flameshot.Flameshot-*.x86_64.flatpak.sha256sum

  snap-pack:
    name: Build snap on ubuntu-20.04
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set env & Print flameshot version
        shell: bash
        run: |
          last_committed_tag=$(git tag -l --sort=-v:refname | head -1)
          git_revno=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
          git_hash=$(git rev-parse --short HEAD)
          echo "=======FLAMESHOT VERSION========"
          echo ${last_committed_tag:1}
          echo "Details: ${last_committed_tag}+git${git_revno}.${git_hash}"
          echo "================================"
          echo "VERSION=${last_committed_tag:1}" >> $GITHUB_ENV
      - name: Packaging snap
        uses: snapcore/action-build@v1
        id: snapcraft
        with: 
          snapcraft-args: --enable-experimental-extensions
      - name: Rename snap name
        shell: bash
        run: |
          mkdir -p $GITHUB_WORKSPACE/build
          cp ${{ steps.snapcraft.outputs.snap }} $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap
      - name: SHA256Sum of snap package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap.sha256sum
          echo "================snap sha256sum download link=================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap.sha256sum)
          echo "=====no operation for you can see link in the log console====="
      - name: Upload snap package(daily build)
        run: |
          echo "=======================snap download link======================"
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.amd64.snap)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v3
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.amd64.snap
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.amd64.snap.sha256sum
