From a749b00d9f86e1d7b57ae1538d2d3cbdca36f4ba Mon Sep 17 00:00:00 2001 From: Kamil Kasperski Date: Thu, 14 Nov 2024 13:49:02 +0100 Subject: [PATCH] feat: Add job that removes old workflow runs /kind feat /area ci Add script and schedule workflow that removes workflow runs older than specific threshold. Workflow runs every night at 0:11 UTC and removes up to 500 runs at a time. feat: Add job that removes old workflow runs /kind feat /area ci Add script and schedule workflow that removes workflow runs older than specific threshold. Workflow runs every night at 0:11 UTC and removes up to 500 runs at a time. --- .github/workflows/ci-cleanup-workflows.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/ci-cleanup-workflows.yaml diff --git a/.github/workflows/ci-cleanup-workflows.yaml b/.github/workflows/ci-cleanup-workflows.yaml new file mode 100644 index 000000000..17779a131 --- /dev/null +++ b/.github/workflows/ci-cleanup-workflows.yaml @@ -0,0 +1,21 @@ +on: + schedule: + - cron: "11 0 * * *" + +permissions: + actions: write + +jobs: + cleanup-workflows: + runs-on: ubuntu-latest + steps: + - id: cleanup + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DAYS_AFTER: 60 days + LIMIT: 500 + run: | + DATE="$(date -d "-$DAYS_AFTER" +%F)" + echo "Removing workflow runs older than $DATE..." + gh run list --json databaseId -q '.[].databaseId' --created "<=$DATE" --limit "$LIMIT" | + xargs -IID -P 15 gh run delete ID \ No newline at end of file