Skip to content

ci: delete the Neon preview branch when its pull request closes - #47

Merged
ftaakash merged 1 commit into
mainfrom
claude/neon-preview-cleanup
Oct 19, 2026
Merged

ftaakash merged 1 commit into
mainfrom
claude/neon-preview-cleanup

Conversation

@ftaakash

Copy link
Copy Markdown
Owner

Why

Every Vercel preview after #31 failed because the Neon project hit the Free plan's 10-branch limit. The Vercel-managed Neon integration has no "delete when the git branch is deleted" setting. It deletes a preview branch only when Vercel deletes that branch's last deployment. On Hobby that takes 30 days at the earliest, and Vercel always keeps the latest 20 previews, so in a project this size it may never happen. See Neon: Managing Vercel preview branch cleanup.

What

.github/workflows/neon-preview-cleanup.yml runs Neon's delete-branch-action when a PR is closed or merged, deleting preview/<head branch> (the name the integration uses). The workflow:

  • has no GitHub token permissions (permissions: {});
  • treats an already-missing branch as success, since some PRs never got a preview database;
  • is dormant: the job is skipped until the NEON_PROJECT_ID repository variable is set, the same pattern as AWS_DEPLOY_ENABLED in deploy.yml.

To turn it on (owner only)

  1. In the Neon Console, go to Account settings → API keys and create a key.
  2. In GitHub, go to Settings → Secrets and variables → Actions and add the secret NEON_API_KEY with that key.
  3. In the same place, under Variables, add NEON_PROJECT_ID = little-field-62303405.

The action deletes only the closed PR's own preview/… branch. It never touches main (production).

The Vercel-managed Neon integration only removes a preview branch when
Vercel deletes the branch's last deployment, which in practice is months
or never. With the Free plan's 10-branch limit, stale branches made every
new preview deployment fail. This runs Neon's delete-branch-action on PR
close, following https://neon.com/docs/guides/vercel-branch-cleanup.

Dormant until NEON_PROJECT_ID (variable) and NEON_API_KEY (secret) are set.
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
dischargeflow Ready Ready Preview Oct 18, 2026 4:41pm UTC

@ftaakash
ftaakash merged commit 136adbe into main Oct 19, 2026
10 checks passed
@ftaakash
ftaakash deleted the claude/neon-preview-cleanup branch October 19, 2026 12:21

This branch was successfully deployed

1 active deployment
Preview — 33f3a3b1 Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant