File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 1+ name : Delete All GHCR PR Tags
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ workflow_dispatch :
8+
9+ jobs :
10+ delete-pr-tags :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Delete all GHCR image tags starting with "pr-"
15+ env :
16+ GHCR_TOKEN : ${{ secrets.GHCR_TOKEN }}
17+ REPO : ${{ github.event.repository.name }}
18+ OWNER : ${{ github.repository_owner }}
19+ run : |
20+ echo "Fetching GHCR container versions for ghcr.io/${OWNER}/${REPO}..."
21+
22+ response=$(curl -s -H "Authorization: Bearer ${GHCR_TOKEN}" \
23+ "https://api.github.com/orgs/${OWNER}/packages/container/${REPO}/versions")
24+
25+ # Check that the response is a JSON array
26+ if ! echo "$response" | jq -e 'type == "array"' > /dev/null; then
27+ echo "❌ Unexpected response from GitHub API:"
28+ echo "$response"
29+ exit 1
30+ fi
31+
32+ echo "$response" | jq -c '.[]' | while read -r version; do
33+ version_id=$(echo "$version" | jq -r '.id')
34+ tag_names=$(echo "$version" | jq -r '.metadata.container.tags[]?')
35+
36+ for tag in $tag_names; do
37+ if [[ "$tag" == pr-* ]]; then
38+ echo "🗑️ Deleting tag: $tag (version ID: $version_id)"
39+ curl -s -X DELETE -H "Authorization: Bearer ${GHCR_TOKEN}" \
40+ "https://api.github.com/orgs/${OWNER}/packages/container/${REPO}/versions/${version_id}"
41+ break # One deletion per version is sufficient
42+ fi
43+ done
44+ done
Original file line number Diff line number Diff line change 3737
3838 if [[ "${{ github.event_name }}" == "release" ]]; then
3939 VERSION_TAG=${{ github.event.release.tag_name }}
40- echo "tags=${REPO}:${VERSION_TAG},${REPO}:latest" >> $GITHUB_OUTPUT
40+ echo "tags<<EOF" >> $GITHUB_OUTPUT
41+ echo "${REPO}:${VERSION_TAG}" >> $GITHUB_OUTPUT
42+ echo "${REPO}:latest" >> $GITHUB_OUTPUT
43+ echo "EOF" >> $GITHUB_OUTPUT
4144
4245 elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
4346 PR_NUMBER=${{ github.event.pull_request.number }}
5457 platforms : linux/amd64,linux/arm64
5558 push : true
5659 tags : ${{ steps.meta.outputs.tags }}
60+ provenance : false
5761 cache-from : type=gha
5862 cache-to : type=gha,mode=max
You can’t perform that action at this time.
0 commit comments