-
Notifications
You must be signed in to change notification settings - Fork 0
37 lines (30 loc) · 1.06 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
name: gcloud-cleanup
env:
GCLOUD_PROJECT_ID: kvaapagarrot
on:
schedule:
# At 00:00 every Sunday
- cron: '0 0 * * 0'
workflow_dispatch:
branches:
- main-kampf
jobs:
clean-up:
name: Clean-up old artifacts
runs-on: ubuntu-latest
steps:
- name: Import Service Account key
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" | base64 -d > /tmp/auth.json
- name: GCloud Auth
run: |
gcloud --quiet auth \
activate-service-account "${{ secrets.GCP_SA_EMAIL }}" \
--key-file=/tmp/auth.json \
--project="${GCLOUD_PROJECT_ID}"
# Get versions without traffic, sort by last deployed desc
# Skip output header along with two last deployed versions (=3 lines skip)
# Delete remaining
- name: Delete old versions
run: |
LIST=($(gcloud app versions list --service=default --sort-by="~LAST_DEPLOYED" --filter="TRAFFIC_SPLIT=0" | awk '{ print $2 }' | tail -n +4))
gcloud --quiet app versions delete --service=default "${LIST[@]:-''}"