-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaction.yml
More file actions
111 lines (100 loc) · 3.34 KB
/
Copy pathaction.yml
File metadata and controls
111 lines (100 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: "Create Hetzner Servers"
author: "Igor Pecovnik"
description: "Create Hetzner Cloud servers via matrix strategy"
inputs:
action:
required: true
description: "Action: 'create' or 'delete'"
server-type:
required: false
description: "Hetzner server type (e.g., cax21, cax31, cax41)"
default: "cax31"
image:
required: false
description: "OS image name"
default: "ubuntu-24.04"
ssh-key:
required: false
description: "SSH key name in Hetzner Cloud (required for create, optional for delete)"
index:
required: false
description: "Server index (for matrix builds)"
default: "0"
delete-existing:
required: false
description: "Delete existing server before creating"
default: "false"
hetzner-token:
required: true
description: "Hetzner Cloud API token"
github-token:
required: false
description: "GitHub token for runner registration (required for create action)"
runner-count:
required: false
description: "Number of runners per machine"
default: "2"
runs:
using: "composite"
steps:
- name: Setup Python
shell: bash
run: |
if command -v python3 &> /dev/null; then
echo "Python3 already installed"
else
echo "Installing Python3..."
apt-get update -qq
apt-get install -y -qq python3 python3-pip
fi
- name: Install hcloud
shell: bash
run: |
pip3 install --break-system-packages hcloud || pip3 install hcloud
- name: Create/Delete Hetzner Server
shell: bash
env:
HCLOUD_TOKEN: ${{ inputs.hetzner-token }}
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
set -e
CMD="python3 ${{ github.action_path }}/create_servers.py \
${{ inputs.action }} \
--server-type ${{ inputs.server-type }} \
--image ${{ inputs.image }} \
--index ${{ inputs.index }}"
# Only add ssh-key if provided
if [[ -n "${{ inputs.ssh-key }}" ]]; then
CMD="${CMD} --ssh-key ${{ inputs.ssh-key }}"
fi
if [[ "${{ inputs.action }}" == "create" ]]; then
CMD="${CMD} --count 1 --runner-count ${{ inputs.runner-count }}"
if [[ "${{ inputs.delete-existing }}" == "true" ]]; then
CMD="${CMD} --delete-existing"
fi
else
CMD="${CMD} --count 1"
fi
echo "Running: $CMD"
# Stream the script's output live AND capture it for the summary. Do NOT
# use a plain `RESULT=$(eval $CMD)`: under `set -e` that command
# substitution aborts the step the instant the script exits non-zero, so
# its output (captured into RESULT, not yet printed) is lost and the
# failure looks silent. tee shows the output live; PIPESTATUS[0] is the
# script's real exit code (not tee's).
result_log="$(mktemp)"
set +e
eval "$CMD" 2>&1 | tee "$result_log"
EXIT_CODE=${PIPESTATUS[0]}
set -e
{
echo "### Result (exit ${EXIT_CODE})"
echo '```'
cat "$result_log"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
rm -f "$result_log"
if [ "$EXIT_CODE" -ne 0 ]; then
echo "::error::Hetzner ${{ inputs.action }} failed (exit ${EXIT_CODE}) — see the script output above"
exit "$EXIT_CODE"
fi