You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: action.yml
+31-2Lines changed: 31 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ inputs:
37
37
required: false
38
38
default: ''
39
39
hostname:
40
-
description: 'Fixed hostname to use.'
40
+
description: 'Fixed hostname to use. Must be a valid DNS label (alphanumeric and dashes only, 1-63 characters, cannot start or end with a dash). If not provided, a hostname will be generated based on the runner name.'
41
41
required: false
42
42
default: ''
43
43
statedir:
@@ -301,13 +301,42 @@ runs:
301
301
TIMEOUT: ${{ inputs.timeout }}
302
302
RETRY: ${{ inputs.retry }}
303
303
run: |
304
+
sanitize_hostname() {
305
+
local hostname="$1"
306
+
hostname=$(echo "$hostname" | sed 's/[^a-zA-Z0-9-]/-/g') # Replace invalid characters with dashes
307
+
hostname=$(echo "$hostname" | cut -c1-63) # Truncate to 63 characters maximum
308
+
hostname=$(echo "$hostname" | sed 's/^-*//;s/-*$//') # Remove leading/trailing dashes
309
+
echo "$hostname"
310
+
}
311
+
312
+
is_valid_dns_label() {
313
+
local hostname="$1"
314
+
if [ ${#hostname} -eq 0 ] || [ ${#hostname} -gt 63 ]; then # Check length (1-63 characters)
315
+
return 1
316
+
fi
317
+
if ! echo "$hostname" | grep -qE '^[a-zA-Z0-9-]+$'; then # Check for valid characters (alphanumeric and dashes only)
318
+
return 1
319
+
fi
320
+
if echo "$hostname" | grep -qE '^-|-$'; then # Check that it doesn't start or end with dash
321
+
return 1
322
+
fi
323
+
return 0
324
+
}
325
+
304
326
if [ -z "${HOSTNAME}" ]; then
305
327
if [ "${{ runner.os }}" == "Windows" ]; then
306
328
HOSTNAME="github-$COMPUTERNAME"
307
-
else
329
+
else
308
330
HOSTNAME="github-$(hostname)"
309
331
fi
332
+
HOSTNAME=$(sanitize_hostname "$HOSTNAME")
333
+
else
334
+
if ! is_valid_dns_label "$HOSTNAME"; then
335
+
echo "::error::HOSTNAME '$HOSTNAME' is not a valid DNS label. It should contain only alphanumeric characters and dashes, be 1-63 characters long, and not start or end with a dash."
0 commit comments