Skip to content

Commit 5819800

Browse files
authored
Also cleanup cloudrun jobs (#572)
1 parent 1477328 commit 5819800

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

.github/workflows/cleanup.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
name: 'Cleanup'
22

33
on:
4+
pull_request:
5+
branches:
6+
- 'main'
7+
- 'release/**'
8+
paths:
9+
- '.github/workflows/cleanup.yml'
10+
push:
11+
branches:
12+
- 'main'
13+
- 'release/**'
14+
paths:
15+
- '.github/workflows/cleanup.yml'
416
schedule:
517
- cron: '0 */6 * * *'
618
workflow_dispatch:
@@ -12,6 +24,13 @@ permissions:
1224
jobs:
1325
cleanup:
1426
runs-on: 'ubuntu-latest'
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
target:
31+
- 'jobs'
32+
- 'services'
33+
name: 'Cleanup (${{ matrix.target }})'
1534

1635
steps:
1736
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
@@ -25,18 +44,19 @@ jobs:
2544
with:
2645
version: 'latest'
2746

28-
- name: 'Delete services'
47+
- name: 'Delete ${{ matrix.target }}'
2948
env:
3049
PROJECT_ID: '${{ vars.PROJECT_ID }}'
50+
TARGET: '${{ matrix.target }}'
3151
run: |-
3252
gcloud config set core/project "${PROJECT_ID}"
3353
gcloud config set run/region "us-central1"
3454
35-
# List and delete all services that were deployed 30 minutes ago or
36-
# earlier. The date math here is a little weird, but we're looking for
37-
# deployments "earlier than" 30 minutes ago, so it's less than since
38-
# time increases.
39-
(IFS=$'\n'; for NAME in $(gcloud run services list --format='value(name)' --filter='metadata.creationTimestamp < "-pt30m"'); do
55+
# List and delete all jobs/services that were deployed 30 minutes ago
56+
# or earlier. The date math here is a little weird, but we're looking
57+
# for deployments "earlier than" 30 minutes ago, so it's less than
58+
# since time increases.
59+
(IFS=$'\n'; for NAME in $(gcloud run "${TARGET}" list --format='value(name)' --filter='metadata.creationTimestamp < "-pt30m"'); do
4060
echo "Deleting ${NAME}..."
41-
gcloud run services delete "${NAME}" --quiet --async
61+
gcloud run "${TARGET}" delete "${NAME}" --quiet --async
4262
done)

0 commit comments

Comments
 (0)