name: Cleanup snapshot

on:
  pull_request_target:
    types: [closed]

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - name: Delete snapshot
        run: |
          NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)
          aws s3 rm --recursive "s3://${AWS_BUCKET}/${NAME}/"
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.S3_REPO_KEY }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_REPO_SECRET }}
          AWS_DEFAULT_REGION: us-east-1
          AWS_BUCKET: snapshot.nextdns.io
