From 31e1d903e41b1b0943b0b809009b917353b6d985 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 20 Jun 2023 15:06:02 -0700 Subject: [PATCH 1/3] CI: Clean GH Action caches older than 1 week --- .github/workflows/cache-cleanup-weekly.yml | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/cache-cleanup-weekly.yml diff --git a/.github/workflows/cache-cleanup-weekly.yml b/.github/workflows/cache-cleanup-weekly.yml new file mode 100644 index 0000000000000..77fa6ade5e30f --- /dev/null +++ b/.github/workflows/cache-cleanup-weekly.yml @@ -0,0 +1,35 @@ +name: Clean caches older than 1 week +on: + schedule: + # 4:10 UTC every day + - cron: "10 4 * * *" + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Clean Cache + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + + echo "Fetching list of cache key" + oldCaches=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/pandas-dev/pandas/actions/caches --jq '.actions_caches' --paginate) + weekAgo=$(date --date="7 day ago" +%s) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting old caches..." + for cacheData in $oldCaches + do + createdAt=$(date -d $(jq '.created_at' $cacheData) +%s) + if [[ createdAt < weekAgo ]] ; + then + cacheKey=$(jq '.key' $cacheData) + gh actions-cache delete $cacheKey -R $REPO --confirm + fi + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c446a92259ba2131e222cd903c7f23d2c4e74d10 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Jun 2023 10:28:24 -0700 Subject: [PATCH 2/3] purge weekly instead --- .github/workflows/cache-cleanup-weekly.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cache-cleanup-weekly.yml b/.github/workflows/cache-cleanup-weekly.yml index 77fa6ade5e30f..52ec776c45abe 100644 --- a/.github/workflows/cache-cleanup-weekly.yml +++ b/.github/workflows/cache-cleanup-weekly.yml @@ -1,8 +1,8 @@ -name: Clean caches older than 1 week +name: Purge caches once a week on: schedule: - # 4:10 UTC every day - - cron: "10 4 * * *" + # 4:10 UTC on Sunday + - cron: "10 4 * * 0" jobs: cleanup: @@ -15,20 +15,14 @@ jobs: REPO=${{ github.repository }} echo "Fetching list of cache key" - oldCaches=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/pandas-dev/pandas/actions/caches --jq '.actions_caches' --paginate) - weekAgo=$(date --date="7 day ago" +%s) + allCaches=$(gh actions-cache list -R $REPO | cut -f 1 ) ## Setting this to not fail the workflow while deleting cache keys. set +e - echo "Deleting old caches..." - for cacheData in $oldCaches + echo "Deleting caches..." + for cacheKey in $allCaches do - createdAt=$(date -d $(jq '.created_at' $cacheData) +%s) - if [[ createdAt < weekAgo ]] ; - then - cacheKey=$(jq '.key' $cacheData) - gh actions-cache delete $cacheKey -R $REPO --confirm - fi + gh actions-cache delete $cacheKey -R $REPO --confirm done echo "Done" env: From 84fd6deb923265db75a74fe0d9568a346a7659f0 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 29 Jun 2023 09:21:19 -0700 Subject: [PATCH 3/3] ensure we list a lot of caches --- .github/workflows/cache-cleanup-weekly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cache-cleanup-weekly.yml b/.github/workflows/cache-cleanup-weekly.yml index 52ec776c45abe..225503f2894f8 100644 --- a/.github/workflows/cache-cleanup-weekly.yml +++ b/.github/workflows/cache-cleanup-weekly.yml @@ -15,7 +15,7 @@ jobs: REPO=${{ github.repository }} echo "Fetching list of cache key" - allCaches=$(gh actions-cache list -R $REPO | cut -f 1 ) + allCaches=$(gh actions-cache list -L 100 -R $REPO | cut -f 1 ) ## Setting this to not fail the workflow while deleting cache keys. set +e