Skip to content

Commit a207952

Browse files
committed
cleanup-self-hosted-runner: avoid deleting VMs that are busy
So far, we avoid deleting VMs when they are too young. But we can do better than that: since the VMs are intended to host an ephemeral runner, and that runner is registered with the current repository, we can have a look whether GitHub says that the runner is busy. If it is, well, let's leave it a-running! Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7f0fe34 commit a207952

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

.github/workflows/cleanup-self-hosted-runners.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ jobs:
4646
4747
if [ "$three_hours_ago" -lt "$vm_creation_time" ]; then
4848
echo "The VM ${vm_name} was created less then 3 hours ago and shouldn't be deleted yet. Skipping."
49+
elif test true = "$(gh api repos/$GITHUB_REPOSITORY/actions/runners \
50+
--jq '.runners[] | select(.name == "'$vm_name'") | .busy)"; then
51+
echo "The VM ${vm_name} is still busy."
4952
else
5053
echo "The VM ${vm_name} was created more than 3 hours ago and wasn't deleted. Let's do that now."
5154
az vm delete -n "$vm_name" -g ${{ secrets.AZURE_RESOURCE_GROUP }} --yes

0 commit comments

Comments
 (0)