From 7520b54ae97dabce4ca88fe95e088c78558632b4 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:55:07 +0100 Subject: [PATCH] Create workflow to delete old releases --- .github/workflows/delete-old-releases.yml | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/delete-old-releases.yml diff --git a/.github/workflows/delete-old-releases.yml b/.github/workflows/delete-old-releases.yml new file mode 100644 index 000000000..c2ccd3a55 --- /dev/null +++ b/.github/workflows/delete-old-releases.yml @@ -0,0 +1,37 @@ +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 }}