cleanup #754
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/1022440990968/locations/global/workloadIdentityPools/github-automation/providers/gma-ci-i' | |
WIF_SERVICE_ACCOUNT: 'github-automation-bot@gha-gma-ci-i-8258a4.iam.gserviceaccount.com' | |
GAR_REPO: 'us-docker.pkg.dev/github-metrics-ci/ci-images' | |
INTEGRATION_PROJECT_ID: 'github-metrics-aggreg-i-64d426' | |
INTEGRATION_REGION: 'us-central1' | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
jobs: | |
# cleanup_cloudrun_revisions deletes all Webhook and Retry Cloud Run revisions | |
# for the given service that are more than 5 hours old. | |
cleanup_cloudrun_revisions: | |
runs-on: 'ubuntu-latest' | |
strategy: | |
matrix: | |
service_name: | |
- 'github-metrics-webhook-c764' | |
- 'github-metrics-retry-4d31' | |
steps: | |
- uses: 'actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b' # ratchet:actions/checkout@v4 | |
- uses: 'google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c' # 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@98ddc00a17442e89a24bbf282954a3b65ce6d200' # ratchet:google-github-actions/setup-gcloud@v2 | |
- name: 'Remove old Webhook Cloud Run revisions' | |
shell: 'bash' | |
run: |- | |
# List all revisions that were deployed 5 hours ago or later, excluding the latest revision | |
# There must be at least one revisions running at all times | |
REVISIONS=$(gcloud run revisions list \ | |
--project="$INTEGRATION_PROJECT_ID" \ | |
--region="$INTEGRATION_REGION" \ | |
--service="${{ matrix.service_name }}" \ | |
--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} --project="$INTEGRATION_PROJECT_ID" --region="$INTEGRATION_REGION" --quiet --async | |
done | |
# cleanup_container_images deletes all untagged container images that are more | |
# than 14 days old. | |
cleanup_container_images: | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: 'actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b' # ratchet:actions/checkout@v4 | |
- uses: 'google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c' # ratchet:google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: '${{ env.WIF_PROVIDER }}' | |
service_account: '${{ env.WIF_SERVICE_ACCOUNT }}' | |
- name: 'Remove old container images' | |
uses: 'docker://us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli' # ratchet:exclude old image versions are removed | |
with: | |
args: >- | |
-repo="${{ env.GAR_REPO }}" | |
-recursive="true" | |
-grace="336h" | |
-tag-filter-any="(?i)[0-9a-f]{40}(-amd64|-arm64)?" |