@@ -197,22 +197,19 @@ if [[ "$MY_RUNNER_VERSION" != "latest" && "$MY_RUNNER_VERSION" != "skip" && ! "$
197197 exit_with_failure " '$MY_RUNNER_VERSION ' is not a valid GitHub Actions Runner version! Enter 'latest', 'skip' or the version without 'v'."
198198fi
199199
200- # Set maximal wait time (retries * 10 sec) for GitHub Actions Runner registration (default: 30 [5 min])
201- # If MY_RUNNER_WAIT is set, use its value; otherwise, use "30 ".
200+ # Set maximal wait time (retries * 10 sec) for GitHub Actions Runner registration (default: 60 [10 min])
201+ # If INPUT_RUNNER_WAIT is set, use its value; otherwise, use "60 ".
202202MY_RUNNER_WAIT=${INPUT_RUNNER_WAIT:- " 60" }
203203# Check if MY_RUNNER_WAIT is an integer
204204if [[ ! " $MY_RUNNER_WAIT " =~ ^[0-9]+$ ]]; then
205205 exit_with_failure " The maximum wait time (retries) for GitHub Action Runner registration must be an integer!"
206206fi
207207
208- # Set create retry logic inputs
209- MY_CREATE_RETRIES= ${INPUT_CREATE_RETRIES :- 1}
210- MY_CREATE_RETRY_DELAY =${INPUT_CREATE_RETRY_DELAY :- 10 }
208+ # Set maximal wait time (retries * 10 sec) for Hetzner Server creation (default: 360 [1 hour])
209+ # If INPUT_CREATE_WAIT is set, use its value; otherwise, use "360".
210+ MY_CREATE_WAIT =${INPUT_CREATE_WAIT :- 360 }
211211if [[ ! " $MY_CREATE_RETRIES " =~ ^[0-9]+$ ]]; then
212- exit_with_failure " The create_retries value must be an integer!"
213- fi
214- if [[ ! " $MY_CREATE_RETRY_DELAY " =~ ^[0-9]+$ ]]; then
215- exit_with_failure " The create_retry_delay value must be an integer!"
212+ exit_with_failure " The maximum wait time (retries) for Hetzner Server creation must be an integer!"
216213fi
217214
218215# Set Hetzner Cloud Server ID
373370
374371# Send a POST request to the Hetzner Cloud API to create a server.
375372# https://docs.hetzner.cloud/#servers-create-a-server
376- MY_CREATE_ATTEMPT=1
377- while [[ $MY_CREATE_ATTEMPT -le $MY_CREATE_RETRIES ]]; do
378- echo " Create server (attempt $MY_CREATE_ATTEMPT of $MY_CREATE_RETRIES )..."
373+ MAX_RETRIES=$MY_CREATE_WAIT
374+ RETRY_COUNT=0
375+ WAIT_SEC=10
376+ while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
377+ echo " Create Server..."
379378 if curl \
380379 -X POST \
381380 --fail-with-body \
@@ -387,16 +386,20 @@ while [[ $MY_CREATE_ATTEMPT -le $MY_CREATE_RETRIES ]]; do
387386 echo " Server created successfully."
388387 break
389388 else
390- echo " Server creation failed (attempt $MY_CREATE_ATTEMPT ). "
391- if [[ $MY_CREATE_ATTEMPT -lt $MY_CREATE_RETRIES ]] ; then
392- echo " Retrying in $MY_CREATE_RETRY_DELAY seconds.. ."
393- sleep " $MY_CREATE_RETRY_DELAY "
394- else
395- cat " servers.json"
396- exit_with_failure " Failed to create Server in Hetzner Cloud after $MY_CREATE_RETRIES attempts !"
397- fi
389+ # Check if the error is related to resource unavailability
390+ if grep -q -E " resource_unavailable|resource_limit_exceeded " " servers.json " ; then
391+ echo " Resource limitation detected ."
392+ # If error is not resource-related, don't retry
393+ else
394+ cat " servers.json"
395+ exit_with_failure " Failed to create Server in Hetzner Cloud!"
396+ fi
398397 fi
399- MY_CREATE_ATTEMPT=$(( MY_CREATE_ATTEMPT + 1 ))
398+
399+ RETRY_COUNT=$(( RETRY_COUNT + 1 )) # Increment retry counter
400+
401+ echo " Failed to create Server. Wait $WAIT_SEC seconds... (Attempt $RETRY_COUNT /$MAX_RETRIES )"
402+ sleep " $WAIT_SEC "
400403done
401404
402405# Get the Hetzner Server ID from the JSON response (assuming valid JSON)
@@ -416,7 +419,6 @@ echo "server_id=$MY_HETZNER_SERVER_ID" >> "$GITHUB_OUTPUT"
416419
417420# Wait for server
418421MAX_RETRIES=$MY_SERVER_WAIT
419- WAIT_SEC=10
420422RETRY_COUNT=0
421423echo " Wait for server..."
422424while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
0 commit comments