forked from tursodatabase/create-database-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
78 lines (65 loc) · 2.37 KB
/
action.yaml
File metadata and controls
78 lines (65 loc) · 2.37 KB
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
name: "Create Turso Database"
description: "Automatically create and clone a Turso database, with the option to restore from a specified point in time."
author: "Turso"
branding:
color: "green"
icon: "database"
inputs:
organization_name:
description: "The name of the organization or account where this action will be performed."
required: true
api_token:
description: "The API key that has access to the organization or account."
required: true
existing_database_name:
description: "The name of the existing database."
required: true
new_database_name:
description: "The new database name."
required: true
group_name:
description: "The group name the database should be created in."
required: false
outputs:
hostname:
description: "The database hostname without protocol."
value: ${{ steps.create-database.outputs.hostname }}
runs:
using: "composite"
steps:
- name: Get Group
id: get-group
if: inputs.group_name == ''
shell: bash
run: |
RESPONSE=$(curl -s -f \
-H "Authorization: Bearer ${{ inputs.api_token }}" \
"https://api.turso.tech/v1/organizations/${{ inputs.organization_name }}/databases/${{ inputs.existing_database_name }}")
if [ $? -ne 0 ]; then
echo "Could not fetch database"
exit 1
fi
GROUP_NAME=$(echo $RESPONSE | jq -r '.database.group')
if [ -z "$GROUP_NAME" ]; then
echo "Group name not found in response"
exit 1
fi
echo "GROUP_NAME=$GROUP_NAME" >> $GITHUB_ENV
- name: Create Database
id: create-database
shell: bash
run: |
if [ -z "${{ inputs.group_name }}" ]; then
GROUP_TO_USE=$GROUP_NAME
else
GROUP_TO_USE="${{ inputs.group_name }}"
fi
RESPONSE=$(curl -s -f -X POST \
-H "Authorization: Bearer ${{ inputs.api_token }}" \
-H "Content-Type: application/json" \
-d '{"name": "${{ inputs.new_database_name }}", "group": "'"$GROUP_TO_USE"'", "seed": {"type": "database", "name": "${{ inputs.existing_database_name }}"} }' \
"https://api.turso.tech/v1/organizations/${{ inputs.organization_name }}/databases")
# log response
echo $RESPONSE
HOSTNAME=$(echo $RESPONSE | jq -r '.database.Hostname')
echo "hostname=$HOSTNAME" >> $GITHUB_OUTPUT