11name : ' Cleanup'
22
33on :
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:
1224jobs :
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
@@ -24,19 +43,21 @@ jobs:
2443 - uses : ' google-github-actions/setup-gcloud@v2' # ratchet:exclude
2544 with :
2645 version : ' latest'
46+ skip_tool_cache : true
2747
28- - name : ' Delete services '
48+ - name : ' Delete ${{ matrix.target }} '
2949 env :
3050 PROJECT_ID : ' ${{ vars.PROJECT_ID }}'
51+ TARGET : ' ${{ matrix.target }}'
3152 run : |-
3253 gcloud config set core/project "${PROJECT_ID}"
3354 gcloud config set run/region "us-central1"
3455
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
56+ # List and delete all jobs/ services that were deployed 30 minutes ago
57+ # or earlier. The date math here is a little weird, but we're looking
58+ # for deployments "earlier than" 30 minutes ago, so it's less than
59+ # since time increases.
60+ (IFS=$'\n'; for NAME in $(gcloud run "${TARGET}" list --format='value(name)' --filter='metadata.creationTimestamp < "-pt30m"'); do
4061 echo "Deleting ${NAME}..."
41- gcloud run services delete "${NAME}" --quiet --async
62+ gcloud run "${TARGET}" delete "${NAME}" --quiet --async
4263 done)
0 commit comments