From 72db12304a62af9d07a87a5e5622b40887ef95f4 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 16 Jan 2026 02:16:54 -0500 Subject: [PATCH] ci: fix nightly prune not working (#1961) * ci: fix nightly prune not working This change makes it so we keep the last three nightly runs + prune anything that was created today. Tested by just running it manually. * driveby to only run the ghp deploy on main --- .github/workflows/nightly.yml | 24 ++++++++++++++++------ .github/workflows/publish_github_pages.yml | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c0d617aa..48eb6ee2 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -92,17 +92,29 @@ jobs: echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV echo "$RELEASE_NAME" - # Delete tags older than 3 days, as well as nightly runs that are a duplicate of today. + # Delete all but last three nightly runs, as well as nightly runs that are a duplicate of today. - name: Delete old tags and release if not mock if: github.event.inputs.isMock != 'true' run: | - THREE_DAYS_AGO=$(date +%s --date='3 days ago') + echo "Deleting any nightly runs with the same name as today's nightly run..." while true; do - PREV_NIGHTLY=$(gh release list --json name,tagName,publishedAt | jq --arg THREE_DAYS_AGO "$THREE_DAYS_AGO" --arg RELEASE_NAME "$RELEASE_NAME" -c '[.[] | select (.tagName | contains("nightly-")) | select ((.publishedAt | fromdateiso8601 > $THREE_DAYS_AGO) or (.name == $RELEASE_NAME))][0] | .tagName' | tr -d '"') + TO_DELETE_NIGHTLY=$(gh release list --json name,tagName,publishedAt | jq --arg RELEASE_NAME "$RELEASE_NAME" -c '[.[] | select (.tagName | contains("nightly-")) | select (.name == $RELEASE_NAME)][0] | .tagName' | tr -d '"') + if [[ "$TO_DELETE_NIGHTLY" != "null" && "$TO_DELETE_NIGHTLY" == *"nightly-"* ]]; then + echo "Will delete nightly release with tag '$TO_DELETE_NIGHTLY'"; + gh release delete $TO_DELETE_NIGHTLY --cleanup-tag || { echo "couldn't delete previous nightly release, halting"; break; } + else + echo "no nightly releases left, done"; + break; + fi + done - if [[ "$PREV_NIGHTLY" != "null" && "$PREV_NIGHTLY" == *"nightly-"* ]]; then - echo "Will delete nightly release with tag '$PREV_NIGHTLY'"; - gh release delete $PREV_NIGHTLY --cleanup-tag || { echo "couldn't delete previous nightly release, halting"; break; } + echo "Now pruning all but the last three nightly runs..." + while true; do + # Very gross trick - keep deleting the 4th nightly element ([3]) until null. + TO_DELETE_NIGHTLY=$(gh release list --json name,tagName,publishedAt | jq --arg RELEASE_NAME "$RELEASE_NAME" -c '[.[] | select (.tagName | contains("nightly-"))][4] | .tagName' | tr -d '"') + if [[ "$TO_DELETE_NIGHTLY" != "null" && "$TO_DELETE_NIGHTLY" == *"nightly-"* ]]; then + echo "Will delete nightly release with tag '$TO_DELETE_NIGHTLY'"; + gh release delete $TO_DELETE_NIGHTLY --cleanup-tag || { echo "couldn't delete previous nightly release, halting"; break; } else echo "no nightly releases left, done"; break; diff --git a/.github/workflows/publish_github_pages.yml b/.github/workflows/publish_github_pages.yml index d4e8d369..2136e5f4 100644 --- a/.github/workflows/publish_github_pages.yml +++ b/.github/workflows/publish_github_pages.yml @@ -30,6 +30,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: build + if: github.ref == 'refs/heads/main' environment: name: github-pages url: ${{ steps.deploy.outputs.page_url }}