[do not merge] Test using cache from a different git SHA from a sibling branch #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI cache cleanup | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| workflow_dispatch: | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| # `actions:write` permission is required to delete caches | |
| actions: write | |
| contents: read | |
| steps: | |
| - name: Cleanup cache | |
| run: | | |
| echo "Fetching list of cache keys for PR branch: $BRANCH" | |
| # Get cache keys and handle the case where no caches exist | |
| cacheKeysForPR=$(gh cache list --repo "$GITHUB_REPO" --ref "$BRANCH" --limit 100 --json key,id --jq '.[].id' 2>/dev/null || echo "") | |
| if [ -z "$cacheKeysForPR" ]; then | |
| echo "No caches found for branch $BRANCH" | |
| exit 0 | |
| fi | |
| echo "Found cache keys: $cacheKeysForPR" | |
| # Set to not fail the workflow while deleting cache keys | |
| set +e | |
| echo "Deleting caches..." | |
| deleted_count=0 | |
| failed_count=0 | |
| for cacheKey in $cacheKeysForPR | |
| do | |
| echo "Attempting to delete cache: $cacheKey" | |
| if gh cache delete "$cacheKey" --repo "$GITHUB_REPO" 2>/dev/null; then | |
| echo "✓ Successfully deleted cache: $cacheKey" | |
| ((deleted_count++)) | |
| else | |
| echo "✗ Failed to delete cache: $cacheKey (likely insufficient permissions)" | |
| ((failed_count++)) | |
| fi | |
| done | |
| echo "Cache cleanup completed:" | |
| echo " - Successfully deleted: $deleted_count caches" | |
| echo " - Failed to delete: $failed_count caches" | |
| # Don't fail the workflow even if some deletions failed | |
| exit 0 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REPO: ${{ github.repository }} | |
| # Only delete cache from PR branch | |
| BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge |