Skip to content

Commit 00b0072

Browse files
authored
Improve cleanup script (#369)
Apparently gcloud can handle relative dates already. Also slightly reduce the run frequency.
1 parent b76ed88 commit 00b0072

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

.github/workflows/cleanup.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'Cleanup'
22

33
on:
44
schedule:
5-
- cron: '0 */4 * * *'
5+
- cron: '0 */6 * * *'
66
workflow_dispatch:
77

88
permissions:
@@ -25,12 +25,14 @@ jobs:
2525

2626
- name: Delete services
2727
run: |-
28-
BUFFER="$(TZ=GMT+4 date +%Y-%m-%d)"
29-
3028
gcloud config set core/project "${{ secrets.PROJECT_ID }}"
3129
gcloud config set functions/region "us-central1"
3230
33-
(IFS=$'\n'; for NAME in $(gcloud functions list --format="value(name)" --filter="updateTime.date('%Y-%m-%d', Z) < '${BUFFER}'"); do
31+
# List and delete all functions that were deployed 30 minutes ago or
32+
# earlier. The date math here is a little weird, but we're looking for
33+
# deployments "earlier than" 30 minutes ago, so it's less than since
34+
# time increases.
35+
(IFS=$'\n'; for NAME in $(gcloud functions list --format="value(name)" --filter="updateTime < '-pt30m'"); do
3436
echo "Deleting ${NAME}..."
3537
gcloud functions delete ${NAME} --quiet
3638
done)

0 commit comments

Comments
 (0)