# documentation: https://github.com/deltachat/sysadmin/tree/master/download.delta.chat
name: Delete node PR previews

on:
  pull_request:
    types: [closed]

jobs:
  delete:
    runs-on: ubuntu-latest

    steps:
      - name: Get Pull Request ID
        id: getid
        run: |
          export PULLREQUEST_ID=$(jq .number < $GITHUB_EVENT_PATH)
          echo "prid=$PULLREQUEST_ID" >> $GITHUB_OUTPUT
      - name: Renaming
        run: |
          # create empty file to copy it over the outdated deliverable on download.delta.chat
          echo "This preview build is outdated and has been removed." > empty
          cp empty deltachat-node-${{ steps.getid.outputs.prid }}.tar.gz
      - name: Replace builds with dummy files
        uses: horochx/deploy-via-scp@v1.0.1
        with:
          user: ${{ secrets.USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          host: "download.delta.chat"
          port: 22
          local: "deltachat-node-${{ steps.getid.outputs.prid }}.tar.gz"
          remote: "/var/www/html/download/node/preview/"
