Skip to content

Commit 0118018

Browse files
committed
Create neon preview branches for pull requests
1 parent 598d330 commit 0118018

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Create/Delete Branch for Pull Request
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- closed
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
14+
jobs:
15+
setup:
16+
name: Setup
17+
outputs:
18+
branch: ${{ steps.branch_name.outputs.current_branch }}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Get branch name
22+
id: branch_name
23+
uses: tj-actions/branch-names@v8
24+
25+
create_neon_branch:
26+
name: Create Neon Branch
27+
outputs:
28+
db_url: ${{ steps.create_neon_branch_encode.outputs.db_url }}
29+
db_url_with_pooler: ${{ steps.create_neon_branch_encode.outputs.db_url_with_pooler }}
30+
needs: setup
31+
if: |
32+
github.event_name == 'pull_request' && (
33+
github.event.action == 'synchronize'
34+
|| github.event.action == 'opened'
35+
|| github.event.action == 'reopened')
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Create Neon Branch
39+
id: create_neon_branch
40+
uses: neondatabase/create-branch-action@v5
41+
with:
42+
project_id: ${{ vars.NEON_PROJECT_ID }}
43+
branch_name: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }}
44+
api_key: ${{ secrets.NEON_API_KEY }}
45+
46+
# The step above creates a new Neon branch.
47+
# You may want to do something with the new branch, such as run migrations, run tests
48+
# on it, or send the connection details to a hosting platform environment.
49+
# The branch DATABASE_URL is available to you via:
50+
# "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}".
51+
# It's important you don't log the DATABASE_URL as output as it contains a username and
52+
# password for your database.
53+
# For example, you can uncomment the lines below to run a database migration command:
54+
# - name: Run Migrations
55+
# run: npm run db:migrate
56+
# env:
57+
# # to use pooled connection
58+
# DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}"
59+
# # OR to use unpooled connection
60+
# # DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url }}"
61+
62+
delete_neon_branch:
63+
name: Delete Neon Branch
64+
needs: 'create_neon_branch'
65+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Delete Neon Branch
69+
uses: neondatabase/delete-branch-action@v3
70+
with:
71+
project_id: ${{ vars.NEON_PROJECT_ID }}
72+
branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }}
73+
api_key: ${{ secrets.NEON_API_KEY }}

0 commit comments

Comments
 (0)