From 33f3a3b16d7c7c3b151582e46e80969ab3d91ba6 Mon Sep 17 00:00:00 2001 From: ftaakash Date: Sun, 18 Oct 2026 22:10:13 +0530 Subject: [PATCH] ci: delete the Neon preview branch when its pull request closes 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. --- .github/workflows/neon-preview-cleanup.yml | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/neon-preview-cleanup.yml diff --git a/.github/workflows/neon-preview-cleanup.yml b/.github/workflows/neon-preview-cleanup.yml new file mode 100644 index 0000000..ffc778b --- /dev/null +++ b/.github/workflows/neon-preview-cleanup.yml @@ -0,0 +1,28 @@ +name: Neon preview branch cleanup + +# The Vercel-managed Neon integration creates a database branch `preview/` for every preview deployment, +# but only deletes it when Vercel deletes that branch's last deployment, which can take months or never happen +# (Vercel keeps the latest 20 previews). The Free plan allows 10 branches per project, and once they are used up, +# every new preview deployment fails. This deletes the preview branch as soon as its pull request is closed or merged. +# See https://neon.com/docs/guides/vercel-branch-cleanup +# +# Dormant until configured: set the repository variable NEON_PROJECT_ID and the repository secret NEON_API_KEY. + +on: + pull_request: + types: [closed] + +permissions: {} + +jobs: + delete-preview-branch: + if: vars.NEON_PROJECT_ID != '' + runs-on: ubuntu-latest + steps: + - uses: neondatabase/delete-branch-action@v3 + # A PR whose preview never got a database branch has nothing to delete; that is not a failure. + continue-on-error: true + with: + project_id: ${{ vars.NEON_PROJECT_ID }} + branch: preview/${{ github.head_ref }} + api_key: ${{ secrets.NEON_API_KEY }}