Skip to content

Commit 7f0fe34

Browse files
committed
cleanup-self-hosted-runner: order the conditional blocks from small to large
In general, if..else..fi constructs are more readable when the first block is shorter than the second, i.e. to handle the "easy" things first; According to Cognitive Load Theory, this uses less mental resources when wrapping our head around the code. In this instance, there is an even better reason: The next commit will add _another_ condition, and having it in this order will avoid adding another nesting level: if too young skip else if busy skip else force delete VM fi Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9beb913 commit 7f0fe34

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ jobs:
4444
vm_creation_iso_string=$(echo $active_vm | jq -r '.timeCreated')
4545
vm_creation_time=$(date -d $vm_creation_iso_string +%s)
4646
47-
if [ "$three_hours_ago" -ge "$vm_creation_time" ]; then
47+
if [ "$three_hours_ago" -lt "$vm_creation_time" ]; then
48+
echo "The VM ${vm_name} was created less then 3 hours ago and shouldn't be deleted yet. Skipping."
49+
else
4850
echo "The VM ${vm_name} was created more than 3 hours ago and wasn't deleted. Let's do that now."
4951
az vm delete -n "$vm_name" -g ${{ secrets.AZURE_RESOURCE_GROUP }} --yes
5052
az network nsg delete -n "$vm_name"-nsg -g ${{ secrets.AZURE_RESOURCE_GROUP }}
5153
az network vnet delete -n "$vm_name"-vnet -g ${{ secrets.AZURE_RESOURCE_GROUP }}
5254
az network public-ip delete -n "$vm_name"-ip -g ${{ secrets.AZURE_RESOURCE_GROUP }}
53-
else
54-
echo "The VM ${vm_name} was created less then 3 hours ago and shouldn't be deleted yet. Skipping."
5555
fi
5656
done

0 commit comments

Comments
 (0)