cleanup #844
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
# Copyright 2023 The Authors (see AUTHORS file) | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
name: 'cleanup' | |
on: | |
pull_request: | |
paths: | |
- '.github/workflows/cleanup.yml' | |
schedule: | |
- cron: '0 0 */1 * *' | |
workflow_dispatch: | |
env: | |
WIF_PROVIDER: 'projects/567170510917/locations/global/workloadIdentityPools/github-automation/providers/lumberjack-ci-i' | |
WIF_SERVICE_ACCOUNT: 'github-automation-bot@gha-lumberjack-ci-i-9d0848.iam.gserviceaccount.com' | |
REGION: 'us-central1' | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
jobs: | |
# cleanup_cloudrun_services deletes all Cloud Run services that are more than | |
# 5 days old, since sometimes services are not deleted during integration | |
# tests. | |
cleanup_cloudrun_services: | |
strategy: | |
matrix: | |
# Lumberjack CI deploys cloud run services in these projects. | |
project: ['lumberjack-app-i-84af7b', 'lumberjack-server-i-8eb3ef'] | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4 | |
- uses: 'google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f' # ratchet:google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: '${{ env.WIF_PROVIDER }}' | |
service_account: '${{ env.WIF_SERVICE_ACCOUNT }}' | |
- uses: 'google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a' # ratchet:google-github-actions/setup-gcloud@v2 | |
- name: 'Remove old Cloud Run services' | |
shell: 'bash' | |
run: |- | |
gcloud config set core/project "${{ matrix.project }}" | |
gcloud config set run/region "${{ env.REGION }}" | |
# List and delete all services that were deployed 5 days ago or later. | |
(IFS=$'\n'; for NAME in $(gcloud run services list --format="value(name)" --filter="metadata.creationTimestamp < '-p5d'"); do | |
echo "Deleting ${NAME}..." | |
gcloud run services delete ${NAME} --quiet --async | |
done) |