Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
name: 'Cleanup'

on:
pull_request:
branches:
- 'main'
- 'release/**'
paths:
- '.github/workflows/cleanup.yml'
push:
branches:
- 'main'
- 'release/**'
paths:
- '.github/workflows/cleanup.yml'
schedule:
- cron: '0 */6 * * *'
workflow_dispatch:
Expand All @@ -12,6 +24,13 @@ permissions:
jobs:
cleanup:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
target:
- 'jobs'
- 'services'
name: 'Cleanup (${{ matrix.target }})'

steps:
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
Expand All @@ -25,18 +44,19 @@ jobs:
with:
version: 'latest'

- name: 'Delete services'
- name: 'Delete ${{ matrix.target }}'
env:
PROJECT_ID: '${{ vars.PROJECT_ID }}'
TARGET: '${{ matrix.target }}'
run: |-
gcloud config set core/project "${PROJECT_ID}"
gcloud config set run/region "us-central1"

# List and delete all services that were deployed 30 minutes ago or
# earlier. The date math here is a little weird, but we're looking for
# deployments "earlier than" 30 minutes ago, so it's less than since
# time increases.
(IFS=$'\n'; for NAME in $(gcloud run services list --format='value(name)' --filter='metadata.creationTimestamp < "-pt30m"'); do
# List and delete all jobs/services that were deployed 30 minutes ago
# or earlier. The date math here is a little weird, but we're looking
# for deployments "earlier than" 30 minutes ago, so it's less than
# since time increases.
(IFS=$'\n'; for NAME in $(gcloud run "${TARGET}" list --format='value(name)' --filter='metadata.creationTimestamp < "-pt30m"'); do
echo "Deleting ${NAME}..."
gcloud run services delete "${NAME}" --quiet --async
gcloud run "${TARGET}" delete "${NAME}" --quiet --async
done)
Loading