name: Building GXDE Testing SID Package
run-name: Building SID ${{ 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:  
  loong64:
    runs-on: ubuntu-24.04
    steps:
      - 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 loong64 sid $REPOSITORY https://github.com/$GITHUB_REPOSITORY https://deb.debian.org/debian-ports/
          #bash .github/workflows/configure-building-enviroment-base-system.sh loong64 sid $REPOSITORY https://github.com/$GITHUB_REPOSITORY https://deb.debian.org/debian-ports/

      - name: Building ${{ GITHUB.repository }}
        run: |
          env gitPath=$(basename $GITHUB_REPOSITORY) bash .github/workflows/run-command-in-chroot.sh env GXDE_CODENAME=bixie GO111MODULE=off dpkg-buildpackage -b

      - name: Remove Debug Package
        run: |
          cd $BOTTLEPATH
          echo -e "ls -1 | grep dbgsym | grep .deb | grep -v dtk | grep -v qt | grep -v dock | grep -v gxtk\nexit 0" | sudo tee remove-deb.sh
          removeDeb=$(bash remove-deb.sh)
          sudo rm -rf $removeDeb

      - 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

  

  riscv64:
    runs-on: ubuntu-24.04
    steps:
      - 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 riscv64 sid $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 dpkg-buildpackage -b 

      - name: Remove Debug Package
        run: |
          set +e
          cd $BOTTLEPATH
          echo -e "ls -1 | grep dbgsym | grep .deb | grep -v dtk | grep -v qt | grep -v dock | grep -v gxtk\nexit 0" | sudo tee remove-deb.sh
          removeDeb=$(bash remove-deb.sh)
          sudo rm -rf $removeDeb 

      - 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

