-
Notifications
You must be signed in to change notification settings - Fork 6
53 lines (46 loc) · 1.76 KB
/
delete-runner-service.yml
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
51
52
53
name: Destroy from GCP
on:
repository_dispatch:
types: [destroy-selfhosted]
env:
NAME_RUNNER: "ghe-runner-gcp-${{github.event.client_payload.issue}}"
jobs:
destroy-runner-and-vm:
runs-on: ubuntu-latest
steps:
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '281.0.0'
service_account_email: ${{ secrets.SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- run: gcloud projects list
- run: |
gcloud config set project octodemo
- name: get runner id
run: |
echo ::set-env name=RUNNER_ID::$(curl --location --request GET 'https://api.github.com/repos/${{ github.repository }}/actions/runners' --header 'Authorization: token ${{ secrets.RDP_TOKEN }}' | jq '.runners[0].id')
- name: delete runner from repo
run: |
curl --location --request DELETE "https://api.github.com/repos/${{ github.repository }}/actions/runners/$RUNNER_ID" --header 'Authorization: token ${{ secrets.RDP_TOKEN }}'
- name: delete vm
run: |
gcloud compute instances delete ${{ env.NAME_RUNNER }} --zone=europe-west3-c --quiet
- name: Update issue
env:
issue_number: '${{github.event.client_payload.issue}}'
uses: actions/github-script@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { issue_number } = process.env;
github.issues.createComment({
...context.repo,
issue_number: issue_number,
body: 'Destroyed self-hosted runner successfully!'
})
github.issues.removeLabel({
...context.repo,
issue_number: issue_number,
name: 'deployed'
})