Skip to content

Conversation

@Rohit3523
Copy link
Collaborator

@Rohit3523 Rohit3523 commented Nov 8, 2025

Proposed changes

Right now we depend upon github to delete the overused cache files after 24 hours which may delete some cache use by other PR. As mentioned in https://docs.github.com/en/actions/how-tos/manage-workflow-runs/manage-caches#force-deleting-cache-entries i have added a workflow to delete the cache related to pull request after the PR get closed

Issue(s)

How to test or reproduce

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Chores
    • Updated internal build pipeline to optimize cache management.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

A new GitHub Actions workflow is introduced that automatically runs when pull requests are closed. The workflow fetches PR-related cache keys and deletes them to maintain cache hygiene.

Changes

Cohort / File(s) Summary
GitHub Actions workflow
.github/workflows/pr-close.yml
New workflow for cleanup job triggered on PR close; fetches and deletes PR-associated cache entries using GitHub CLI.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub as GitHub Platform
    participant Workflow as PR Close Workflow
    participant GH as GitHub CLI (gh)
    participant Cache as GitHub Cache
    
    GitHub->>Workflow: Pull request closed
    Workflow->>GH: gh cache list (filter by branch)
    GH->>Cache: Query cache keys
    Cache-->>GH: Return matching cache keys
    GH-->>Workflow: Cache key list
    Workflow->>Workflow: Iterate over each cache key
    loop For each cache key
        Workflow->>GH: gh cache delete <key>
        GH->>Cache: Delete cache entry
        Cache-->>GH: Deletion confirmed
    end
    GH-->>Workflow: All caches deleted
    Workflow->>GitHub: Workflow complete
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify GitHub CLI commands (gh cache list, gh cache delete) are syntactically correct
  • Confirm proper environment variable setup (GH_TOKEN, GH_REPO, BRANCH) for authentication
  • Review permissions scope (actions: write) aligns with workflow requirements
  • Check workflow trigger conditions and branch filtering logic

Suggested reviewers

  • diegolmello

Poem

🐰 A cache runs deep when PR's complete,
Our cleanup workflow can't be beat,
With gh commands, so swift and clean,
No stale artifacts will be seen! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: clear action cache after PR merge' accurately describes the main change: a new GitHub Actions workflow that clears PR-related caches when pull requests are closed, addressing cache management between PRs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch action-cache-clean

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3532447 and ac465ce.

📒 Files selected for processing (1)
  • .github/workflows/pr-close.yml (1 hunks)
🔇 Additional comments (2)
.github/workflows/pr-close.yml (2)

1-28: Approve workflow design; verify environment variable correctness.

The workflow logic is sound: it triggers on PR closure and cleans up associated caches. The use of set +e to allow continued deletion attempts despite individual failures is appropriate for cleanup operations. However, verify that the BRANCH ref refs/pull/${{ github.event.pull_request.number }}/merge correctly scopes caches to the PR context.

Please confirm:

  1. The BRANCH ref correctly maps all PR-related caches (e.g., verify against GitHub's cache scoping rules).
  2. The --jq '.[].id' syntax is supported in your gh CLI version.

You may reference the GitHub Actions cache documentation to verify cache scoping and the gh CLI version you're using in ubuntu-latest.


16-16: Syntax is correct, but verify --limit 100 is adequate for PR cache cleanup.

The command syntax is valid—gh cache list correctly lists GitHub Actions caches and the --jq flag works as expected (verified in the test output above).

However, unlike some gh commands which perform automatic pagination when given a high limit, the built-in gh cache list command does not support automatic pagination. The --limit 100 sets a hard cap on returned results; if a PR accumulates more than 100 caches, those beyond the limit will not be listed or deleted.

For most scenarios this is acceptable (26 caches in the test is typical), but in projects with extensive matrix builds or many CI runs, this could leave orphaned caches. Consider adding a loop to re-run the command if the result count equals 100, or use the official gh actions-cache extension which explicitly supports iterative cleanup.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rohit3523 Rohit3523 requested a deployment to approve_e2e_testing November 8, 2025 19:43 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to experimental_android_build November 8, 2025 19:47 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to official_android_build November 8, 2025 19:47 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to experimental_ios_build November 8, 2025 19:47 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants