@@ -113,8 +113,7 @@ jobs:
113113 # Tag the scanned image with final tags
114114 docker buildx imagetools create \
115115 --tag ${{ env.IMAGE_NAME }}:latest \
116- --tag ${{ env.IMAGE_NAME }}:${{ github.sha }} \
117- --tag ${{ env.IMAGE_NAME }}:v${{ steps.package-version.outputs.version }} \
116+ --tag ${{ env.IMAGE_NAME }}:v${{ steps.package-version.outputs.version }}-${{github.run_number}} \
118117 ${{ env.IMAGE_NAME }}:scan-${{ github.sha }}
119118
120119 # This step dispatches an event to the utils repo to trigger downstream deployments
@@ -128,3 +127,17 @@ jobs:
128127 https://api.github.com/repos/bahnew/utils/dispatches \
129128 -d '{"event_type":"clinical-frontend-publish","client_payload":{"version":"v${{ steps.package-version.outputs.version }}","sha":"${{ github.sha }}"}}'
130129
130+ # Cleanup Docker images from GitHub Container Registry
131+ - name : Cleanup temporary Docker images
132+ if : always() # This ensures the step runs even if previous steps fail
133+ run : |
134+ # Delete the temporary scan tag from GitHub Container Registry
135+ # Extract the package name from the image name (remove the registry prefix)
136+ PACKAGE_NAME=$(echo "${{ env.IMAGE_NAME }}" | sed 's/ghcr.io\///')
137+
138+ # Delete the temporary tag using GitHub API
139+ curl -X DELETE \
140+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
141+ -H "Accept: application/vnd.github.v3+json" \
142+ "https://api.github.com/user/packages/container/${PACKAGE_NAME}/versions/scan-${{ github.sha }}"
143+
0 commit comments