-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
156 lines (132 loc) · 4.49 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: "SurrealDB in Github Action"
description: "Start a SurrealDB instance in Github Actions"
branding:
icon: "database"
color: "purple"
inputs:
surrealdb_version:
description: "The version of SurrealDB to use, default is latest"
required: false
default: "latest"
surrealdb_port:
description: "The port to run SurrealDB on, default is 8000"
required: false
default: "8000"
surrealdb_username:
description: "The username to use for SurrealDB"
required: false
surrealdb_password:
description: "The password to use for SurrealDB"
required: false
surrealdb_auth:
description: "Enable authentication for SurrealDB"
required: false
default: "false"
surrealdb_strict:
description: "Enable strict mode for SurrealDB"
required: false
default: "false"
surrealdb_log:
description: "Enable logs printed out in the console."
required: false
surrealdb_additional_args:
description: "Additional arguments to pass to SurrealDB"
required: false
surrealdb_retry_count:
description: "The number of times to retry connecting to SurrealDB"
required: false
default: "30"
runs:
using: composite
steps:
- name: Install SurrealDB
shell: bash
run: |
SURREALDB_VERSION="${{ inputs.surrealdb_version }}"
# Download the SurrealDB binary when the version is not latest
if [ "$SURREALDB_VERSION" = "latest" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh
else
curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh -s -- --version ${{ inputs.surrealdb_version }}
fi
- name: Run SurrealDB in Background
shell: bash
run: |
SURREALDB_VERSION="${{ inputs.surrealdb_version }}"
SURREALDB_PORT="${{ inputs.surrealdb_port }}"
SURREALDB_USERNAME="${{ inputs.surrealdb_username }}"
SURREALDB_PASSWORD="${{ inputs.surrealdb_password }}"
SURREALDB_AUTH="${{ inputs.surrealdb_auth }}"
SURREALDB_STRICT="${{ inputs.surrealdb_strict }}"
SURREALDB_LOG="${{ inputs.surrealdb_log }}"
SURREALDB_ADDITIONAL_ARGS="${{ inputs.surrealdb_additional_args }}"
SURREALDB_ALLOW_ALL="${{ inputs.surrealdb_allow_all }}"
if [ -z "$SURREALDB_USERNAME" ]; then
SURREALDB_USERNAME="-u root"
else
SURREALDB_USERNAME="-u $SURREALDB_USERNAME"
fi
if [ -z "$SURREALDB_PASSWORD" ]; then
SURREALDB_PASSWORD="-p root"
else
SURREALDB_PASSWORD="-p $SURREALDB_PASSWORD"
fi
if [[ "$SURREALDB_VERSION" = v1.* ]]; then
if [ "$SURREALDB_AUTH" == "true" ]; then
SURREALDB_AUTH="--auth"
else
SURREALDB_AUTH=""
fi
else
if [ "$SURREALDB_AUTH" = "true" ]; then
SURREALDB_AUTH=""
else
SURREALDB_AUTH="--unauthenticated"
fi
fi
if [[ -z "$SURREALDB_PORT" ]]; then
SURREALDB_PORT="--bind 0.0.0.0:8000"
else
SURREALDB_PORT="--bind 0.0.0.0:$SURREALDB_PORT"
fi
if [ "$SURREALDB_STRICT" = "true" ]; then
SURREALDB_STRICT="--strict"
else
SURREALDB_STRICT=""
fi
if [ -z "$SURREALDB_LOG" ]; then
SURREALDB_LOG="--log trace"
else
SURREALDB_LOG="--log $SURREALDB_LOG"
fi
if [ -z "$SURREALDB_ADDITIONAL_ARGS" ]; then
SURREALDB_ADDITIONAL_ARGS=""
fi
cd /usr/local/bin
nohup surreal start \
$SURREALDB_USERNAME \
$SURREALDB_PASSWORD \
$SURREALDB_AUTH \
$SURREALDB_PORT \
$SURREALDB_STRICT \
$SURREALDB_LOG \
$SURREALDB_ADDITIONAL_ARGS &
- name: Wait for SurrealDB to start
shell: bash
run: |
URL="http://localhost:8000/health"
MAX_ATTEMPTS="${{ inputs.surrealdb_retry_count }}"
ATTEMPT=0
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $URL)
if [ "$RESPONSE" -eq 200 ]; then
echo "SurrealDB instance is up and running, continuing..."
break
fi
ATTEMPT=$((ATTEMPT + 1))
sleep 1
done
if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then
echo "SurrealDB instance could not be contacted, aborting."
exit 1
fi