name: Pull Request Cleanup

on:
  pull_request_target:
    types:
      - closed

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - name: Setup SSH
        uses: kielabokkie/ssh-key-and-known-hosts-action@v1
        with:
          ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
          ssh-host: srv.bbaovanc.com
          ssh-port: 2222

      - name: Delete pull request on server
        run:
          ssh -p 2222 droneci@srv.bbaovanc.com rm -r /var/www/demo.bbaovanc.com/pull_request/${{ github.event.number }}/

      - name: Deactivate deployment
        uses: bobheadxi/deployments@v0.6.0
        with:
          step: deactivate-env
          token: ${{ github.token }}
          env: pr-${{ github.event.number }}
          desc: Deployment was pruned
