Skip to content

Commit

Permalink
use tag name instead of date to delete releases
Browse files Browse the repository at this point in the history
  • Loading branch information
devl00p committed Sep 17, 2024
1 parent 35401c5 commit 82d1117
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,25 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
current_date=$(date +%s)
gh release list --limit 100 --json id,createdAt --jq '.[] | [.id, .createdAt] | @tsv' | \
while IFS=$'\t' read -r release_id release_date; do
release_date_seconds=$(date -d "$release_date" +%s)
release_age_days=$(( (current_date - release_date_seconds) / 86400 ))
if [ $release_age_days -gt 30 ]; then
echo "Deleting release $release_id (age: $release_age_days days)"
gh release delete "$release_id" --yes
gh release list --limit 100 --json tagName --jq '.[] | [.tagName] | @tsv' | while read -r tagName; do
# Extract the date from the tagName
release_date=$(echo $tagName | grep -oP '\d{8}')
# Convert the extracted date into seconds
release_date_seconds=$(date -d "$release_date" +%s 2>/dev/null)
# If the date conversion was successful
if [ $? -eq 0 ]; then
release_age_days=$(( (current_date - release_date_seconds) / 86400 ))
if [ $release_age_days -gt 30 ]; then
echo "Deleting release $tagName (age: $release_age_days days)"
gh release delete "$tagName" --yes
# Delete the associated tag
echo "Deleting tag $tagName"
git push origin --delete $tagName || echo "Failed to delete tag $tagName"
fi
else
echo "Failed to extract or parse the date for release $tagName"
fi
done

0 comments on commit 82d1117

Please sign in to comment.