@@ -251,30 +251,33 @@ jobs:
251251 (cd manifests && zip -r ../uid2-operator-release-manifests-${{ needs.start.outputs.new_version }}.zip .)
252252
253253
254- - name : Cleanup old assets from existing release
255- # Clean up all assets from existing release to ensure only current assets are included
254+ - name : Cleanup assets from all previous releases
255+ # Clean up assets from all releases to prevent accumulation
256256 env :
257257 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
258258 REPO : ${{ github.repository }}
259- TAG : v${{ needs.start.outputs.new_version }}
259+ CURRENT_TAG : v${{ needs.start.outputs.new_version }}
260260 shell : bash
261261 run : |
262262 set -euo pipefail
263- # Check if release exists
264- if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
265- echo "Found existing release $TAG, cleaning up all assets..."
266- # Get all asset IDs and delete them
267- gh api "repos/$REPO/releases/tags/$TAG" --jq '.assets[].id' | \
268- while read -r asset_id; do
269- asset_name=$(gh api "repos/$REPO/releases/assets/$asset_id" --jq -r '.name')
270- echo "Deleting asset: $asset_name (ID: $asset_id)"
271- gh api "repos/$REPO/releases/assets/$asset_id" -X DELETE
272- done
273- echo "All assets cleaned up for release $TAG"
274- else
275- echo "No existing release $TAG found - will create new release"
276- fi
277-
263+ echo "Current release will be: $CURRENT_TAG"
264+
265+ # Get all releases and clean up their assets
266+ gh api "repos/$REPO/releases" --jq '.[].tag_name' | \
267+ while read -r tag; do
268+ if [ "$tag" != "$CURRENT_TAG" ]; then
269+ echo "Cleaning up assets from release: $tag"
270+ # Get all asset IDs for this release and delete them
271+ gh api "repos/$REPO/releases/tags/$tag" --jq '.assets[].id' | \
272+ while read -r asset_id; do
273+ asset_name=$(gh api "repos/$REPO/releases/assets/$asset_id" --jq -r '.name')
274+ echo " Deleting asset: $asset_name from $tag"
275+ gh api "repos/$REPO/releases/assets/$asset_id" -X DELETE
276+ done
277+ fi
278+ done
279+
280+ echo "Cleanup complete - only $CURRENT_TAG will have assets"
278281 - name : Create draft release
279282 uses : softprops/action-gh-release@v2
280283 with :
0 commit comments