From 5a05bcabaec3d7f8220d00c33349efdb4c30de04 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Fri, 6 Sep 2024 14:32:51 -0400 Subject: [PATCH] add cache cleanup steps Signed-off-by: Alex Goodman --- .github/actions/bootstrap/action.yaml | 2 +- .../workflows/test-fixture-cache-publish.yaml | 2 -- .github/workflows/validations.yaml | 25 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/actions/bootstrap/action.yaml b/.github/actions/bootstrap/action.yaml index 5b712c5e656..6150113aee0 100644 --- a/.github/actions/bootstrap/action.yaml +++ b/.github/actions/bootstrap/action.yaml @@ -58,7 +58,7 @@ runs: uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: ${{ github.workspace }}/.tmp/oras-cache - key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-oras-cache + key: ${{ inputs.cache-key-prefix }}-oras-cache - name: Download test fixture cache if: inputs.download-test-fixture-cache == 'true' diff --git a/.github/workflows/test-fixture-cache-publish.yaml b/.github/workflows/test-fixture-cache-publish.yaml index 14eee754486..3144a0b6bc5 100644 --- a/.github/workflows/test-fixture-cache-publish.yaml +++ b/.github/workflows/test-fixture-cache-publish.yaml @@ -2,8 +2,6 @@ name: "Test fixture cache: publish" on: workflow_dispatch: - # TODO: remove me, just here for testing - push: schedule: # run nightly at 4AM UTC - cron: "0 4 * * *" diff --git a/.github/workflows/validations.yaml b/.github/workflows/validations.yaml index 67fc5cd1878..709e1bfe972 100644 --- a/.github/workflows/validations.yaml +++ b/.github/workflows/validations.yaml @@ -202,3 +202,28 @@ jobs: - name: Run CLI Tests (Linux) run: make cli + + + Cleanup-Cache: + name: "Cleanup snapshot cache" + if: always() + runs-on: ubuntu-20.04 + needs: + - Acceptance-Linux + - Acceptance-Mac + - Cli-Linux + steps: + - name: Delete snapshot cache + run: | + # Define the cache key to delete + CACHE_KEY="snapshot-build-${{ github.run_id }}" + + # Fetch cache list and delete the cache by key using gh api + CACHE_ID=$(gh api repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/caches --jq ".actions_caches[] | select(.key == \"$CACHE_KEY\") | .id") + + if [ -n "$CACHE_ID" ]; then + echo "Deleting cache with key $CACHE_KEY (ID: $CACHE_ID)" + gh api --method DELETE repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/caches/$CACHE_ID + else + echo "Cache with key $CACHE_KEY not found." + fi