Skip to content
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

Pull_request close event not restoring existing cache with same key #1559

Closed
CelesteNzeza-Expel opened this issue Feb 19, 2025 · 1 comment
Closed

Comments

@CelesteNzeza-Expel
Copy link

CelesteNzeza-Expel commented Feb 19, 2025

I have a workflow that runs on pull_request with types [opened, synchronize, reopened, closed]. I can see that when I push commits to my pull request it's able to restore the cache, however when the same workflow runs when I merge the pr (type=closed) It's not able to restore the existing cache and it's instead creating a new cache with the same key.

From the docs:

When a cache is created by a workflow run triggered on a pull request, the cache is created for the merge ref (refs/pull/.../merge). Because of this, the cache will have a limited scope and can only be restored by re-runs of the pull request. It cannot be restored by the base branch or other pull requests targeting that base branch.

Does the merging the same pull request not count as a re-run? Can you please clarify if this is expected behavior or not?

I see that in the cache UI it lists there are two caches with the same key. One has ref/pulls/{pr-number} while the other has the name of the base branch (which is not the default branch).

@CelesteNzeza-Expel
Copy link
Author

I was able to get caching to work by using the pull_request_target instead of pull_request. My issue was the scoping of the caches that were created. When using pull_request the closed event would create the cache under the base branch while the opened, synchronize, reopened would create the cache under the pull request branch, so the closed event was not able to restore the cache created from the other events. After switching to pull_request_target all events create caches under the base branch which solved my issue.

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

No branches or pull requests

1 participant