-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.yml
112 lines (102 loc) · 4.01 KB
/
action.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: 'Neon Database Reset Branch Action'
author: 'Neon Database'
description: 'Resets a Neon branch'
branding:
icon: 'box'
color: 'green'
inputs:
project_id:
required: true
description: 'The project id'
branch:
required: true
description: 'The branch name or id to reset'
api_key:
description: 'The Neon API key'
required: true
api_host:
description: 'The Neon API Host'
default: 'https://console.neon.tech/api/v2'
parent:
description: 'If specified, the branch will be reset to the parent branch'
required: false
cs_role_name:
description: 'The output connection string db role name'
required: false
cs_database:
description: 'The output connection string database name'
required: false
cs_prisma:
description: 'Use prisma in output connection string or not'
required: false
default: 'false'
cs_ssl:
description: >
Add sslmode to the connection string. Supported values are: "require", "verify-ca", "verify-full", "omit".
required: false
default: 'require'
outputs:
branch_id:
description: 'Returns the branch id'
value: ${{ steps.reset-branch.outputs.branch_id }}
db_url:
description: 'DATABASE_URL of the branch after the reset'
value: ${{ steps.reset-branch.outputs.db_url }}
db_url_with_pooler:
description: 'DATABASE_URL with pooler of the branch after the reset'
value: ${{ steps.reset-branch.outputs.db_url_with_pooler }}
host:
description: 'Branch host after reset'
value: ${{ steps.reset-branch.outputs.host }}
host_with_pooler:
description: 'Branch host with pooling enabled after reset'
value: ${{ steps.reset-branch.outputs.host_with_pooler }}
password:
description: 'Password for connecting to the branch database after reset'
value: ${{ steps.reset-branch.outputs.password }}
runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
- run: npm i -g neonctl@v2
shell: bash
- name: Reset branch
env:
NEON_API_KEY: ${{ inputs.api_key }}
NEON_API_HOST: ${{ inputs.api_host }}
id: reset-branch
shell: bash
run: |
neonctl branches reset ${{ inputs.branch }} \
--project-id ${{ inputs.project_id }} \
$(if [[ -n "${{ inputs.parent }}" ]] && [[ "${{ inputs.parent }}" != "false" ]]; then echo "--parent"; fi) \
--output json \
> branch_out
echo "branch reset out:"
cat branch_out
branch_id=$(cat branch_out | jq --raw-output '.id')
echo "branch_id=${branch_id}" >> $GITHUB_OUTPUT
cs_json () {
neonctl cs ${branch_id} \
--project-id ${{ inputs.project_id }} \
$(if [[ -n "${{ inputs.cs_role_name }}" ]] && [[ "${{ inputs.cs_role_name }}" != "false" ]]; then echo "--role-name ${{ inputs.cs_role_name }}"; fi) \
$(if [[ -n "${{ inputs.cs_database }}" ]] && [[ "${{ inputs.cs_database }}" != "false" ]]; then echo "--database-name ${{ inputs.cs_database }}"; fi) \
$(if [[ -n "${{ inputs.cs_ssl }}" ]]; then echo "--ssl ${{ inputs.cs_ssl }}"; fi) \
$(if [[ -n "${{ inputs.cs_prisma }}" ]]; then echo "--prisma ${{ inputs.cs_prisma }}"; fi) \
--extended -o json \
$(if [[ -n "$1" ]]; then echo "--pooled"; fi)
}
CS_JSON=$(cs_json)
CS_JSON_POOLED=$(cs_json true)
DB_URL=$(echo $CS_JSON | jq -r '.connection_string')
DB_URL_WITH_POOLER=$(echo $CS_JSON_POOLED | jq -r '.connection_string')
echo "db_url=${DB_URL}" >> $GITHUB_OUTPUT
echo "db_url_with_pooler=${DB_URL_WITH_POOLER}" >> $GITHUB_OUTPUT
HOST=$(echo $CS_JSON | jq -r '.host')
HOST_WITH_POOLER=$(echo $CS_JSON_POOLED | jq -r '.host')
echo "host=${HOST}" >> $GITHUB_OUTPUT
echo "host_with_pooler=${HOST_WITH_POOLER}" >> $GITHUB_OUTPUT
PASSWORD=$(echo $CS_JSON | jq -r '.password')
echo $'\n'
echo "::add-mask::${PASSWORD}"
echo "password=${PASSWORD}" >> $GITHUB_OUTPUT