Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Write caches on main branch only by default #143

Closed
3flex opened this issue Jan 25, 2022 · 4 comments
Closed

Write caches on main branch only by default #143

3flex opened this issue Jan 25, 2022 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@3flex
Copy link
Contributor

3flex commented Jan 25, 2022

In #120 (comment) it was stated that there was consideration of changing the config default so the cache is only written from main branch, thus preventing many PR builds from exhausting available cache and evicting the main branch's cache.

Just creating this issue for tracking (or rejection). I think it makes sense to change the default.

@bigdaz bigdaz added the enhancement New feature or request label Jan 26, 2022
@bigdaz
Copy link
Member

bigdaz commented Jan 28, 2022

I'm more and more convinced that this is a good idea, but I'm not sure how to model it.

Option 1: keep cache-read-only as is, but change the default value when it's not set.

  • Can explicitly set to either 'true' or 'false'
  • Default will be to use the GH API to determine the default branch, and use 'true' unless the current branch == default branch.

Option 2: Add a 'cache-write-branches' parameter (or something with a better name). Only builds on these branches (or matching a pattern) would write to the cache.

  • Default this to the repository default branch name
  • User could then provide something like cache-write-branches: main, release, feature-*

Option 2 is really just a more convenient way of specifying option 1. So I think I'd start with Option 1 and leave Option 2 open for later.

@bigdaz bigdaz added this to the v2.2.0 milestone Jan 28, 2022
bigdaz added a commit that referenced this issue Jan 28, 2022
Cache entries _written_ from jobs run on a non-default branch will be private
to other jobs for that branch. When development flow involves working on a
feature branch and then merging into 'main', these branch-private cache
entries can result in eviction of other (shared) cache entries generated
for the default branch.

With this change, we make the recommended setup the default, by running
with `cache-read-only: true` for any jobs run on a non-default branch.
These jobs will be able to read cache entries written from the main branch,
but will not write any cache entries.

Fixes #143
@bigdaz
Copy link
Member

bigdaz commented Jan 28, 2022

This was surprisingly easy to implement: e1f5f66

However, I'm a little wary since this would have a negative impact on projects that do their primary development on a non-default branch. For instance, a project that uses 'main' for their latest stable release and some other branch for active development.
I don't really have a good answer here: this change will give a mild benefit many users who will get more efficient caching, but might have a significant negative impact on a smaller set of users (who would get no caching at all).

@bigdaz
Copy link
Member

bigdaz commented Jan 28, 2022

For reference, here is the documentation where we recommend this pattern: https://github.com/gradle/gradle-build-action#only-write-to-the-cache-from-the-default-branch

@bigdaz bigdaz removed this from the v2.2.0 milestone May 29, 2022
@bigdaz
Copy link
Member

bigdaz commented Jun 3, 2022

I think we should add this in v2.2.0, with an appropriate message in the Job Summary informing users that the cache is read-only and why.

@bigdaz bigdaz added this to the v2.2.0 milestone Jun 3, 2022
@bigdaz bigdaz closed this as completed in 0a36ca9 Jun 4, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants