Skip to content

Commit 50cc22a

Browse files
committed
retry delete
1 parent 62495bf commit 50cc22a

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ jobs:
141141

142142
| Name | Required | Description | Default |
143143
|---------------------|----------|-------------|---------|
144-
| `create_wait` | | Wait up to 'create_wait' retries (10 sec each) to create the Hetzner Cloud Server resource. | `360` (1 hour) |
144+
| `create_wait` | | Wait up to `create_wait` retries (10 sec each) to create the Server resource via the Hetzner Cloud API. Retry if: Resource is not available ([Limited availability of Cloud plans](https://status.hetzner.com/incident/aa5ce33b-faa5-4fd0-9782-fde43cd270cf)). | `360` (1 hour) |
145+
| `delete_wait` | | Wait up to `delete_wait` retries (10 sec each) to delete the Server resource via the Hetzner Cloud API. Retry if: Temporary outage of the API ([Fault report on Cloud API and Cloud Console](https://status.hetzner.com/incident/440e6b5f-249c-45fd-8074-e5d79cc4e2a6)). | `360` (1 hour) |
145146
| `enable_ipv4` | | Attach an IPv4 on the public NIC (true/false). If false, no IPv4 address will be attached. Warning: The GitHub API requires IPv4. Disabling it will result in connection failures. | `true` |
146147
| `enable_ipv6` | | Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached. | `true` |
147148
| `github_token` | ✓ (always) | Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned. | |

action.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ done
5959
# https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#inputs
6060
# When you specify an input, GitHub creates an environment variable for the input with the name INPUT_<VARIABLE_NAME>.
6161

62+
# Set maximal retries * 10 seconds for Hetzner Server creation via the Hetzer Cloud API (default: 360 [1 hour])
63+
# If INPUT_CREATE_WAIT is set, use its value; otherwise, use "360".
64+
MY_CREATE_WAIT=${INPUT_CREATE_WAIT:-360}
65+
if [[ ! "$MY_CREATE_WAIT" =~ ^[0-9]+$ ]]; then
66+
exit_with_failure "The maximum wait time (retries) for Hetzner Server creation via the Hetzer Cloud API must be an integer!"
67+
fi
68+
69+
# Set maximal retries * 10 seconds for Hetzner Server deletion via the Hetzer Cloud API (default: 360 [1 hour])
70+
# If INPUT_DELETE_WAIT is set, use its value; otherwise, use "360".
71+
MY_DELETE_WAIT=${INPUT_DELETE_WAIT:-360}
72+
if [[ ! "$MY_DELETE_WAIT" =~ ^[0-9]+$ ]]; then
73+
exit_with_failure "The maximum wait time (retries) for Hetzner Server deletion via the Hetzer Cloud API must be an integer!"
74+
fi
75+
6276
# Set the Hetzner Cloud API token.
6377
# Retrieves the value from the INPUT_HCLOUD_TOKEN environment variable.
6478
MY_HETZNER_TOKEN=${INPUT_HCLOUD_TOKEN}
@@ -205,16 +219,12 @@ if [[ ! "$MY_RUNNER_WAIT" =~ ^[0-9]+$ ]]; then
205219
exit_with_failure "The maximum wait time (retries) for GitHub Action Runner registration must be an integer!"
206220
fi
207221

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-
215222
# Set Hetzner Cloud Server ID
216223
MY_HETZNER_SERVER_ID=${INPUT_SERVER_ID}
217224

225+
# Retry wait time in secounds
226+
WAIT_SEC=10
227+
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}" \
@@ -372,7 +386,6 @@ fi
372386
# https://docs.hetzner.cloud/#servers-create-a-server
373387
MAX_RETRIES=$MY_CREATE_WAIT
374388
RETRY_COUNT=0
375-
WAIT_SEC=10
376389
while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
377390
echo "Create Server..."
378391
if curl \

action.yml

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ branding:
77
color: 'red'
88

99
inputs:
10-
mode:
11-
description: >-
12-
Choose either 'create' to create a new GitHub Actions Runner or 'delete' to delete a previously created one.
13-
required: true
14-
github_token:
10+
create_wait:
1511
description: >-
16-
Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned.
17-
required: true
18-
hcloud_token:
12+
Wait up to 'create_wait' retries (10 sec each) to create the Server resource via the Hetzner Cloud API (default: 360 = 1 hour).
13+
required: false
14+
default: '360'
15+
delete_wait:
1916
description: >-
20-
Hetzner Cloud API token with 'Read & Write' permissions assigned.
21-
required: true
17+
Wait up to 'delete_wait' retries (10 sec each) to delete the Server resource via the Hetzner Cloud API (default: 360 = 1 hour).
18+
required: false
19+
default: '360'
2220
enable_ipv4:
2321
description: >-
2422
Attach an IPv4 on the public NIC (true/false) . If false, no IPv4 address will be attached.
@@ -30,6 +28,14 @@ inputs:
3028
Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached.
3129
required: false
3230
default: 'true'
31+
github_token:
32+
description: >-
33+
Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned.
34+
required: true
35+
hcloud_token:
36+
description: >-
37+
Hetzner Cloud API token with 'Read & Write' permissions assigned.
38+
required: true
3339
image:
3440
description: >-
3541
Name or ID (integer) of the Image the Server is created from.
@@ -40,6 +46,10 @@ inputs:
4046
Name of Location to create Server in.
4147
required: false
4248
default: 'nbg1'
49+
mode:
50+
description: >-
51+
Choose either 'create' to create a new GitHub Actions Runner or 'delete' to delete a previously created one.
52+
required: true
4353
name:
4454
description: >-
4555
The name for the server and label for the GitHub Actions Runner (must be unique within the project and conform to hostname rules: '[a-zA-Z0-9_-]').
@@ -49,6 +59,11 @@ inputs:
4959
Network ID (integer) which should be attached to the Server private network interface at the creation time.
5060
required: false
5161
default: 'null'
62+
pre_runner_script:
63+
description: >-
64+
Specifies bash commands to run before the GitHub Actions Runner starts.
65+
It's useful for installing dependencies with apt-get, dnf, zypper etc.
66+
required: false
5267
primary_ipv4:
5368
description: >-
5469
ID (integer) of the IPv4 Primary IP to use.
@@ -66,23 +81,18 @@ inputs:
6681
GitHub Actions Runner installation directory (created automatically; no trailing slash).
6782
required: false
6883
default: '/actions-runner'
84+
runner_wait:
85+
description: >-
86+
Wait up to 'runner_wait' retries (10 sec each) for runner registration (default: 10 minutes).
87+
required: false
88+
default: '60'
6989
runner_version:
7090
description: >-
7191
GitHub Actions Runner version (omit 'v'; e.g., '2.321.0').
7292
'latest' will install the latest version.
7393
'skip' will skip the installation. A working installation is expected in the 'runner_dir'.
7494
required: false
7595
default: 'latest'
76-
create_wait:
77-
description: >-
78-
Wait up to 'create_wait' retries (10 sec each) to create the Hetzner Cloud Server resource (default: 360 = 1 hour).
79-
required: false
80-
default: '360'
81-
runner_wait:
82-
description: >-
83-
Wait up to 'runner_wait' retries (10 sec each) for runner registration (default: 10 minutes).
84-
required: false
85-
default: '60'
8696
server_id:
8797
description: >-
8898
ID (integer) of Hetzner Cloud Server to delete.
@@ -102,11 +112,6 @@ inputs:
102112
SSH key ID (integer) or name which should be injected into the Server at creation time.
103113
required: false
104114
default: 'null'
105-
pre_runner_script:
106-
description: >-
107-
Specifies bash commands to run before the GitHub Actions Runner starts.
108-
It's useful for installing dependencies with apt-get, dnf, zypper etc.
109-
required: false
110115

111116
outputs:
112117
label:
@@ -128,6 +133,8 @@ runs:
128133
working-directory: ${{ github.action_path }}
129134
run: bash action.sh
130135
env:
136+
INPUT_CREATE_WAIT: ${{ inputs.create_wait }}
137+
INPUT_DELETE_WAIT: ${{ inputs.delete_wait }}
131138
INPUT_ENABLE_IPV4: ${{ inputs.enable_ipv4 }}
132139
INPUT_ENABLE_IPV6: ${{ inputs.enable_ipv6 }}
133140
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -147,4 +154,3 @@ runs:
147154
INPUT_SERVER_TYPE: ${{ inputs.server_type }}
148155
INPUT_SERVER_WAIT: ${{ inputs.server_wait }}
149156
INPUT_SSH_KEY: ${{ inputs.ssh_key }}
150-
INPUT_CREATE_WAIT: ${{ inputs.create_wait }}

0 commit comments

Comments
 (0)