mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
45 lines
1.5 KiB
YAML
45 lines
1.5 KiB
YAML
name: GAR Cleanup
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '30 6 * * *'
|
|
workflow_dispatch: {}
|
|
workflow_run:
|
|
workflows: ['Deploy']
|
|
types:
|
|
- completed
|
|
|
|
jobs:
|
|
docker_cleanup:
|
|
name: Cleanup Deployed Images
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
region: [us, europe, asia]
|
|
fail-fast: false
|
|
steps:
|
|
- name: Set up Cloud SDK
|
|
uses: google-github-actions/setup-gcloud@master
|
|
with:
|
|
project_id: ${{ secrets.GCS_PROJECT_ID }}
|
|
service_account_key: ${{ secrets.GCS_TF_KEY }}
|
|
export_default_credentials: true
|
|
|
|
- name: Delete stale artifacts
|
|
run: |
|
|
flags="--format=json --location=${{matrix.region}} --repository=roleypoly"
|
|
|
|
packagesToPrune=$(gcloud artifacts packages list $flags | jq -r '.[].name')
|
|
|
|
for package in $packagesToPrune; do
|
|
tagsToKeep=$(gcloud artifacts tags list --package=$package $flags | jq -r '.[].version')
|
|
versionsToCheck=$(gcloud artifacts versions list --package=$package $flags | jq -r '.[].name')
|
|
|
|
for version in $versionsToCheck; do
|
|
if [[ "$tagsToKeep" =~ .*"$version".* ]]; then
|
|
continue
|
|
fi
|
|
|
|
gcloud artifacts versions delete $version --package=$package $flags --quiet
|
|
done
|
|
done
|