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 \
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