-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
CI: Cache config.cache across runs to speed up build #104800
Conversation
where is the cache file stored? is it using per-repo or per-org storage? I'm not familiar with config.cache - are the configure and configure.ac files the only relevant inputs? I also tried thinking about cross-branch and cross-PR interactions, but since the key uses the hash of the input files then if the hashes are identical across branches and PRs then it should be ok to reuse the cached file. one concern is implicit inputs that are not captured by the current key:
|
https://github.com/actions/cache does it per-org, so it won't be shared with forks. Forks will have their own copies.
Let's ask @erlend-aasland :)
I ran this PR twice: once with no cache, and second time with cache present.
Could you give an example?
I think the action will invalidate the cache itself if they change something, but I couldn't find anything to confirm. I also don't think the action's version is exposed, anyway. |
Also, environment variables:
|
@arhadthedev provided examples :) the result can also be affected by the exact OS version (I don't know how granular regarding the implementation - hashFiles can operate on multiple files, so use |
👍
https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context I added the workflow file to hashFiles, so it will invalidate and make a new cache when things defined in the file change, for example the env vars and CLI flags. There's a
Possibly but I'm not sure if it's worth the complexity: we can just have hashFiles computed each time. |
LG!
this will be over-conservative, invalidating for any change in the workflow file, even if it doesn't affect the result (which is probably most changes). probably a fair trade off (preferring correctness over CI latency).
agreed. I'd suggest at least refactoring the list of files to be a shared constant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. With the workflow file in the cache key, we're pretty safe regarding any environment change.
I guess we want this CI speedup in the other branches as well. |
Do you know how to do this? I tried a few things, but didn't get it working. |
I think workflow-level environment variable can work for this https://docs.github.com/en/actions/learn-github-actions/variables |
I tried that like: env:
CONFIG_CACHE_HASH_FILES: ${{ hashFiles('configure', 'configure.ac', '.github/workflows/build.yml') }} and: key: ${{ github.job }}-${{ runner.os }}-${{ env.CONFIG_CACHE_HASH_FILES }} But it said "The workflow is not valid ", "Unrecognized function: 'hashFiles'" I also tried: env:
CONFIG_CACHE_HASH_FILES: ('configure', 'configure.ac', '.github/workflows/build.yml') and: key: ${{ github.job }}-${{ runner.os }}-${{ hashFiles(env.CONFIG_CACHE_HASH_FILES) }} But it couldn't read the env var:
Let me try again with https://github.com/orgs/community/discussions/25761#discussioncomment-4626908 |
Hmm, no luck, because it formats into strings, and we need a sort of tuple of strings. We might be able to do something like: env:
CONFIG_CACHE_HASH_FILE1: 'configure'
CONFIG_CACHE_HASH_FILE2: 'configure.ac'
CONFIG_CACHE_HASH_FILE3: '.github/workflows/build.yml' And then format it something like this: key: ${{ github.job }}-${{ runner.os }}-${{ hashFiles(format('{0}', env.CONFIG_CACHE_HASH_FILE1))-${{ hashFiles(format('{0}', env.CONFIG_CACHE_HASH_FILE2))-${{ format('{0}', env.CONFIG_CACHE_HASH_FILE3)) }} But it feels like a backward refactor... |
yeah, I agree, this doesn't improve anything. let's leave it as explicit lists of files, I might give it another try separately after this merges. |
Backport through all security branches? |
Sorry @hugovk, I had trouble checking out the |
GH-104967 is a backport of this pull request to the 3.12 branch. |
GH-104968 is a backport of this pull request to the 3.11 branch. |
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, @hugovk, I could not cleanly backport this to |
Sorry @hugovk, I had trouble checking out the |
Sorry, @hugovk, I could not cleanly backport this to |
Sorry @hugovk, I had trouble checking out the |
Actually, maybe we should skip the security branches? They've already diverged quite a bit, and don't get built (or backported) as often, so there's less benefit. |
Yeah, makes sense. |
… (#104968) Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
I think it worked out nicely in gh-105008 |
Run
./configure
with the--config-cache
to create a cache file on Ubuntu and macOS jobs, and use https://github.com/actions/cache to re-use it between runs:When the key changes, the action will upload a fresh cache file.
So we have a unique cache file per job ID (
github.job
, for example:build_macos
,build_ubuntu_ssltests
), and we'll also get a fresh cache file whenever theconfigure
orconfigure.ac
files change.Seconds to download cache + configure: