@@ -51,6 +51,9 @@ for MY_FILE in "${MY_FILES[@]}"; do
5151 fi
5252done
5353
54+ # Retry wait time in secounds
55+ WAIT_SEC=10
56+
5457#
5558# INPUT
5659#
5962# https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#inputs
6063# When you specify an input, GitHub creates an environment variable for the input with the name INPUT_<VARIABLE_NAME>.
6164
62- # Set the Hetzner Cloud API token.
63- # Retrieves the value from the INPUT_HCLOUD_TOKEN environment variable.
64- MY_HETZNER_TOKEN=${INPUT_HCLOUD_TOKEN}
65- if [[ -z " $MY_HETZNER_TOKEN " ]]; then
66- exit_with_failure " Hetzner Cloud API token is not set."
65+ # Set maximum retries * WAIT_SEC (10 sec) for Hetzner Server creation via the Hetzer Cloud API (default: 360 [1 hour])
66+ # If INPUT_CREATE_WAIT is set, use its value; otherwise, use "360".
67+ MY_CREATE_WAIT=${INPUT_CREATE_WAIT:- 360}
68+ if [[ ! " $MY_CREATE_WAIT " =~ ^[0-9]+$ ]]; then
69+ exit_with_failure " The maximum retries for Hetzner Server creation via the Hetzer Cloud API must be an integer!"
70+ fi
71+
72+ # Set maximum retries * WAIT_SEC (10 sec) for Hetzner Server deletion via the Hetzer Cloud API (default: 360 [1 hour])
73+ # If INPUT_DELETE_WAIT is set, use its value; otherwise, use "360".
74+ MY_DELETE_WAIT=${INPUT_DELETE_WAIT:- 360}
75+ if [[ ! " $MY_DELETE_WAIT " =~ ^[0-9]+$ ]]; then
76+ exit_with_failure " The maximum retries for Hetzner Server deletion via the Hetzer Cloud API must be an integer!"
77+ fi
78+
79+ # Enable IPv4 (default: false)
80+ # If INPUT_ENABLE_IPV4 is set, use its value; otherwise, use "false".
81+ MY_ENABLE_IPV4=${INPUT_ENABLE_IPV4:- " true" }
82+ if [[ " $MY_ENABLE_IPV4 " != " true" && " $MY_ENABLE_IPV4 " != " false" ]]; then
83+ exit_with_failure " Enable IPv4 must be 'true' or 'false'."
84+ fi
85+
86+ # Enable IPv6 (default: true)
87+ # If INPUT_ENABLE_IPV6 is set, use its value; otherwise, use "true".
88+ MY_ENABLE_IPV6=${INPUT_ENABLE_IPV6:- " true" }
89+ if [[ " $MY_ENABLE_IPV6 " != " true" && " $MY_ENABLE_IPV6 " != " false" ]]; then
90+ exit_with_failure " Enable IPv6 must be 'true' or 'false'."
6791fi
6892
6993# Set the GitHub Personal Access Token (PAT).
@@ -86,27 +110,11 @@ MY_GITHUB_REPOSITORY_OWNER_ID=${GITHUB_REPOSITORY_OWNER_ID:-"0"}
86110# Set The ID of the repository (used for Hetzner Cloud Server label).
87111MY_GITHUB_REPOSITORY_ID=${GITHUB_REPOSITORY_ID:- " 0" }
88112
89- # Specify here which mode you want to use (default: create):
90- # - create : Create a new runner
91- # - delete : Delete the previously created runner
92- # If INPUT_MODE is set, use its value; otherwise, use "create".
93- MY_MODE=${INPUT_MODE:- " create" }
94- if [[ " $MY_MODE " != " create" && " $MY_MODE " != " delete" ]]; then
95- exit_with_failure " Mode must be 'create' or 'delete'."
96- fi
97-
98- # Enable IPv4 (default: false)
99- # If INPUT_ENABLE_IPV4 is set, use its value; otherwise, use "false".
100- MY_ENABLE_IPV4=${INPUT_ENABLE_IPV4:- " true" }
101- if [[ " $MY_ENABLE_IPV4 " != " true" && " $MY_ENABLE_IPV4 " != " false" ]]; then
102- exit_with_failure " Enable IPv4 must be 'true' or 'false'."
103- fi
104-
105- # Enable IPv6 (default: true)
106- # If INPUT_ENABLE_IPV6 is set, use its value; otherwise, use "true".
107- MY_ENABLE_IPV6=${INPUT_ENABLE_IPV6:- " true" }
108- if [[ " $MY_ENABLE_IPV6 " != " true" && " $MY_ENABLE_IPV6 " != " false" ]]; then
109- exit_with_failure " Enable IPv6 must be 'true' or 'false'."
113+ # Set the Hetzner Cloud API token.
114+ # Retrieves the value from the INPUT_HCLOUD_TOKEN environment variable.
115+ MY_HETZNER_TOKEN=${INPUT_HCLOUD_TOKEN}
116+ if [[ -z " $MY_HETZNER_TOKEN " ]]; then
117+ exit_with_failure " Hetzner Cloud API token is not set."
110118fi
111119
112120# Set the image to use for the instance (default: ubuntu-24.04)
121129# If INPUT_LOCATION is set, use its value; otherwise, use "nbg1".
122130MY_LOCATION=${INPUT_LOCATION:- " nbg1" }
123131
132+ # Specify here which mode you want to use (default: create):
133+ # - create : Create a new runner
134+ # - delete : Delete the previously created runner
135+ # If INPUT_MODE is set, use its value; otherwise, use "create".
136+ MY_MODE=${INPUT_MODE:- " create" }
137+ if [[ " $MY_MODE " != " create" && " $MY_MODE " != " delete" ]]; then
138+ exit_with_failure " Mode must be 'create' or 'delete'."
139+ fi
140+
124141# Set the name of the instance (default: gh-runner-$RANDOM)
125142# If INPUT_NAME is set, use its value; otherwise, generate a random name using "gh-runner-$RANDOM".
126143MY_NAME=${INPUT_NAME:- " gh-runner-$RANDOM " }
@@ -160,26 +177,6 @@ if [[ "$MY_PRIMARY_IPV6" != "null" && ! "$MY_PRIMARY_IPV6" =~ ^[0-9]+$ ]]; then
160177 exit_with_failure " The primary IPv6 ID must be 'null' or an integer!"
161178fi
162179
163- # Set the server type/instance type (default: cx22)
164- # If INPUT_SERVER_TYPE is set, use its value; otherwise, use "cx22".
165- MY_SERVER_TYPE=${INPUT_SERVER_TYPE:- " cx22" }
166-
167- # Set maximal wait time (retries * 10 sec) for Hetzner Cloud Server (default: 30 [5 min])
168- # If INPUT_SERVER_WAIT is set, use its value; otherwise, use "30".
169- MY_SERVER_WAIT=${INPUT_SERVER_WAIT:- " 30" }
170- # Check if MY_RUNNER_WAIT is an integer
171- if [[ ! " $MY_SERVER_WAIT " =~ ^[0-9]+$ ]]; then
172- exit_with_failure " The maximum wait time (reties) for a running Hetzner Cloud Server must be an integer!"
173- fi
174-
175- # Set the SSH key to use for the instance (default: null)
176- # If INPUT_SSH_KEY is set, use its value; otherwise, use "null".
177- MY_SSH_KEY=${INPUT_SSH_KEY:- " null" }
178- # Check if MY_SSH_KEY is an integer
179- if [[ " $MY_SSH_KEY " != " null" && ! " $MY_SSH_KEY " =~ ^[0-9]+$ ]]; then
180- exit_with_failure " The SSH key ID must be 'null' or an integer!"
181- fi
182-
183180# Set default GitHub Actions Runner installation directory (default: /actions-runner)
184181# If INPUT_RUNNER_DIR is set, its value is used. Otherwise, the default value "/actions-runner" is used.
185182MY_RUNNER_DIR=${INPUT_RUNNER_DIR:- " /actions-runner" }
@@ -197,24 +194,37 @@ if [[ "$MY_RUNNER_VERSION" != "latest" && "$MY_RUNNER_VERSION" != "skip" && ! "$
197194 exit_with_failure " '$MY_RUNNER_VERSION ' is not a valid GitHub Actions Runner version! Enter 'latest', 'skip' or the version without 'v'."
198195fi
199196
200- # Set maximal wait time ( retries * 10 sec) for GitHub Actions Runner registration (default: 60 [10 min])
197+ # Set maximal retries * WAIT_SEC ( 10 sec) for GitHub Actions Runner registration (default: 60 [10 min])
201198# If INPUT_RUNNER_WAIT is set, use its value; otherwise, use "60".
202199MY_RUNNER_WAIT=${INPUT_RUNNER_WAIT:- " 60" }
203200# Check if MY_RUNNER_WAIT is an integer
204201if [[ ! " $MY_RUNNER_WAIT " =~ ^[0-9]+$ ]]; then
205202 exit_with_failure " The maximum wait time (retries) for GitHub Action Runner registration must be an integer!"
206203fi
207204
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}
211- if [[ ! " $MY_CREATE_WAIT " =~ ^[0-9]+$ ]]; then
212- exit_with_failure " The maximum wait time (retries) for Hetzner Server creation must be an integer!"
213- fi
214-
215205# Set Hetzner Cloud Server ID
206+ # Check only if mode is delete.
216207MY_HETZNER_SERVER_ID=${INPUT_SERVER_ID}
217208
209+ # Set the server type/instance type (default: cx22)
210+ # If INPUT_SERVER_TYPE is set, use its value; otherwise, use "cx22".
211+ MY_SERVER_TYPE=${INPUT_SERVER_TYPE:- " cx22" }
212+
213+ # Set maximal retries * WAIT_SEC (10 sec) for Hetzner Cloud Server (default: 30 [5 min])
214+ # If INPUT_SERVER_WAIT is set, use its value; otherwise, use "30".
215+ MY_SERVER_WAIT=${INPUT_SERVER_WAIT:- " 30" }
216+ # Check if MY_RUNNER_WAIT is an integer
217+ if [[ ! " $MY_SERVER_WAIT " =~ ^[0-9]+$ ]]; then
218+ exit_with_failure " The maximum wait time (reties) for a running Hetzner Cloud Server must be an integer!"
219+ fi
220+
221+ # Set the SSH key to use for the instance (default: null)
222+ # If INPUT_SSH_KEY is set, use its value; otherwise, use "null".
223+ MY_SSH_KEY=${INPUT_SSH_KEY:- " null" }
224+ # Check if MY_SSH_KEY is an integer
225+ if [[ " $MY_SSH_KEY " != " null" && ! " $MY_SSH_KEY " =~ ^[0-9]+$ ]]; then
226+ exit_with_failure " The SSH key ID must be 'null' or an integer!"
227+ fi
218228
219229#
220230# DELETE
@@ -228,9 +238,13 @@ if [[ "$MY_MODE" == "delete" ]]; then
228238
229239 # Send a DELETE request to the Hetzner Cloud API to delete the server.
230240 # https://docs.hetzner.cloud/#servers-delete-a-server
241+ # curl retry: https://everything.curl.dev/usingcurl/downloads/retry.html
231242 echo " Delete server..."
232243 curl \
233244 -X DELETE \
245+ --retry " $MY_DELETE_WAIT " \
246+ --retry-delay " $WAIT_SEC " \
247+ --retry-all-errors \
234248 --fail-with-body \
235249 -H " Content-Type: application/json" \
236250 -H " Authorization: Bearer ${MY_HETZNER_TOKEN} " \
372386# https://docs.hetzner.cloud/#servers-create-a-server
373387MAX_RETRIES=$MY_CREATE_WAIT
374388RETRY_COUNT=0
375- WAIT_SEC=10
376389while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
377390 echo " Create Server..."
378391 if curl \
0 commit comments