Skip to content

chore(deps): update docker/metadata-action action to v5.10.0 - autoclosed #10

chore(deps): update docker/metadata-action action to v5.10.0 - autoclosed

chore(deps): update docker/metadata-action action to v5.10.0 - autoclosed #10

name: Cleanup PR Images
on:
pull_request:
types: [closed]
jobs:
cleanup:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read
packages: write
steps:
- name: Cleanup PR images
env:
GH_TOKEN: ${{ secrets.GHCR_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
PACKAGE_NAME="custom-studios-examples/development"
echo "Cleaning up images for PR #${PR_NUMBER}..."
# Get all versions of the package
VERSIONS=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/seqeralabs/packages/container/${PACKAGE_NAME}/versions" \
--paginate 2>/dev/null || echo "[]")
# Find all versions with tags ending in -pr<PR_NUMBER>
echo "$VERSIONS" | jq -r --arg pr "pr${PR_NUMBER}" '
.[] |
select(.metadata.container.tags[] | endswith("-" + $pr)) |
.id
' | while read -r VERSION_ID; do
if [[ -n "$VERSION_ID" ]]; then
TAGS=$(echo "$VERSIONS" | jq -r --arg id "$VERSION_ID" '.[] | select(.id == ($id | tonumber)) | .metadata.container.tags | join(", ")')
echo "Deleting version $VERSION_ID (tags: $TAGS)..."
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/orgs/seqeralabs/packages/container/${PACKAGE_NAME}/versions/${VERSION_ID}" \
&& echo "Successfully deleted" \
|| echo "Failed to delete"
fi
done
echo "Cleanup complete for PR #${PR_NUMBER}"