-
Notifications
You must be signed in to change notification settings - Fork 41
50 lines (42 loc) · 1.42 KB
/
sub_clean-and-delete-runner.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This workflow is a reusable one called by other workflows
name: (template) Clean and delete GitHub Actions runner on GCP
on:
workflow_call:
# Variables to set when calling this reusable workflow
inputs:
runner_hostname:
required: true
type: string
zone:
required: true
type: string
# Secrets to set when calling this reusable workflow
secrets:
credentials:
required: true
jobs:
clean-delete:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate to GCP
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.credentials }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v2
- name: Delete runner
run: |
# Disable failure on first error, needed for the "delete" check
set +e
# If runner is already deleted we can bypass the error
if ! LOGS=$(gcloud --quiet compute instances delete ${{ inputs.runner_hostname }} \
--delete-disks all \
--zone ${{ inputs.zone }} 2>&1); then
echo "${LOGS}" | grep -q "resource .* was not found" || RC=1
# Show logs in case of error
(( RC )) && echo "${LOGS}" || true
fi
# Force exit with the *real* error code
exit ${RC:-0}