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.cachedirectory shall never be present.Simply put, the approaches described above, either constantly create a new cache on each
github.refschange or create it once and constantly reuse the same cache files and constantly recreate changes.The solution to this are
restore-keyshttps://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.shasince it's the commit hash, similar output to thehashFilesfunction.Same issue applied to other
npmcaches in the workflows, but I can also understand wanting to invalidate caches frequently, therefore I didn't change them.