Skip to content

Commit 6afec81

Browse files
Enhance release cleanup process to exclude current release and sort old releases by creation date
1 parent 2df3006 commit 6afec81

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

.github/workflows/build.yaml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,38 @@ jobs:
190190
env:
191191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
192192
run: |
193-
# Keep no releases (excluding current new release)
194-
releases=$(gh release list --limit 100 --exclude-drafts --exclude-pre-releases --json tagName,createdAt -q '.[].tagName')
193+
# Get current release tag we're creating
194+
current_tag="v${{ env.VERSION }}"
195+
echo "Current release tag: $current_tag"
196+
197+
# List all releases excluding the current one we're creating
198+
# Sort by creation date (oldest first)
199+
echo "Listing existing releases..."
200+
readarray -t old_releases < <(gh release list --limit 100 --exclude-drafts --exclude-pre-releases --json tagName,createdAt --jq 'sort_by(.createdAt) | .[].tagName')
201+
202+
# Keep no old releases
195203
keep=0
196204
count=0
205+
total=${#old_releases[@]}
197206
198-
echo "Current releases (oldest first):"
199-
echo "$releases"
207+
echo "Found $total existing releases"
200208
201-
for release in $releases; do
209+
# Delete all releases except the most recent 'keep' number
210+
for tag in "${old_releases[@]}"; do
211+
# Skip the current release if it somehow appears in the list
212+
if [[ "$tag" == "$current_tag" ]]; then
213+
echo "Skipping current release: $tag"
214+
continue
215+
fi
216+
202217
((count++))
203218
if ((count > keep)); then
204-
echo "Deleting old release: $release"
205-
gh release delete "$release" --yes
219+
echo "Deleting old release: $tag"
220+
gh release delete "$tag" --yes || echo "Failed to delete release $tag"
221+
else
222+
echo "Keeping release: $tag"
206223
fi
207224
done
225+
226+
echo "Release cleanup complete"
208227

0 commit comments

Comments
 (0)