patch attempt for GH cleanup tag

This commit is contained in:
Timothy Carambat
2026-03-05 08:31:40 -08:00
parent bac9b8be4c
commit f5cf7a155d

View File

@@ -10,17 +10,27 @@ jobs:
name: Delete QA GHCR image tag
runs-on: ubuntu-latest
if: >-
${{ (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'PR: Ready for QA')) ||
(github.event.action == 'unlabeled' && github.event.label.name == 'PR: Ready for QA') }}
(github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'PR: Ready for QA')) ||
(github.event.action == 'unlabeled' && github.event.label.name == 'PR: Ready for QA')
permissions:
packages: write
steps:
- name: Delete PR tag from GHCR
uses: actions/delete-package-versions@v5
continue-on-error: true # Package may not exist if build never ran
with:
owner: ${{ github.repository_owner }}
package-name: ${{ github.event.repository.name }}
package-type: container
min-versions-to-keep: 0
ignore-versions: '^(?!pr-${{ github.event.pull_request.number }}$).*$'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION_ID=$(gh api \
-H "Accept: application/vnd.github+json" \
"/orgs/${{ github.repository_owner }}/packages/container/${{ github.event.repository.name }}/versions" \
--jq '.[] | select(.metadata.container.tags[] == "pr-${{ github.event.pull_request.number }}") | .id' \
2>/dev/null || true)
if [ -n "$VERSION_ID" ]; then
echo "Deleting package version $VERSION_ID (tag: pr-${{ github.event.pull_request.number }})"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
"/orgs/${{ github.repository_owner }}/packages/container/${{ github.event.repository.name }}/versions/$VERSION_ID"
else
echo "No package found with tag pr-${{ github.event.pull_request.number }}, skipping cleanup"
fi