From 3b11a834a7f3d9bdb4e2cd77b69ac54fa892fdbe Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Thu, 2 Nov 2023 11:43:22 +0100 Subject: [PATCH] Add Ghcr clean-up workflow --- .github/workflows/ghcr-cleanup.yaml | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/ghcr-cleanup.yaml diff --git a/.github/workflows/ghcr-cleanup.yaml b/.github/workflows/ghcr-cleanup.yaml new file mode 100644 index 00000000..16354a01 --- /dev/null +++ b/.github/workflows/ghcr-cleanup.yaml @@ -0,0 +1,44 @@ +name: Delete old ghcr images +on: + schedule: + - cron: "15 1 * * *" # every day at 1:15am + pull_request: + types: [closed] + workflow_dispatch: + +jobs: + ghcr-cleanup: + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + name: Delete old vnext images + runs-on: ubuntu-latest + steps: + - name: Delete older than a month vnext images + uses: snok/container-retention-policy@v2 + with: + image-names: device/* + cut-off: One month ago UTC + account-type: org + org-name: plgd-dev + filter-tags: vnext-* + skip-tags: main,latest + token: ${{ secrets.GHCR_CLEANUP_PAT }} + + - name: Set up Docker Buildx for delete untagged images action + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry for delete untagged images action + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_CLEANUP_PAT }} + + - name: Delete untagged images with no dependency + uses: Chizkiyahu/delete-untagged-ghcr-action@v3 + with: + repository: ${{ github.repository }} + repository_owner: ${{ github.repository_owner }} + token: ${{ secrets.GHCR_CLEANUP_PAT }} + owner_type: org + untagged_only: true + except_untagged_multiplatform: true