Skip to content

Commit

Permalink
Add retry to GHCR clean-up job
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Nov 20, 2023
1 parent aa5f4d7 commit 4234b88
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 20 deletions.
52 changes: 52 additions & 0 deletions .github/actions/cleanup-stale/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Delete stale images

description: Delete stale images

inputs:
delay:
description: Delay before running the action (in seconds)
required: false
default: "0" # seconds
token:
description: A Github PAT token to fetch repository and delete packages (needs delete:packages permissions).
required: true

runs:
using: composite
steps:
- name: Delay # needed in case of retry to avoid triggering the rate limit of the Github API
if: ${{ inputs.delay != '0' }}
shell: bash
run: |
sleep ${{ inputs.delay }}
- name: Delete older than a month vnext and vnext-pr images
uses: snok/container-retention-policy@v2
with:
image-names: iotivity-lite/*
cut-off: One month ago UTC
account-type: org
org-name: iotivity
filter-tags: vnext-*
skip-tags: master
token: ${{ inputs.token }}

- 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: ${{ inputs.token }}

- name: Delete untagged images with no dependency
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
with:
repository: ${{ github.repository }}
repository_owner: ${{ github.repository_owner }}
token: ${{ inputs.token }}
owner_type: org
untagged_only: true
except_untagged_multiplatform: true
41 changes: 21 additions & 20 deletions .github/workflows/ghcr-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,28 @@ jobs:
token: ${{ secrets.GHCR_CLEANUP_PAT }}
nightly-ghcr-cleanup:
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
name: Delete old images
name: Delete stale or untagged images
runs-on: ubuntu-latest
steps:
- name: Delete older than a month vnext images
uses: snok/container-retention-policy@v2
- name: Checkout local actions
uses: actions/checkout@v4
- name: Delete stale or untagged images (1)
id: run-1
continue-on-error: true
uses: ./.github/actions/cleanup-stale
with:
token: ${{ secrets.GHCR_CLEANUP_PAT }}
- name: Delete stale or untagged images (2)
id: run-2
if: ${{ steps.run-1.outcome == 'failure' }}
with:
token: ${{ secrets.GHCR_CLEANUP_PAT }}
delay: 60
continue-on-error: true
uses: ./.github/actions/cleanup-stale
- name: Delete stale or untagged images (3)
if: ${{ steps.run-2.outcome == 'failure' }}
uses: ./.github/actions/cleanup-stale
with:
image-names: cloud-server*, iotivity-lite*
cut-off: One month ago UTC
account-type: org
org-name: iotivity
filter-tags: vnext-*
skip-tags: vnext-pr*, master
token: ${{ secrets.GHCR_CLEANUP_PAT }}
# Cannot enable clean-up of untagged images until issue#63 is fixed
# https://github.com/snok/container-retention-policy/issues/63
# - name: Delete untagged images older than a month
# uses: snok/container-retention-policy@v2
# with:
# image-names: cloud-server*, iotivity-lite*
# cut-off: One month ago UTC
# account-type: org
# org-name: iotivity
# untagged-only: true
# token: ${{ secrets.GHCR_CLEANUP_PAT }}
delay: 60

0 comments on commit 4234b88

Please sign in to comment.