From 56e7b280d1630133801f45d1822a6d9d9a38a7c5 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Wed, 1 Nov 2023 21:10:25 +0000 Subject: [PATCH 1/2] Keep the last 90 nightly builds Keep nightly builds around for longer to account for the fact that a certain feature available in a nightly might not be available in a release build for over 10 days in some circumstances. --- .github/workflows/cleanup-old.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-old.yml b/.github/workflows/cleanup-old.yml index 34aa46e..c5253d5 100644 --- a/.github/workflows/cleanup-old.yml +++ b/.github/workflows/cleanup-old.yml @@ -12,11 +12,11 @@ jobs: name: Remove old nightly releases runs-on: ubuntu-latest steps: - - name: Remove all but last 10 releases + - name: Remove all but last 90 releases env: GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' shell: bash run: | - RELEASES=`gh release list --repo dsp-testing/codeql-cli-nightlies | grep "Pre-release" | sed '1,10d' | cut -f 3` + RELEASES=`gh api --paginate repos/dsp-testing/codeql-cli-nightlies/releases --jq 'map(select(.prerelease == true)).[90:].[] | .tag_name'` echo "$RELEASES" | awk NF | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh release delete --repo dsp-testing/codeql-cli-nightlies --yes echo "$RELEASES" | awk NF | sed 's/^/\/repos\/dsp-testing\/codeql-cli-nightlies\/git\/refs\/tags\//' | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh api -X DELETE --silent From f369c1b6c31fc98a5680007ba5ef1018383440ef Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 2 Nov 2023 17:04:21 +0000 Subject: [PATCH 2/2] Explain chronological order of API --- .github/workflows/cleanup-old.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cleanup-old.yml b/.github/workflows/cleanup-old.yml index c5253d5..1a63ef7 100644 --- a/.github/workflows/cleanup-old.yml +++ b/.github/workflows/cleanup-old.yml @@ -17,6 +17,8 @@ jobs: GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' shell: bash run: | - RELEASES=`gh api --paginate repos/dsp-testing/codeql-cli-nightlies/releases --jq 'map(select(.prerelease == true)).[90:].[] | .tag_name'` - echo "$RELEASES" | awk NF | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh release delete --repo dsp-testing/codeql-cli-nightlies --yes - echo "$RELEASES" | awk NF | sed 's/^/\/repos\/dsp-testing\/codeql-cli-nightlies\/git\/refs\/tags\//' | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh api -X DELETE --silent + # The GitHub API returns results in reverse chronological order, so `[90:]` captures the + # 91st and older releases which we want to delete. + RELEASES_TO_DELETE=`gh api --paginate repos/dsp-testing/codeql-cli-nightlies/releases --jq 'map(select(.prerelease == true)).[90:].[] | .tag_name'` + echo "$RELEASES_TO_DELETE" | awk NF | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh release delete --repo dsp-testing/codeql-cli-nightlies --yes + echo "$RELEASES_TO_DELETE" | awk NF | sed 's/^/\/repos\/dsp-testing\/codeql-cli-nightlies\/git\/refs\/tags\//' | tr '\n' '\0' | xargs --no-run-if-empty -0 -n1 gh api -X DELETE --silent