Skip to content

Commit 44a4b1e

Browse files
committed
add more debug messages
1 parent b7d3d58 commit 44a4b1e

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

ephemeral/shutdown/action.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ runs:
5858
}
5959
6060
shutdown_instance() {
61-
http_code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
61+
# The API returns a 200 on successful deletion.
62+
# We use --fail-with-body so curl fails on server errors (5xx) and triggers the retry.
63+
# We allow a 404 since that means the instance is already gone.
64+
http_code=$(curl --fail-with-body -s -o /dev/null -w "%{http_code}" -X DELETE \
6265
-H "$AUTH_HEADER" \
6366
-H "$CONTENT_TYPE_HEADER" \
6467
"$API_URL_BASE/$previewName")
65-
if [[ "$http_code" -ne 200 && "$http_code" -ne 404 ]]; then
66-
echo "Unable to delete preview environment. API returned HTTP code: $http_code"
67-
return 1
68+
if [ $? -eq 0 ]; then
69+
if [ "$http_code" -eq 200 ]; then
70+
echo "Instance '$previewName' deleted successfully."
71+
elif [ "$http_code" -eq 404 ]; then
72+
echo "Instance '$previewName' was already deleted (not found)."
73+
fi
6874
fi
6975
}
7076
retry shutdown_instance

ephemeral/startup/action.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,19 @@ runs:
9494
}
9595
9696
fetch_instances() {
97+
local list_response
9798
list_response=$(curl --fail-with-body -s -X GET \
98-
-H "$AUTH_HEADER" \
99-
-H "$CONTENT_TYPE_HEADER" \
100-
"$API_URL_BASE")
101-
if ! echo "$list_response" | jq -e 'type == "array"' > /dev/null; then
102-
echo "API returned an error: $list_response"
103-
return 1
99+
-H "$AUTH_HEADER" \
100+
-H "$CONTENT_TYPE_HEADER" \
101+
"$API_URL_BASE")
102+
if [ $? -ne 0 ]; then
103+
echo "API returned an error: $list_response"
104+
return 1
104105
fi
106+
echo "$list_response"
105107
}
106108
107-
retry fetch_instances
109+
list_response=$(retry fetch_instances)
108110
109111
autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"
110112
extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}"
@@ -130,20 +132,21 @@ runs:
130132
fi
131133
132134
create_instance_func() {
135+
local response
133136
response=$(curl --fail-with-body -s -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\
134137
-H "$AUTH_HEADER" \
135138
-H "$CONTENT_TYPE_HEADER" \
136139
"$API_URL_BASE")
137-
138-
endpointUrl=$(echo "$response" | jq -r .endpoint_url)
139-
if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then
140+
if [ $? -ne 0 ] || ! echo "$response" | jq -e 'has("endpoint_url") and (.endpoint_url | test(".+"))' > /dev/null; then
140141
echo "Unable to create preview environment. API response: $response"
141142
return 1
142143
fi
144+
echo "$response"
143145
}
144146
145147
echo "Creating preview environment ..."
146-
retry create_instance_func
148+
response=$(retry create_instance_func)
149+
endpointUrl=$(echo "$response" | jq -r .endpoint_url)
147150
148151
echo "Created preview environment with endpoint URL: $endpointUrl"
149152
@@ -193,11 +196,22 @@ runs:
193196
}
194197
195198
fetch_logs() {
199+
local log_response
196200
log_response=$(curl --fail-with-body -s -X GET \
197201
-H "$AUTH_HEADER" \
198202
-H "$CONTENT_TYPE_HEADER" \
199203
"$API_URL_BASE/$previewName/logs")
204+
if [ $? -ne 0 ]; then
205+
echo "API returned an error while fetching logs: $log_response"
206+
return 1
207+
fi
208+
if [ -z "$log_response" ]; then
209+
echo "API returned an empty response when fetching logs."
210+
return 1
211+
fi
212+
echo "$log_response"
200213
}
201214
echo "Fetching logs for $previewName ..."
202-
retry fetch_logs
203-
echo "Logs:\n$log_response" | jq -r '.[].content'
215+
log_response=$(retry fetch_logs)
216+
echo "Logs:"
217+
echo "$log_response" | jq -r '.[].content'

0 commit comments

Comments
 (0)