name: Packaging(Linux)

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

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

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

jobs:
  deb-pack:
    name: ${{ matrix.dist.name }}
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        dist:
          - {
              name: debian-10,
              os: debian,
              symbol: buster
            }
          - {
              name: ubuntu-20.04,
              os: ubuntu,
              symbol: focal
            }
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v2
        with: 
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        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@v2
        with:
          # flameshot-org/packpack or packpack/packpack
          repository: flameshot-org/packpack
          path: tools
      - name: Packaging on ${{ matrix.dist.name }}
        run: |
          cp -r $GITHUB_WORKSPACE/packaging/debian $GITHUB_WORKSPACE
          bash $GITHUB_WORKSPACE/tools/packpack
          mv $GITHUB_WORKSPACE/build/${PRODUCT}_${VERSION}-${RELEASE}_amd64.deb $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb
        env:
          OS: ${{ matrix.dist.os }}
          DIST: ${{ matrix.dist.symbol }}
      - name: SHA256Sum of ${{ matrix.dist.name }} package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb.sha256sum
          echo "=============${{ matrix.dist.name }} sha256sum download link============"
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb.sha256sum)
          echo "========no operation for you can see link in the log console======="
      - name: Upload ${{ matrix.dist.name }} package(daily build)
        run: |
          echo "================${{ matrix.dist.name }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.${{ matrix.dist.name }}.amd64.deb)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v2
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.${{ matrix.dist.name }}.amd64.deb
            ${{ github.workspace }}/build/${{ env.PRODUCT }}-*-${{ env.RELEASE }}.${{ matrix.dist.name }}.amd64.deb.sha256sum

  deb-pack-extra:
    name: ubuntu-18.04(extra job to packaging deb)
    runs-on: ubuntu-20.04
    container:
      image: vitzy/flameshot:ubuntu-bionic
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        # Because git version < 2.18(ubuntu 18.04), so only actions/checkout@v1 can be used.
        # If you use actions/checkout@v2, you will have no .git folder.
        uses: actions/checkout@v1
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v1
        with:
          fetch-depth: 0
          ref: refs/pull/${{ github.event.number }}/head
      - 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: |
          apt-get -y -qq update
          apt-get -y --no-install-recommends install \
            qt5-default \
            qttools5-dev-tools \
            qttools5-dev \
            libqt5dbus5 \
            libqt5network5 \
            libqt5core5a \
            libqt5widgets5 \
            libqt5gui5 \
            libqt5svg5-dev \
            python3 \
            python3-pip
      - name: Prepare cmake(>=3.13.0)
        run: |
          apt-get -y autoremove cmake
          wget https://github.com/Kitware/CMake/releases/download/v3.18.3/cmake-3.18.3-Linux-${ARCH}.tar.gz
          tar -xf cmake-3.18.3-Linux-${ARCH}.tar.gz
          cd ./cmake-3.18.3-Linux-${ARCH}
          cp -r bin /usr/
          cp -r share /usr/
          cp -r doc /usr/share/
          cp -r man /usr/share/
          cd ..
          rm -rf cmake-3.18.3-Linux-${ARCH} cmake-3.18.3-Linux-${ARCH}.tar.gz
          echo "======CMAKE VERSION======"
          cmake --version
          echo "========================="
      - name: Packaging on ubuntu-18.04
        run: |
          cp -r $GITHUB_WORKSPACE/packaging/debian $GITHUB_WORKSPACE
          mkdir -p $GITHUB_WORKSPACE/build
          sed -e "/cmake (>= 3.13~),/d" -i $GITHUB_WORKSPACE/debian/control
          dpkg-buildpackage -b
          cp $GITHUB_WORKSPACE/../${PRODUCT}_*-${RELEASE}_amd64.deb $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb
      - name: SHA256Sum of ubuntu-18.04 package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb.sha256sum
          echo "============ubuntu-18.04 sha256sum download link=============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb.sha256sum)
          echo "=====no operation for you can see link in the log console====="
      - name: Upload ubuntu-18.04 package(daily build)
        run: |
          echo "===================ubuntu-18.04 download link=================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.ubuntu-18.04.amd64.deb)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v2
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/*

  rpm-pack:
    name: ${{ matrix.dist.name }}
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        dist:
          - {
              name: fedora-31,
              os: fedora,
              symbol: 31
            }
          - {
              name: fedora-32,
              os: fedora,
              symbol: 32
            }
          - {
              name: opensuse-leap-15.2,
              os: opensuse-leap,
              symbol: 15.2
            }
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v2
        with: 
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        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@v2
        with:
          # flameshot-org/packpack or packpack/packpack
          repository: flameshot-org/packpack
          path: tools
      - name: Packaging on ${{ matrix.dist.name }}
        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 }} package(daily build)
        if: matrix.dist.os == 'fedora'
        run: |
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${ARCH}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${ARCH}.rpm > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc${{ matrix.dist.symbol }}.${ARCH}.rpm.sha256sum
          echo "============${{ matrix.dist }} sha256sum download link============"
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${ARCH}.rpm.sha256sum)
          echo "=======no operation for you can see link in the log console======="
      - name: SHA256Sum of ${{ matrix.dist.name }} package(daily build)
        if: matrix.dist.os == 'opensuse-leap'
        run: |
          mv $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-lp*.${ARCH}.rpm $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${ARCH}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${ARCH}.rpm
          sha256sum $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${ARCH}.rpm > $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${ARCH}.rpm.sha256sum
          echo "============${{ matrix.dist }} sha256sum download link==========="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${ARCH}.rpm.sha256sum)
          echo "=======no operation for you can see link in the log console======"
      - name: Upload ${{ matrix.dist.name }} package(daily build)
        if: matrix.dist.os == 'fedora'
        run: |
          echo "================${{ matrix.dist.name }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}.fc*.${ARCH}.rpm)
          echo "======no operation for you can see link in the log console====="
      - name: Upload ${{ matrix.dist.name }} package(daily build)
        if: matrix.dist.os == 'opensuse-leap'
        run: |
          echo "================${{ matrix.dist.name }} download link==============="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/build/${PRODUCT}-${VERSION}-${RELEASE}-lp${{ matrix.dist.symbol }}.${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@v2
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/build/

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

  appimage-pack:
    name: appimage
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v2
        with: 
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        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 \
            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
      - 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 the inventor of the AppImage format.
        run: |
          wget -c https://github.com/$(wget -q https://github.com/probonopd/go-appimage/releases -O - \
          | grep "appimagetool-.*-${ARCH}.AppImage" | head -n 1 | cut -d '"' -f 2) -O appimagetool
          chmod +x appimagetool
      - 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
          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/${ARCH}-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}/

          rm  ${APPIMAGE_DST_PATH}/lib/x86_64-linux-gnu/libxcb-glx.so.0

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

  flatpak-pack:
    name: flatpak
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        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}_${ARCH}.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}_${ARCH}.flatpak $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.${ARCH}.flatpak
      - name: SHA256Sum of flatpak package(daily build)
        run: |
          sha256sum $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.${ARCH}.flatpak
          sha256sum $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.${ARCH}.flatpak > $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.${ARCH}.flatpak.sha256sum
          echo "================flatpak sha256sum download link===================="
          echo $(sh $GITHUB_WORKSPACE/scripts/upload_services/${UPLOAD_SERVICE}.sh $GITHUB_WORKSPACE/org.flameshot.Flameshot-${VERSION}.${ARCH}.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}.${ARCH}.flatpak)
          echo "======no operation for you can see link in the log console====="
      - name: Artifact Upload
        uses: actions/upload-artifact@v2
        with:
          name: Linux-distribution-artifact
          path: |
            ${{ github.workspace }}/org.flameshot.Flameshot-*.${{ env.ARCH }}.flatpak
            ${{ github.workspace }}/org.flameshot.Flameshot-*.${{ env.ARCH }}.flatpak.sha256sum

  snap-pack:
    name: snap
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Source code
        if: github.event_name == 'push'
        uses: actions/checkout@v2
        with: 
          fetch-depth: 0
          ref: master
      - name: Checkout Source code
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        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
      - 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@v2
        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
