DEVOPS

Teardown Preview Env When Its PR Closes

Listens for GitHub pull-request close/merge events and immediately tears down the matching Vercel preview deployment, commenting on the PR with what was removed.

CategoryDevOps
Enginesim
Difficultyintermediate
Triggerevent
Steps6
Setup~15 min

How it runs

The automated pipeline, trigger to output.

  • TriggerGitHub pull_request closed webhookGitHubGitHub
  • LogicFilter merged/closed + read head branch
  • ActionFind Vercel deploy for that branchVercelVercel
  • LogicConfirm it's a preview, not production
  • ActionDelete the preview deploymentVercelVercel
  • OutputComment teardown result on the PRGitHubGitHub

What it does

Reacts the instant a pull request is merged or closed by deleting the preview environment tied to that branch, so dead previews never linger past the PR they belonged to. It comments back on the PR confirming the teardown.

When to use it

Use this for event-driven cleanup instead of a nightly sweep — the orphan never exists because it's reaped at the moment the PR closes. Best when each PR maps to exactly one preview deployment.

How it works

  1. 1A GitHub webhook fires on the `pull_request` closed event (covers both merged and abandoned PRs).
  2. 2A filter passes only closed/merged events and extracts the head branch name.
  3. 3Match Vercel deployments whose git branch equals the head branch.
  4. 4A logic step confirms the deployment is a `preview` and not promoted to production.
  5. 5Delete the matched preview deployment through the Vercel API.
  6. 6Comment on the closed PR with the deployment URL that was removed and the freed resources.

Set it up

What you configure once, before turning it on.

  1. 1
    Connect GitHubRepos, issues, pull requests, actions.
  2. 2
    Connect VercelDeploys, runtime logs, analytics.
  3. 3
    Set each agent's modelWe leave models unset so you pick the tier — fast + cheap, or top-quality.
  4. 4
    Tune it to your dataEdit the prompts, filters, and field mappings so it matches how your team works.
  5. 5
    Test, then turn it onRun once against a sample, confirm the output, then enable the trigger.

Run this workflow in your colony.

14-day trial. No DevOps. No Sales call. Provisioned in under a minute.