-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GitHub Action caching methodology #5448
Conversation
Thanks for the PR! To clarify:
I've chosen |
Maybe I did something incorrectly in our project's branch. The ref would typically be
True, the "cleanest" approach requires creating the hash based on the files that will actually change. But since the
According to the docs the caches are bound to their respective branch / scope, and they can only restore caches from their "upper" branches. So in case of this repository a feature branch will only have read access to the |
Thanks for the quick explainer! Sounds all good to me, let's give it a try |
It seems I made a mistake reading the docs previously. According to the docs the github.ref for merges would be The |
Oh, no worries. Could you create a new PR? |
Sure, I will do that shortly ~1 hour. Considering the amount of people who use the project I do see that adverting |
Hi, 👋
I've been working on adding social cards to our documentation, and I've encountered a mistake in the advertised caching methodology, then I checked this project's workflow file and it had almost the same mistake present.
mkdocs-material/docs/publishing-your-site.md
Lines 41 to 44 in 2ac2cbc
mkdocs-material/.github/workflows/documentation.yml
Lines 49 to 54 in 2ac2cbc
As seen in this action run the cache is being restored:
https://github.com/squidfunk/mkdocs-material/actions/runs/4837605087/jobs/8621534809#step:4:21
but it is not being saved:
https://github.com/squidfunk/mkdocs-material/actions/runs/4837605087/jobs/8621534809#step:14:2
It is not being saved, because the cache hit occurred on the primary
key
. Also it will always be the same emptyLinux-
key because during the hash check the.cache
directory shall never be present.Simply put, the approaches described above, either constantly create a new cache on each
github.refs
change or create it once and constantly reuse the same cache files and constantly recreate changes.The solution to this are
restore-keys
https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cacheThis approach works based on a cache key prefix, which will be used as a fallback if the primary key isn't found.
I've used the
github.sha
since it's the commit hash, similar output to thehashFiles
function.Same issue applied to other
npm
caches in the workflows, but I can also understand wanting to invalidate caches frequently, therefore I didn't change them.