Skip to content

Commit 094f209

Browse files
author
Prakash
committed
The previous approach to delete temp tags was both cumbersome and error-prone. Moving to a more robust solution.
1 parent b55ba65 commit 094f209

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,11 @@ jobs:
130130
# Cleanup temporary Docker tags from GitHub Container Registry
131131
- name: Cleanup temporary Docker tags
132132
if: always() # This ensures the step runs even if previous steps fail
133-
run: |
134-
# Get the package name without the registry prefix
135-
PACKAGE_NAME=$(echo "${{ env.IMAGE_NAME }}" | sed 's/ghcr.io\///')
136-
137-
# The package name needs to be URL-encoded for the API
138-
# Replace "/" with "%2F"
139-
ENCODED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/\//%2F/g')
140-
141-
# First, we need to find the ID of the tag
142-
RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
143-
-H "Accept: application/vnd.github.v3+json" \
144-
"https://api.github.com/orgs/bahnew/packages/container/${ENCODED_PACKAGE_NAME}/versions")
145-
146-
# Extract the ID of the version with our temporary tag
147-
VERSION_ID=$(echo $RESPONSE | jq -r '.[] | select(.metadata.container.tags[] | contains("scan-${{ github.sha }}")) | .id')
148-
149-
if [ -n "$VERSION_ID" ]; then
150-
# Delete just this specific tag (not the entire version)
151-
curl -X DELETE \
152-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
153-
-H "Accept: application/vnd.github.v3+json" \
154-
"https://api.github.com/orgs/bahnew/packages/container/${ENCODED_PACKAGE_NAME}/versions/${VERSION_ID}"
155-
echo "Deleted temporary tag: scan-${{ github.sha }}"
156-
else
157-
echo "Could not find version ID for tag: scan-${{ github.sha }}"
158-
fi
133+
uses: actions/delete-package-versions@v5
134+
with:
135+
package-name: 'clinical-frontend'
136+
package-type: 'container'
137+
owner: 'bahnew'
138+
token: ${{ secrets.GITHUB_TOKEN }}
139+
min-versions-to-keep: 0
140+
ignore-versions: '^(?!scan-${{ github.sha }}$).*$'

0 commit comments

Comments
 (0)