Skip to content

Commit f22b188

Browse files
committed
Add label input to allow recreating the VM
1 parent a36405b commit f22b188

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

action.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ disk_size=
2828
image_project=
2929
image=
3030
image_family=
31+
label=
3132
scopes=
3233
shutdown_timeout=
3334
task=
@@ -44,6 +45,7 @@ while getopts_long :h opt \
4445
image_project optional_argument \
4546
image optional_argument \
4647
image_family optional_argument \
48+
label optional_argument \
4749
scopes required_argument \
4850
shutdown_timeout required_argument \
4951
task required_argument \
@@ -79,6 +81,9 @@ while getopts_long :h opt \
7981
image_family)
8082
image_family=${OPTLARG-$image_family}
8183
;;
84+
label)
85+
label=${OPTLARG-$label}
86+
;;
8287
scopes)
8388
scopes=$OPTLARG
8489
;;
@@ -102,6 +107,10 @@ done
102107

103108
function start_vm {
104109
VM_ID="runner-$(echo ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}-${task} | sha1sum | cut -f 1 -d " ")"
110+
if [ ! -z "${label}" ]; then
111+
echo "Label provided, using it as VM ID (${label})"
112+
VM_ID="${label}"
113+
fi
105114

106115
if [ ! -z "$(gcloud compute instances list | grep "${VM_ID}")" ]; then
107116
# the VM already exists.
@@ -114,7 +123,7 @@ function start_vm {
114123
fi
115124

116125
echo "Starting GCE VM ..."
117-
if [ -z "$runner_token" ]; then
126+
if [ -z "$runner_token" ]; then
118127
echo "❌ runner_token parameter is required"
119128
exit 1
120129
fi
@@ -123,7 +132,7 @@ function start_vm {
123132
-H "Authorization: Bearer $runner_token" \
124133
"https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runners/registration-token" |
125134
jq -r .token)
126-
if [ -z "$RUNNER_TOKEN" ]; then
135+
if [ -z "$RUNNER_TOKEN" ]; then
127136
echo "❌ Failed to get a registration token"
128137
exit 1
129138
fi
@@ -202,10 +211,10 @@ REMOVE_TOKEN=\$(curl \
202211
-H "Accept: application/vnd.github+json" \
203212
-H "Authorization: Bearer ${RUNNER_TOKEN}" \
204213
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/remove-token | jq .token --raw-output)
205-
if [ -z "\$REMOVE_TOKEN" ]; then
214+
if [ -z "\$REMOVE_TOKEN" ]; then
206215
echo "❌ Failed to get a removal token"
207216
exit 0
208-
fi
217+
fi
209218
210219
su -s /bin/bash -c "cd /actions-runner/;/actions-runner-1/config.sh remove --token \${REMOVE_TOKEN}" runner
211220
su -s /bin/bash -c "cd /actions-runner/;/actions-runner-2/config.sh remove --token \${REMOVE_TOKEN}" runner

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ inputs:
3939
image_family:
4040
description: The image family for the operating system that the boot disk will be initialized with.
4141
required: false
42+
label:
43+
description: >-
44+
Runner label. Can be set to override the VM name to recreate a runner with a specific label,
45+
e.g. to replace a runner that was shutdown. If set, 'task' will be ignored.
46+
required: false
4247
scopes:
4348
description: Scopes granted to the VM, defaults to full access (cloud-platform).
4449
default: cloud-platform
@@ -108,5 +113,6 @@ runs:
108113
--image_project=${{ inputs.image_project }} \
109114
--image=${{ inputs.image }} \
110115
--image_family=${{ inputs.image_family }} \
116+
--label=${{ inputs.label }} \
111117
--boot_disk_type=pd-ssd \
112118
--task=${{ inputs.task }}

0 commit comments

Comments
 (0)