-
Notifications
You must be signed in to change notification settings - Fork 4
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: PR cache fallback to master/main branch's cache #573
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as outdated.
This comment was marked as outdated.
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
3 times, most recently
from
August 16, 2024 13:42
1ba5a26
to
68d6390
Compare
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
2 times, most recently
from
August 16, 2024 14:05
b766d55
to
9cf1f62
Compare
fredrikaverpil
changed the title
fix: use dynamic cache keys
fix: add branch name / target branch name to cache key
Aug 16, 2024
fredrikaverpil
changed the title
fix: add branch name / target branch name to cache key
fix: make cache fall back to default branch (if one doesn't exist for the PR)
Aug 16, 2024
fredrikaverpil
changed the title
fix: make cache fall back to default branch (if one doesn't exist for the PR)
fix: PR cache fallback to main branch's cache
Aug 16, 2024
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
from
August 16, 2024 15:30
9cf1f62
to
daa33ca
Compare
fredrikaverpil
changed the title
fix: PR cache fallback to main branch's cache
fix: PR cache fallback to master/main branch's cache
Aug 16, 2024
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
2 times, most recently
from
August 19, 2024 14:16
f3eacc4
to
80b7393
Compare
fredrikaverpil
commented
Aug 20, 2024
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
from
August 20, 2024 06:17
7a7770a
to
c82e83d
Compare
fredrikaverpil
force-pushed
the
dynamic-cache-keys
branch
from
August 20, 2024 10:21
c82e83d
to
79d930d
Compare
alethenorio
approved these changes
Aug 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure a PR always gets a cache hit
(unless there is no cache yet, or course)
Why this change?
In #571 we disabled
actions/go-setup
, and delegated all caching toactions/cache
because we can reliably pass it a cache key.However, it turns out that there are specific constraints/requirements around caches and branches:
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
Right now, the first commit of a PR doesn't use the cache that was created by another PR. But:
This means we could make sure to have a "master cache" that the PR falls back onto (using a
restore-keys
entry).What was changed?
First try (commit "fix: cache from branch, fallback to target branch")
key
andrestore-keys
values.Second try (commit "refactor: simplify cache keys")
key
andrestore-keys
values are just populated inline. A caveat of this approach is that each branch will produce a new cache. Risk for disk space blowing up and that we exceed the included disk space shown in https://github.com/organizations/einride/settings/billing (I don't have access there).Also...
restore_keys
values. This is rather unconventional but after discussions we decided we either wanted a 100% match from Go version +go.sum
to get a cache hit. If not, we would rather see no cache hit../sage/build
folder to cache (forgot this in earlier PR).actions/go-setup
cache in fix: address unreliable go dependency caching #571.Notes
Try it out without merging this PR
We should try this in some repo by setting this temporarily:
Do not forget to trigger cache creation in master
...to build the cache in the
master
branch.or something like:
Further improvement
When the first commit of a PR is pushed, the cache from
master
will be used. But at the end of the run, a new cache (for the PR) is written which takes around 1 minute in our larger repos with ~1.7 GB of cache.To shave off this minute in GHA and avoid exploding disk spage usage, we can opt in to only writing cache from
master
and only read cache from the PR.See here:
However, this requires breaking up this workflow into two workflows. Or create a post job, which I haven't done before, but seems possible although mighty quirky.
Either way, any of those methods looks like non-trivial changes to me, and I believe this PR (as it stands right now) balances the low-effort change with major impact quite nicely. The only question I would like to discuss is this.
We could add the following, which would also further lower the amount of disk space used by PR cache: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy