Skip to content

Commit ab029b5

Browse files
committed
Check if the VM already exists
1 parent 811ab29 commit ab029b5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

action.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,23 @@ while getopts_long :h opt \
106106
done
107107

108108
function start_vm {
109+
VM_ID="gce-gh-runner-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
110+
111+
if [ ! -z "$(gcloud compute instances list | grep "${VM_ID}")" ]; then
112+
# the VM already exists.
113+
# this can happen when we call the action from a reusable workflow.
114+
# in these scenarios we don't want a new VM ;)
115+
echo "Skipping creation of new VM. Using the existing one."
116+
exit 0
117+
fi
118+
109119
echo "Starting GCE VM ..."
110120
RUNNER_TOKEN=$(curl -S -s -XPOST \
111121
-H "authorization: Bearer ${token}" \
112122
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/registration-token" |
113123
jq -r .token)
114124
echo "✅ Successfully got the GitHub Runner registration token"
115125

116-
VM_ID="gce-gh-runner-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
117126
image_project_flag=$([[ -z "${image_project}" ]] || echo "--image-project=${image_project}")
118127
image_flag=$([[ -z "${image}" ]] || echo "--image=${image}")
119128
image_family_flag=$([[ -z "${image_family}" ]] || echo "--image-family=${image_family}")

0 commit comments

Comments
 (0)