diff --git a/.forgejo/workflows/cleanup.yml b/.forgejo/workflows/cleanup.yml index 6dc6e05..a911a55 100644 --- a/.forgejo/workflows/cleanup.yml +++ b/.forgejo/workflows/cleanup.yml @@ -1,15 +1,15 @@ -name: Ryd op i Forgejo Container Registry +name: Clean up Forgejo Container Registry on: schedule: - - cron: '0 0 * * 0' # Kører hver søndag ved midnat - workflow_dispatch: # Gør det muligt at køre den manuelt + - cron: '0 0 * * 0' # Runs every Sunday at midnight + workflow_dispatch: # Allows manual triggering jobs: delete-old-images: runs-on: almalinux-10 steps: - - name: Slet gamle versioner + - name: Delete old versions run: | REGISTRY="forge.pc-rytteren.dk" OWNER="${{ github.repository_owner }}" @@ -17,27 +17,27 @@ jobs: MIN_KEEP=50 TOKEN="${{ secrets.PACKAGE_TOKEN }}" - # Hent alle pakker af typen container med dette navn, sorteret ældste først (via id) - # API returnerer en liste af package-objekter, hvert med "id" og "version" + # Fetch all container packages with this name, sorted oldest first (by id) + # API returns a list of package objects, each with "id" and "version" RAW=$(curl -s -H "Authorization: token ${TOKEN}" \ "https://${REGISTRY}/api/v1/packages/${OWNER}?type=container&q=${IMAGE}&limit=200") - # Filtrer kun pakker med korrekt navn og udtræk id + created_at, sorter ældste først + # Filter only packages with the correct name and extract id, sort oldest first IDS=$(echo "$RAW" | tr '{' '\n' | grep "\"name\":\"${IMAGE}\"" | \ sed 's/.*"id":\([0-9]*\).*/\1/' | sort -n) TOTAL=$(echo "$IDS" | grep -c '[0-9]' || true) - echo "Fundet ${TOTAL} pakker totalt, beholder ${MIN_KEEP}" + echo "Found ${TOTAL} packages total, keeping ${MIN_KEEP}" if [ "$TOTAL" -le "$MIN_KEEP" ]; then - echo "Ingen pakker at slette" + echo "No packages to delete" exit 0 fi - # Slet de ældste (laveste id'er) ud over MIN_KEEP + # Delete the oldest (lowest ids) beyond MIN_KEEP TO_DELETE=$(echo "$IDS" | head -n $(( TOTAL - MIN_KEEP ))) for ID in $TO_DELETE; do - echo "Sletter pakke id: ${ID}" + echo "Deleting package id: ${ID}" curl -s -X DELETE -H "Authorization: token ${TOKEN}" \ "https://${REGISTRY}/api/v1/packages/${OWNER}/${ID}" done \ No newline at end of file