name: Building GXDE Testing Package
run-name: Building ${{ GITHUB.REPOSITORY }}

on:
  workflow_call:
    secrets:
      PASSWD:
        required: true
      USERS:
        required: true
      HOST: 
        required: true
      UPATH: 
        required: true
      UPROGRAM: 
        required: true
      UPORT: 
        required: true

env:
  REPOSITORY: https://github.com/GXDE-OS/GXDE  
  BOTTLEPATH: system-bottle

jobs:  
  i386:
    runs-on: ubuntu-latest
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'

      - name: Clone Repository To Get Script
        run: |
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh i386 bookworm $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh i386
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true

  amd64-Debian12:
    runs-on: ubuntu-latest
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'
      - name: Clone Repository To Get Script
        run: |
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 bookworm $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh amd64
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true

  arm64:
    runs-on: ubuntu-24.04
    #runs-on: self-hosted
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'
      - name: Clone Repository To Get Script
        run: |
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 bookworm $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh arm64
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null
  
      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true

  mips64:
    runs-on: ubuntu-24.04
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'

      - name: Clone Repository To Get Script
        run: |
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 bookworm $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh mips64el
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true

  loong64-debian-port:
    runs-on: ubuntu-24.04
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'

      - name: Clone Repository To Get Script
        run: |
          #apt update
          #apt install sudo git -y
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 testing $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh loong64
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true

  riscv64:
    runs-on: ubuntu-24.04
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'

      - name: Clone Repository To Get Script
        run: |
          #apt update
          #apt install sudo git -y
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 testing $REPOSITORY https://github.com/$GITHUB_REPOSITORY 

      - name: Building ${{ GITHUB.repository }}
        run: |
          set +e
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off bash build-deb.sh riscv64
          cp $BOTTLEPATH/*.deb . -rv 
          sudo rename 's/\.deb$/_tianlu.deb/' *.deb

      - name: Remove Debug Package
        run: |
          set +e
          env env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb 

      - name: Pack tar
        run: |
          set +e
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          set +e
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          if [[ $tarName != "" ]]; then
            sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH > /dev/null
            sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM tianlu $UPATH/$tarName > /dev/null
          fi

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true
  
  loong64-loongnix:
    runs-on: ubuntu-24.04
    steps:
      # 由于默认的 Ubuntu 环境只有 17G 左右的剩余空间，所以我们需要先利用如下 action 对编译环境进行扩容
      - name: Maximize build space
        uses: easimon/maximize-build-space@master
        with:
          # 这个值是保留给系统的空间大小，之前设置太小，总会在安装依赖或者编译过程中报设备空间不足的错误而导致编译失败
          root-reserve-mb: 4096
          swap-size-mb: 512
          remove-dotnet: 'true'
          remove-docker-images: 'true'
          remove-codeql: 'true'
          remove-haskell: 'true'
          remove-android: 'true'

      - name: Clone Repository To Get Script
        run: |
          #apt update
          #apt install sudo git -y
          git clone $REPOSITORY --depth=1
          mv $(basename $REPOSITORY)/* . -v
          mv $(basename $REPOSITORY)/.* . -v | true

      - name: Configure Base System
        run: |
          bash .github/workflows/configure-building-enviroment-base-system.sh amd64 testing $REPOSITORY https://github.com/$GITHUB_REPOSITORY

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=meimei GO111MODULE=off bash build-deb.sh loong64
          cp $BOTTLEPATH/*.deb . -rv
          sudo rename 's/\.deb$/_meimei.deb/' *.deb

      - name: Remove Debug Package
        run: |
          env env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh rm -rfv ../*dbg*.deb

      - name: Pack tar
        run: |
          cd $BOTTLEPATH
          sudo tar -cvf ../deb-$(date +%s).tar *.deb 

      - name: Push
        env: 
          UPASSWD: ${{ secrets.PASSWD }}
          UUSERS: ${{ secrets.USERS }}
          UHOST: ${{ secrets.HOST }}
          UPATH: ${{ secrets.UPATH }}
          UPROGRAM: ${{ secrets.UPROGRAM }}
          UPORT: ${{ secrets.UPORT }}
        run: |
          sudo apt update
          sudo apt install sshpass -y
          mkdir -p ~/.ssh/
          ssh-keyscan -p $UPORT -H $UHOST >> ~/.ssh/known_hosts
          tarName=$(ls | grep .tar | head -n 1)
          sshpass -p "$UPASSWD" rsync -e "ssh -p $UPORT" $tarName $UUSERS@$UHOST:$UPATH
          sshpass -p "$UPASSWD" ssh $UUSERS@$UHOST -p $UPORT $UPROGRAM meimei $UPATH/$tarName > /dev/null

      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOCKEN_GITHUB }}
        with:
          files: |
            *.deb
          generate_release_notes: true