-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
115 lines (106 loc) · 3.73 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
113
114
115
name: Astra DB Setup
description: Setup a new database in Datastax Astra DB
inputs:
token:
required: true
description: "Astra DB application token. It needs to have enough permissions to create/delete databases in the organization."
region:
required: true
description: "Region whereas to create the database."
cloud:
required: true
description: "Cloud provider whereas to create the database. (aws,gcp,azure)"
vector:
required: false
description: "Whether to create a Vector database. (true, false)"
default: "true"
keyspace:
default: "default_keyspace"
description: "Database default keyspace. Defaults to 'default_keyspace'."
name:
required: false
description: "Name of the database to create."
name-prefix:
required: false
default: ""
description: "Prefix for the generated database name."
env:
description: "Astra DB environment. (ENV, PROD)"
default: "PROD"
outputs:
api-endpoint:
description: "Full URL API endpoint of the database"
value: ${{ steps.db-setup.outputs.api-endpoint }}
id:
description: "Database ID"
value: ${{ steps.db-setup.outputs.id }}
name:
description: "Database name"
value: ${{ steps.db-setup.outputs.name }}
runs:
using: "composite"
steps:
- name: Create a new database
shell: bash
id: db-setup
env:
TERM: linux
run: |
set -e
(curl -Ls "https://dtsx.io/get-astra-cli" | bash) || true
echo "Astra CLI installed"
/home/runner/.astra/cli/astra -v
if [ -z "${{ inputs.name }}" ]; then
prefix=""
if [ -n "${{ inputs.name-prefix }}" ]; then
echo "Generating database name with prefix: $prefix"
prefix="${{ inputs.name-prefix }}_"
else
echo "Generating database name without prefix"
fi
random_suffix=$RANDOM
db_name="${prefix}${{ github.run_id }}_${random_suffix}"
echo "Using generated database name: $db_name"
else
db_name="${{ inputs.name }}"
echo "Using provided database name: $db_name"
fi
vector_param=""
if [ "${{ inputs.vector }}" == "true" ]; then
vector_param="--vector"
fi
(/home/runner/.astra/cli/astra db create -v "$db_name" $vector_param \
--env "${{ inputs.env }}" \
-k "${{ inputs.keyspace }}" \
--token "${{ inputs.token }}" \
--region "${{ inputs.region }}" \
--cloud "${{ inputs.cloud }}" \
--timeout 1200) || echo "Failed to create database, check if creation is still in progress"
while true; do
describe_out=$(/home/runner/.astra/cli/astra db describe "$db_name" \
--token "${{ inputs.token }}" --env "${{ inputs.env }}" -o json)
status=$(echo "$describe_out" | jq -r '.data.status')
database_id=$(echo "$describe_out" | jq -r '.data.id')
if [ "$status" == "ACTIVE" ]; then
break
fi
if [ "$status" == "INITIALIZING" ]; then
echo "Database is not active, status: $status"
sleep 10
fi
echo "Database creation failed, status: $status"
exit 1
done
echo "Database id: $database_id"
domain="astra"
if [ "${{ inputs.env }}" == "DEV" ]; then
domain="astra-dev"
fi
db_endpoint="https://${database_id}-${{ inputs.region }}.apps.${domain}.datastax.com"
echo "Database endpoint: $db_endpoint"
echo "api-endpoint=$db_endpoint" >> $GITHUB_OUTPUT
echo "id=$database_id" >> $GITHUB_OUTPUT
echo "name=$db_name" >> $GITHUB_OUTPUT
branding:
icon: 'database'
color: 'orange'