Delete old releases #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Delete old releases | |
on: | |
schedule: | |
- cron: '15 23 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Related: https://github.com/actions/checkout/issues/1471 | |
- name: Fetch tags | |
run: git fetch --prune --unshallow --tags | |
- name: Delete old releases if required | |
run: | | |
# Keep last 50 releases | |
tags_to_delete=($(git tag --sort=-v:refname | grep nightly- | tail -n+50)) | |
if (( ${#tags_to_delete[@]} )); then | |
echo "Will delete ${tags_to_delete[*]}" | |
for tag_to_delete in "${tags_to_delete[@]}" | |
do | |
echo "Deleting $tag_to_delete" | |
git push -v --delete origin "$tag_to_delete" | |
# Delete GitHub release if present | |
gh release delete -y "$tag_to_delete" || true | |
done | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} |