-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (50 loc) · 2.16 KB
/
cleanup.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
54
55
56
57
58
59
60
name: CLEANUP
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v3'
- id: 'auth'
# here we authenticate with GCP using Service Account
# json stored in github secrets
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- id: 'setup'
# here we setup gcloud / Cloud SDK to use it
# later in the workflow
name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- id: 'list_buckets'
# here we list existing buckets to decide if
# the bucket needs to be deleted
name: 'List buckets'
run: echo buckets=$(gcloud storage buckets list --filter=name=${{ vars.GCS_BUCKET_NAME }} 2>&1) >> $GITHUB_OUTPUT
- id: 'remove_bucket'
name: "(OPT) Remove Cloud Storage bucket"
run: gcloud storage rm -r gs://${{ vars.GCS_BUCKET_NAME }}
if: ${{ steps.list_buckets.outputs.buckets != 'Listed 0 items.' }}
- id: 'list_functions'
# here we list existing functions to decide if
# the function needs to be deleted
name: 'List functions'
run: echo functions=$(gcloud functions list --filter=name~${{ vars.CLOUD_FUNCTION_NAME }} 2>&1) >> $GITHUB_OUTPUT
- id: 'remove_function'
# here we remove the function if we found it during last step
name: "(OPT) Remove Cloud Function"
run: gcloud functions delete ${{ vars.CLOUD_FUNCTION_NAME }}
if: ${{ steps.list_functions.outputs.functions != 'Listed 0 items.' }}
- id: 'notify'
# here we notify of successful build using pushover
# see https://pushover.net/ for details
name: "(OPT) Send push notification on success"
if: ${{ vars.NOTIFY }}
run: |
curl -s \
--form-string "token=${{ secrets.NOTIFY_TOKEN }}" \
--form-string "user=${{ secrets.NOTIFY_USER }}" \
--form-string "message=\"$GITHUB_WORKFLOW\" workflow finished successfully" \
https://api.pushover.net/1/messages.json