Skip to content

cleanup

cleanup #462

Workflow file for this run

# 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 * *'
jobs:
# cleanup-revisions deletes all Cloud Run revisions for api, public key, cert
# rotator, ui services when the revison is more than 5 hours old.
cleanup-revisions:
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11' # ratchet:actions/checkout@v4
- uses: 'google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c' # ratchet:google-github-actions/auth@v2
with:
workload_identity_provider: '${{ vars.WIF_PROVIDER }}'
service_account: '${{ vars.WIF_SERVICE_ACCOUNT }}'
- uses: 'google-github-actions/setup-gcloud@98ddc00a17442e89a24bbf282954a3b65ce6d200' # ratchet:google-github-actions/setup-gcloud@v2
- name: 'Remove old Cloud Run revisions'
env:
SERVICES: 'jvs-api-4527 jvs-cert-rotator-e04a jvs-public-key-f22e jvs-ui-8ab7'
run: |-
for SERVICE in ${SERVICES}; do
echo "🧹 Cleaning up revisions for ${SERVICE}..."
REVISIONS=$(gcloud run revisions list \
--project="${PROJECT_ID}" \
--region="us-central1" \
--service="${SERVICE}" \
--format="value(name)" \
--sort-by="~metadata.creationTimestamp" \
--filter="metadata.creationTimestamp < '-p5h'" | sed 1d)
IFS=$'\n'; for NAME in $REVISIONS; do
echo "Deleting ${NAME}..."
gcloud run revisions delete ${NAME} \
--quiet \
--verbosity="warning" \
--no-user-output-enabled \
--project="${PROJECT_ID}" \
--region="us-central1" \
--async
done
done