@@ -3,94 +3,64 @@ name: (template) Clean and delete GitHub Actions runner on GCP
3
3
4
4
on :
5
5
workflow_call :
6
- # Jobs inputs
6
+ # Variables to set when calling this reusable workflow
7
7
inputs :
8
8
create_runner_result :
9
9
description : Status of the create-runner job
10
10
required : true
11
11
type : string
12
12
destroy_runner :
13
- description : Destroy the auto-generated self-hosted runner
14
- default : true
13
+ required : true
15
14
type : boolean
16
- qase_run_id :
17
- description : Case run ID where the results will be reported
18
- type : string
19
- runner :
20
- description : Name of the GCP runner
15
+ runner_hostname :
21
16
required : true
22
17
type : string
23
18
steps_status :
24
19
description : Status of all the steps from the previous job
25
20
required : true
26
21
type : string
27
- uuid :
28
- description : UUID of the GitHub runner
22
+ runner_label :
29
23
required : true
30
24
type : string
31
25
zone :
32
- description : GCP zone to host the runner
33
- default : us-central1-a
26
+ required : true
34
27
type : string
28
+
35
29
# Secrets to set when calling this reusable workflow
36
30
secrets :
37
31
credentials :
38
- description : Credentials to use to connect
39
32
required : true
40
33
pat_token :
41
- # A token is needed to be able to add runner on the repo, maybe this can be changed later
42
- # This token is linked to a personal account
43
- # So in case of token issue you have to check (no specific order and for example):
44
- # - the expiration date
45
- # - if the account associated still exists
46
- # - if the person still has access to the repo
47
- description : PAT token used to add runner
48
34
required : true
49
- qase_api_token :
50
- description : Qase API token to use for Cypress tests
51
35
52
36
jobs :
53
37
clean-delete :
54
38
runs-on : ubuntu-latest
55
- # Don't block if a step fails
56
- continue-on-error : true
57
- env :
58
- # QASE variables
59
- QASE_API_TOKEN : ${{ secrets.qase_api_token }}
60
- QASE_PROJECT_CODE : ELEMENTAL
61
- QASE_RUN_ID : ${{ inputs.qase_run_id }}
62
39
steps :
63
40
- name : Checkout
64
41
uses : actions/checkout@v4
65
- - name : Setup Go
66
- uses : actions/setup-go@v5
67
- with :
68
- cache-dependency-path : tests/go.sum
69
- go-version-file : tests/go.mod
70
- - name : Finalize Qase Run and publish Results
71
- if : ${{ env.QASE_RUN_ID != '' && !contains(inputs.steps_status, 'cancelled') }}
72
- run : cd tests && make publish-qase-run
73
- - name : Delete Qase Run if job has been cancelled
74
- if : ${{ env.QASE_RUN_ID != '' && contains(inputs.steps_status, 'cancelled') }}
75
- run : cd tests && make delete-qase-run
42
+
76
43
- name : Authenticate to GCP
77
44
uses : google-github-actions/auth@v2
78
45
with :
79
46
credentials_json : ${{ secrets.credentials }}
47
+
80
48
- name : Setup gcloud
81
49
uses : google-github-actions/setup-gcloud@v2
50
+
82
51
- name : Delete GCP secrets
83
52
run : |
84
53
for SECRET in PAT_TOKEN GH_REPO; do
85
- gcloud --quiet secrets delete ${SECRET}_${{ inputs.uuid }} || true
54
+ gcloud --quiet secrets delete ${SECRET}_${{ inputs.runner_label }} || true
86
55
done
56
+
87
57
- name : Delete runner
88
58
if : ${{ inputs.create_runner_result == 'success' && inputs.destroy_runner == true }}
89
59
run : |
90
60
# Disable failure on first error, needed for the "delete" check
91
61
set +e
92
62
# If runner is already deleted we can bypass the error
93
- if ! LOGS=$(gcloud --quiet compute instances delete ${{ inputs.runner }} \
63
+ if ! LOGS=$(gcloud --quiet compute instances delete ${{ inputs.runner_hostname }} \
94
64
--delete-disks all \
95
65
--zone ${{ inputs.zone }} 2>&1); then
96
66
echo "${LOGS}" | grep -q "resource .* was not found" || RC=1
0 commit comments