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
This commit is contained in:
Clement Tsang
2026-01-16 02:16:54 -05:00
committed by GitHub
parent 78ae9169e6
commit 72db12304a
2 changed files with 19 additions and 6 deletions
+18 -6
View File
@@ -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;
@@ -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 }}