Cleanup #2203
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Cleanup' | |
on: | |
schedule: | |
- cron: '0 */6 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
jobs: | |
cleanup: | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: 'actions/checkout@v4' | |
- uses: 'google-github-actions/auth@v2' | |
with: | |
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}' | |
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' | |
- uses: 'google-github-actions/setup-gcloud@v2' | |
with: | |
version: 'latest' | |
- name: 'Delete services' | |
run: |- | |
gcloud config set core/project "${{ vars.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 | |
echo "Deleting ${NAME}..." | |
gcloud run services delete ${NAME} --quiet --async | |
done) |