Skip to content

Commit 5f7b169

Browse files
committed
fixup
1 parent b3ad5bc commit 5f7b169

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

ephemeral/shutdown/action.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,25 @@ runs:
3939
CONTENT_TYPE_HEADER="content-type: application/json"
4040
API_URL_BASE="https://api.localstack.cloud/v1/compute/instances"
4141
42-
source ${{ github.action_path }}/retry-function.sh
42+
source ${{ github.action_path }}/../retry-function.sh
4343
shutdown_instance() {
4444
# The API returns a 200 on successful deletion.
4545
# We use --fail-with-body so curl fails on server errors (5xx) and triggers the retry.
4646
# We allow a 404 since that means the instance is already gone.
47+
local http_code
4748
http_code=$(curl --fail-with-body -s -o /dev/null -w "%{http_code}" -X DELETE \
4849
-H "$AUTH_HEADER" \
4950
-H "$CONTENT_TYPE_HEADER" \
5051
"$API_URL_BASE/$previewName")
51-
if [ $? -eq 0 ]; then
52-
if [ "$http_code" -eq 200 ]; then
53-
echo "Instance '$previewName' deleted successfully."
54-
elif [ "$http_code" -eq 404 ]; then
55-
echo "Instance '$previewName' was already deleted (not found)."
56-
fi
52+
local exit_code=$?
53+
if [ $exit_code -ne 0 ]; then
54+
echo "Error deleting instance, curl failed with exit code $exit_code. API response: $http_code" >&2
55+
return 1
56+
fi
57+
if [ "$http_code" -eq 200 ]; then
58+
echo "Instance '$previewName' deleted successfully."
59+
elif [ "$http_code" -eq 404 ]; then
60+
echo "Instance '$previewName' was already deleted (not found)."
5761
fi
5862
}
5963
retry shutdown_instance

ephemeral/startup/action.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ runs:
6363
CONTENT_TYPE_HEADER="content-type: application/json"
6464
API_URL_BASE="https://api.localstack.cloud/v1/compute/instances"
6565
66-
source ${{ github.action_path }}/retry-function.sh
66+
source ${{ github.action_path }}/../retry-function.sh
6767
fetch_instances() {
6868
local list_response
6969
list_response=$(curl --fail-with-body -s -X GET \
@@ -77,7 +77,10 @@ runs:
7777
echo "$list_response"
7878
}
7979
80-
list_response=$(retry fetch_instances)
80+
if ! list_response=$(retry fetch_instances); then
81+
echo "Error: Failed to fetch instances after multiple retries."
82+
exit 1
83+
fi
8184
8285
autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"
8386
extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}"
@@ -87,19 +90,27 @@ runs:
8790
8891
delete_instance() {
8992
# We expect a 200 on success or 404 if it's already gone. Other codes are errors.
90-
http_code=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
93+
local http_code
94+
http_code=$(curl --fail-with-body -s -o /dev/null -w "%{http_code}" -X DELETE \
9195
-H "$AUTH_HEADER" \
9296
-H "$CONTENT_TYPE_HEADER" \
9397
"$API_URL_BASE/$previewName")
94-
if [ "$http_code" -ne 200 ] && [ "$http_code" -ne 404 ]; then
95-
echo "Error deleting instance, HTTP code: $http_code"
98+
local exit_code=$?
99+
if [ $exit_code -ne 0 ]; then
100+
echo "Error deleting instance, curl failed with exit code $exit_code. API response: $http_code" >&2
96101
return 1
97102
fi
103+
if [ "$http_code" -eq 200 ]; then
104+
echo "Instance '$previewName' deleted successfully."
105+
fi
98106
}
99107
100108
if [ -n "$instance_exists" ]; then
101109
echo "Found existing instance using '$previewName', trying to delete the old one..."
102-
retry delete_instance
110+
if ! retry delete_instance; then
111+
echo "Error: Failed to delete existing instance after multiple retries."
112+
exit 1
113+
fi
103114
fi
104115
105116
create_instance_func() {
@@ -116,7 +127,11 @@ runs:
116127
}
117128
118129
echo "Creating preview environment ..."
119-
response=$(retry create_instance_func)
130+
if ! response=$(retry create_instance_func); then
131+
echo "Error: Failed to create preview environment after multiple retries."
132+
exit 1
133+
fi
134+
120135
endpointUrl=$(echo "$response" | jq -r .endpoint_url)
121136
122137
echo "Created preview environment with endpoint URL: $endpointUrl"
@@ -147,7 +162,7 @@ runs:
147162
CONTENT_TYPE_HEADER="content-type: application/json"
148163
API_URL_BASE="https://api.localstack.cloud/v1/compute/instances"
149164
150-
source ${{ github.action_path }}/retry-function.sh
165+
source ${{ github.action_path }}/../retry-function.sh
151166
fetch_logs() {
152167
local log_response
153168
log_response=$(curl --fail-with-body -s -X GET \
@@ -175,8 +190,7 @@ runs:
175190
echo "$log_response"
176191
}
177192
echo "Fetching logs for $previewName ..."
178-
log_response=$(retry fetch_logs)
179-
if [ -z "$log_response" ]; then
193+
if ! log_response=$(retry fetch_logs); then
180194
echo "Error: Failed to fetch logs after multiple retries."
181195
exit 1
182196
fi

0 commit comments

Comments
 (0)