-
Notifications
You must be signed in to change notification settings - Fork 50
39 lines (35 loc) · 1.25 KB
/
delete-neon-branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Delete Neon Branch
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
pull_request:
types:
- closed
paths-ignore:
- '*.md'
workflow_dispatch:
jobs:
delete-neon-branch:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Search branch by name
id: get_branch_id
# list all branches and filter by name
run: |
branch_id=$(curl --silent --fail-with-body \
"https://console.neon.tech/api/v2/projects/${{ secrets.NEON_PROJECT_ID }}/branches" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${{ secrets.NEON_API_KEY }}" \
| jq -r .branches \
| jq -c '.[] | select(.name | contains("'${{ github.event.pull_request.head.ref || github.head_ref }}'")) .id' \
| jq -r)
echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT
- name: Delete Neon Branch
uses: neondatabase/delete-branch-action@v3
with:
project_id: ${{ secrets.NEON_PROJECT_ID }}
branch_id: ${{ steps.get_branch_id.outputs.branch_id }}
api_key: ${{ secrets.NEON_API_KEY }}