I have a few separate caches set up for my Gradle-based project but I noticed today that cache restoration seems to not happen at all. Actions says there is no cache hit when it attempts to restore it before the build, then says it can’t create the cache because it already exists. I’m not sure what’s up with this, are caches not accessible to PRs from forks?
are caches not accessible to PRs from forks?
Sure, caches is available to PRs from forks. However, there are some restrictions for accessing a cache that you need to know.
According to the description below from the docs about cache:
With v2 of the cache action, you can access the cache in workflows triggered by any event that has a GITHUB_REF.
A workflow can access and restore a cache created in the current branch, the base branch (including base branches of forked repositories), or the default branch (usually master).
The cache created for a branch would not be accessible to its base branch and other branches which are not based on this branch.
Similarly, the cache created in the forked repository would not be accessible to the original repository. If you create a cache in the forked repository, this cache is not accessible to the PR opened for merging from the forked repository into the original repository, because this PR is opened in the original repository.
Welp, that’d explain it. Thanks for your assistance!
@brightran I’ve been having the same problem. I’ve been creating a cache during my release pushes but it’s never found during future releases. According to your explanation that’s because I’m creating the cache on a release branch and not a base branch.
What would the proper workflow be then? Should I run a separate GitHub Action on the master branch to cache my data and only run it again if I need to update the cache? I’m using cache@v2 btw.