Skip to content

Commit 7d3ef90

Browse files
committed
Add a workflow to delete a self-hosted runner VM
Since we're using ephemeral runners, the VMs are no longer used after they completed a workflow job, and need to be deleted. This GitHub workflow is designed to perform that action, and it is intended to be triggered by the GitForWindowsHelper GitHub App in response to receiving a `workflow_job.completed` event. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c39dbf0 commit 7d3ef90

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: delete azure-self-hosted-runner
2+
run-name: Delete ${{ inputs.runner_name }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
runner_name:
8+
type: string
9+
required: true
10+
description: The name of the runner that needs to be deleted
11+
12+
env:
13+
ACTIONS_RUNNER_NAME: ${{ github.event.inputs.runner_name }}
14+
15+
# The following secrets are required for this workflow to run:
16+
# AZURE_CREDENTIALS - Credentials for the Azure CLI. It's recommended to set up a resource
17+
# group specifically for self-hosted Actions Runners.
18+
# az ad sp create-for-rbac --name "{YOUR_DESCRIPTIVE_NAME_HERE}" --role contributor \
19+
# --scopes /subscriptions/{SUBSCRIPTION_ID_HERE}/resourceGroups/{RESOURCE_GROUP_HERE} \
20+
# --sdk-auth
21+
# AZURE_RESOURCE_GROUP - Resource group to create the runner(s) in
22+
jobs:
23+
delete-runner:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Azure Login
27+
uses: azure/login@v1
28+
with:
29+
creds: ${{ secrets.AZURE_CREDENTIALS }}
30+
- name: Delete VM '${{ env.ACTIONS_RUNNER_NAME }}'
31+
uses: azure/CLI@v1
32+
with:
33+
azcliversion: 2.43.0
34+
inlineScript: |
35+
az vm delete -n "$ACTIONS_RUNNER_NAME" -g ${{ secrets.AZURE_RESOURCE_GROUP }} --yes
36+
az network nsg delete -n "$ACTIONS_RUNNER_NAME"-nsg -g ${{ secrets.AZURE_RESOURCE_GROUP }}
37+
az network vnet delete -n "$ACTIONS_RUNNER_NAME"-vnet -g ${{ secrets.AZURE_RESOURCE_GROUP }}
38+
az network public-ip delete -n "$ACTIONS_RUNNER_NAME"-ip -g ${{ secrets.AZURE_RESOURCE_GROUP }}

0 commit comments

Comments
 (0)