Uh oh!
There was an error while loading. Please reload this page.
CI: Cache config.cache across runs to speed up build - #104800
Conversation
itamaro
commented
May 23, 2023
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:
|
hugovk
commented
May 23, 2023
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:
|
itamaro
commented
May 23, 2023
@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 |
hugovk
commented
May 23, 2023
👍
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. |
erlend-aasland
left a comment
There was a problem hiding this comment.
LGTM. With the workflow file in the cache key, we're pretty safe regarding any environment change.
erlend-aasland
commented
May 23, 2023
I guess we want this CI speedup in the other branches as well. |
hugovk
commented
May 24, 2023
Do you know how to do this? I tried a few things, but didn't get it working. |
itamaro
commented
May 24, 2023
I think workflow-level environment variable can work for this https://docs.github.com/en/actions/learn-github-actions/variables |
hugovk
commented
May 24, 2023
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 |
hugovk
commented
May 24, 2023
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... |
itamaro
commented
May 24, 2023
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. |
erlend-aasland
commented
May 25, 2023
Backport through all security branches? |
miss-islington
commented
May 26, 2023
Sorry @hugovk, I had trouble checking out the |
bedevere-bot
commented
May 26, 2023
GH-104967 is a backport of this pull request to the 3.12 branch. |
bedevere-bot
commented
May 26, 2023
GH-104968 is a backport of this pull request to the 3.11 branch. |
miss-islington
commented
May 26, 2023
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
miss-islington
commented
May 26, 2023
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
miss-islington
commented
May 26, 2023
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
miss-islington
commented
May 26, 2023
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10. |
miss-islington
commented
May 26, 2023
Sorry, @hugovk, I could not cleanly backport this to |
miss-islington
commented
May 26, 2023
Sorry @hugovk, I had trouble checking out the |
miss-islington
commented
May 26, 2023
Sorry, @hugovk, I could not cleanly backport this to |
miss-islington
commented
May 26, 2023
Sorry @hugovk, I had trouble checking out the |
hugovk
commented
May 26, 2023
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. |
erlend-aasland
commented
May 26, 2023
Yeah, makes sense. |
… (#104968) Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
itamaro
commented
May 27, 2023
I think it worked out nicely in gh-105008 |
Run
./configurewith the--config-cacheto 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 theconfigureorconfigure.acfiles change.Seconds to download cache + configure: