Skip to content

Commit 3602ec7

Browse files
authored
Enc do not retry on delete 404 (#23)
1 parent 3e88e55 commit 3602ec7

3 files changed

Lines changed: 43 additions & 27 deletions

File tree

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,33 @@ jobs:
150150
> [!TIP]
151151
> Use an SSH key ID (`ssh_key`) to disable root password generation and Hetzner Cloud email notifications.
152152

153-
| Name | Required | Description | Default |
154-
|-----------------------|----------|-------------|---------|
155-
| `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) |
156-
| `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) |
157-
| `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` |
158-
| `enable_ipv6` | | Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached. | `true` |
159-
| `github_token` | ✓ (always) | Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned. | |
160-
| `hcloud_token` | ✓ (always) | Hetzner Cloud API token with 'Read & Write' permissions assigned. | |
161-
| `image` | | Name or ID (integer) of the Image the Server is created from. | `ubuntu-24.04` (Ubuntu 24.04) |
162-
| `location` | | Name of Location to create Server in. | `nbg1` (Nürnberg 1) |
163-
| `mode` | ✓ (always) | Choose either `create` to create a new GitHub Actions Runner or `delete` to delete a previously created one. | |
164-
| `name` | ✓ (mode `delete`, optional for mode `create`) | 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_-]{1,64}`). | `gh-runner-[RANDOM-INT]` |
165-
| `network` | | Comma separated Network IDs (integer) which should be attached to the Server private network interface at the creation time. | `null` |
166-
| `pre_runner_script` | | Specifies bash commands to run before the GitHub Actions Runner starts. It's useful for installing dependencies with apt-get, dnf, zypper etc. | |
167-
| `primary_ipv4` | | ID (integer) of the IPv4 Primary IP to use. If omitted and `enable_ipv4` is true, a new IPv4 Primary IP will automatically be created. | `null` |
168-
| `primary_ipv6` | | ID (integer) of the IPv6 Primary IP to use. If omitted and `enable_ipv6` is true, a new IPv6 Primary IP will automatically be created. | `null` |
169-
| `runner_dir` | | GitHub Actions Runner installation directory (created automatically; no trailing slash). | `/actions-runner` |
170-
| `runner_version` | | GitHub Actions Runner version (omit "v"; e.g., "2.321.0"). "latest" will install the latest version. "skip" will skip the installation. A working installation is expected in the `runner_dir`. | `latest` |
171-
| `runner_wait` | | Wait up to `runner_wait` retries (10 sec each) for runner registration. | `60` (10 min) |
172-
| `server_id` | ✓ (mode `stop`) | ID (integer) of Hetzner Cloud Server to delete. | |
173-
| `server_type` | | Name of the Server type this Server should be created with. | `cx23` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
174-
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
175-
| `ssh_key` | | Comma separated SSH key IDs (integer) which should be injected into the Server at creation time. | `null` |
176-
| `volume` | | Comma separated Volume IDs (integer) to attach and mount to the Server during creation. Volumes will be automatically mounted at `/mnt/HC_Volume_[VOLUME-ID]`. Volumes must be in the same location as the Server. More details in [Volumes section](#Volumes). | `null` |
177-
| `runner_scope` | | Select scope for this runner. 'org' creates a org-wide runner, while 'repo' creates a repo-only runner. | `repo` |
178-
| `runner_start_method` | | Defines how the GitHub runner process is started. Supported values are `standalone` and `systemd`. | `standalone` |
153+
| Name | Required | Description | Default |
154+
|---------------------------|----------|-------------|---------|
155+
| `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) |
156+
| `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) |
157+
| `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` |
158+
| `enable_ipv6` | | Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached. | `true` |
159+
| `github_token` | ✓ (always) | Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned. | |
160+
| `hcloud_token` | ✓ (always) | Hetzner Cloud API token with 'Read & Write' permissions assigned. | |
161+
| `image` | | Name or ID (integer) of the Image the Server is created from. | `ubuntu-24.04` (Ubuntu 24.04) |
162+
| `location` | | Name of Location to create Server in. | `nbg1` (Nürnberg 1) |
163+
| `mode` | ✓ (always) | Choose either `create` to create a new GitHub Actions Runner or `delete` to delete a previously created one. | |
164+
| `name` | ✓ (mode `delete`, optional for mode `create`) | 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_-]{1,64}`). | `gh-runner-[RANDOM-INT]` |
165+
| `network` | | Comma separated Network IDs (integer) which should be attached to the Server private network interface at the creation time. | `null` |
166+
| `pre_runner_script` | | Specifies bash commands to run before the GitHub Actions Runner starts. It's useful for installing dependencies with apt-get, dnf, zypper etc. | |
167+
| `primary_ipv4` | | ID (integer) of the IPv4 Primary IP to use. If omitted and `enable_ipv4` is true, a new IPv4 Primary IP will automatically be created. | `null` |
168+
| `primary_ipv6` | | ID (integer) of the IPv6 Primary IP to use. If omitted and `enable_ipv6` is true, a new IPv6 Primary IP will automatically be created. | `null` |
169+
| `runner_dir` | | GitHub Actions Runner installation directory (created automatically; no trailing slash). | `/actions-runner` |
170+
| `runner_version` | | GitHub Actions Runner version (omit "v"; e.g., "2.321.0"). "latest" will install the latest version. "skip" will skip the installation. A working installation is expected in the `runner_dir`. | `latest` |
171+
| `runner_wait` | | Wait up to `runner_wait` retries (10 sec each) for runner registration. | `60` (10 min) |
172+
| `server_id` | ✓ (mode `stop`) | ID (integer) of Hetzner Cloud Server to delete. | |
173+
| `server_type` | | Name of the Server type this Server should be created with. | `cx23` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
174+
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
175+
| `ssh_key` | | Comma separated SSH key IDs (integer) which should be injected into the Server at creation time. | `null` |
176+
| `volume` | | Comma separated Volume IDs (integer) to attach and mount to the Server during creation. Volumes will be automatically mounted at `/mnt/HC_Volume_[VOLUME-ID]`. Volumes must be in the same location as the Server. More details in [Volumes section](#Volumes). | `null` |
177+
| `runner_scope` | | Select scope for this runner. 'org' creates a org-wide runner, while 'repo' creates a repo-only runner. | `repo` |
178+
| `runner_start_method` | | Defines how the GitHub runner process is started. Supported values are `standalone` and `systemd`. | `standalone` |
179+
| `no_retry_on_delete_404` | | The action does not attempt to delete again if the API already returns a 404 Not Found. Supported values are `true` and `false`. | `false` |
179180

180181
## Outputs
181182

action.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ if [[ "$MY_VOLUMES" != "null" ]]; then
263263
}
264264
fi
265265

266+
# Do not retry delete if api return 404 (default: false)
267+
MY_NO_RETRY_ON_DELETE_404=${INPUT_NO_RETRY_ON_DELETE_404}
268+
if [[ "$MY_NO_RETRY_ON_DELETE_404" == true ]]; then
269+
SERVER_RETRY_OPT="--no-retry-all-errors"
270+
else
271+
SERVER_RETRY_OPT="--retry-all-errors"
272+
fi
273+
266274
#
267275
# DELETE
268276
#
@@ -281,7 +289,7 @@ if [[ "$MY_MODE" == "delete" ]]; then
281289
-X DELETE \
282290
--retry "$MY_DELETE_WAIT" \
283291
--retry-delay "$WAIT_SEC" \
284-
--retry-all-errors \
292+
"${SERVER_RETRY_OPT}" \
285293
--fail-with-body \
286294
-H "Content-Type: application/json" \
287295
-H "Authorization: Bearer ${MY_HETZNER_TOKEN}" \

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ inputs:
136136
Comma separated Volume IDs (integer) which should be attached to the Server at the creation time.
137137
required: false
138138
default: 'null'
139+
no_retry_on_delete_404:
140+
description: >-
141+
Do not retry delete if api return 404
142+
required: false
143+
default: false
144+
type: 'boolean'
139145

140146
outputs:
141147
label:
@@ -168,6 +174,7 @@ runs:
168174
INPUT_MODE: ${{ inputs.mode }}
169175
INPUT_NAME: ${{ inputs.name }}
170176
INPUT_NETWORKS: ${{ inputs.network }}
177+
INPUT_NO_RETRY_ON_DELETE_404: ${{ inputs.no_retry_on_delete_404 }}
171178
INPUT_PRE_RUNNER_SCRIPT: ${{ inputs.pre_runner_script }}
172179
INPUT_PRIMARY_IPV4: ${{ inputs.primary_ipv4 }}
173180
INPUT_PRIMARY_IPV6: ${{ inputs.primary_ipv6 }}

0 commit comments

Comments
 (0)