name: Rebuild signaller for deprived.dev to rebuild site

on: [push]

jobs:
  test_service:
    runs-on: native

    steps:
      - name: Get branch
        run: echo "BRANCH=$(echo "${{ gitea.ref }}" | cut -d'/' -f3)" >> $GITHUB_ENV
      - name: Signal deprived.dev for rebuild
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
          GITKEY: ${{ secrets.GITKEY }}
          PUBLIC_URL_BASE: ${{ variables.PUBLIC_URL_BASE }}
          PUBLIC_POCKET_URL: ${{ variables.PUBLIC_POCKET_URL }}
        run: |
          sshkey=$(mktemp)
          trap "rm -rf $sshkey" exit
          echo -e $SSH_PRIVATE_KEY > $sshkey
          service="build-deprived-website-$BRANCH"
          sshargs="-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
          echo "Starting systemd oneshot service: $service"
          ssh -i $sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no deprivedbuilder@deprived.dev -t "sudo /run/current-system/sw/bin/systemctl start $service"
          echo "Build Log: $(ssh -i $sshkey $sshargs deprivedbuilder@deprived.dev "cat ~/latest_build.log")"
