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 }}