Skip to content

Allow optionally refreshing existing cache entries.#1096

Open
Lord-Kamina wants to merge 11 commits into
actions:mainfrom
Lord-Kamina:refresh-cache
Open

Allow optionally refreshing existing cache entries.#1096
Lord-Kamina wants to merge 11 commits into
actions:mainfrom
Lord-Kamina:refresh-cache

Conversation

@Lord-Kamina
Copy link
Copy Markdown

Description

By enabling an optional input, this feature allows users to update existing cache keys. The way this can be done is by using Octokit to send a request to the Github API to delete the matched cache. This then allows the key to be reused and the save step to operate as if there hadn't been a match in the first place.

Motivation and Context

Pretty much since forever, people have been asking for a way to update existing cache entries. As of now, the best alternative is to just create a slightly different key each time, which would rapidly consume space.
#1093

How Has This Been Tested?

I have written tests to test the functionality. They:

Test the deleteCacheByKey function in three scenarios: A successful and an unsucessful request (using MSW to mock the Github API), as well as a real request to the API, which is expected to return a 401 error because it uses a bogus token.

Test the run function in the scenarios of refresh-cache being enabled, but not being provided an API token, as well as a successful scenario in which it would attempt to delete the existing cache, and then reupload it.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (add or update README or docs)

Checklist:

  • My code follows the code style of this project. (Or at least I think? I run both the lint and format scripts)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Lord-Kamina Lord-Kamina requested a review from a team as a code owner January 31, 2023 14:12
@github-actions github-actions Bot requested a review from Phantsure January 31, 2023 14:12
@Lord-Kamina
Copy link
Copy Markdown
Author

Due to the conflict in README., I just noticed I haven't updated the granular save action, will fix that now.

@cdce8p
Copy link
Copy Markdown
Contributor

cdce8p commented Feb 9, 2023

Personally, I'd love this option. However, just from working the the cache API myself I noticed permission issues with deleting cache entries. For example the normal pull_request trigger doesn't grant the required write access to the parent repo.

Unfortunately, that might be a dealbreaker with that approach.

@Lord-Kamina
Copy link
Copy Markdown
Author

Lord-Kamina commented Feb 10, 2023

Personally, I'd love this option. However, just from working the the cache API myself I noticed permission issues with deleting cache entries. For example the normal pull_request trigger doesn't grant the required write access to the parent repo.

Unfortunately, that might be a dealbreaker with that approach.

I have tested it from a pull_request from the same repo, which works fine. I'd have to try it from a fork and see how it goes. It would make sense that maybe it won't work. However, is it a deal breaker? It should just report a warning and move on in that case.

EDIT: You can see exactly that outcome in here: https://github.com/Lord-Kamina/actions-cache-update/actions/runs/4144733484/jobs/7168158463

Now... there are few scenarios I can think of when you would want an external PR to be able to manipulate your existing cache. The main one would be a project developer doing work on their personal fork and then submitting it as a PR.

In this scenario, the limitation could likely be circumvented by using a PAT instead, no?

@Lord-Kamina
Copy link
Copy Markdown
Author

I have rebased this on main, as well as corrected a couple errors and added a way to update an existing cache even if using the granular save action (uses a lookup to see if the key exists)

@Lord-Kamina Lord-Kamina force-pushed the refresh-cache branch 2 times, most recently from 7755eb5 to 6e0386c Compare February 4, 2025 16:32
@Lord-Kamina
Copy link
Copy Markdown
Author

Hey everyone... I've been using this branch pretty much since I posted it way back when, without many issues. I recently realized there was a bug in my logic and have corrected it, as well as updated and rebased it.

Is there any chance this could get merged now?

@Lord-Kamina Lord-Kamina force-pushed the refresh-cache branch 2 times, most recently from a25a486 to 4043ab8 Compare February 4, 2025 17:27
@Lord-Kamina
Copy link
Copy Markdown
Author

Note: CI runs on my fork are all good except for some reason prettier is complaining but only on windows, which I can't reproduce because I'm on mac. The workflow logs don't really give details either as to what the issue actually is.

https://github.com/Lord-Kamina/always-upload-cache/actions/runs/13141274792/job/36668786025#annotation:5:13

@Lord-Kamina
Copy link
Copy Markdown
Author

Once again, rebased onto the main branch, and I've also figured out what the issue was with the tests on my branch. Made some additional changes to how eslint and prettier were being invoked, and corrected all those errors.

@Lord-Kamina
Copy link
Copy Markdown
Author

image

@tanuj077 tanuj077 removed their assignment Feb 12, 2026
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
And rebuild.

Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
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.

4 participants