I've done this a couple ways:
1. cron job that compares git branches to test envs, and shuts down any test envs for branches that have been deleted. This does, of course, rely on branches being deleted after they're merged. I know both github and gitlab now have an option you can set that will auto delete a branch after it is merged to master (or whatever you designate the "main" branch)
2. Gitlab CI has the concept of environments that are tied to branches. When a branch is deleted gitlab will run any jobs you've configured to run at the shutdown of an environment.
I've not used drone, but I'd be surprised if it doesn't have something like events or webhooks that you could use for this.
👍️1