-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Caching test results across action runs #22
Comments
I'm curious, is there a particular reason you want the test cache to be included? I generally want CI to always re-run the tests, so I can catch flaky tests more easily. I'm fairly sure that the test results are also cached in the build cache; see
|
I think for big repositories you can take advantage of the test cache and additionally set up a |
Sure, I don't oppose improving the docs here. Someone has to dig into the actual reason why the test cache isn't being reused, though - I laid out three possibilities above. I don't have the time to dig into them right now. |
I'm digging into this. On a small repo I've managed to get test caching working reliably using the instructions in this repo. The same instructions applied to another repo with no testdata, no file loading, and only one consistent environment variable results in no test caching. I think it might be related to test caching not working when running a single test package vs |
Maybe test caching is broken in Go when any env var is read. In my test example when an |
I think I know what the issue is. It's the cache key we're using. GitHub Actions will not resave the cache if it got a cache hit on cache load, which means if go.sum hasn't changed, then we won't update the cache even if other things have changed! |
Hm, that's unfortunate. I guess it makes sense from a "pure deterministic cache" perspective on their end, but on our end it's very hard to provide a proper, full cache key that combines all inputs for Go's module deps, package builds, and tests. CC @FiloSottile since he raised similar points in #12. I think using hashes of go.sum files is fine if we are only caching the module download cache. But if we're also caching package builds and tests, it's certainly not enough. Perhaps |
I'd go further and include all files in the hash, because test files could impact the build too. This is the pattern I'm using now: - uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-go-mod
- uses: actions/cache@v2
if: ${{ github.ref != 'master' }}
with:
path: ~/.cache/go-build
key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-go-all-${{ github.ref }}-${{ hashFiles('**', '!.git') }}
restore-keys: |
${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-go-all-${{ github.ref }}
${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-go-all See it in context here: stellar/go#3727 Note that I've chosen to include If there was a way to serialize the |
Oh, wow, that's pretty long :P At that point, practically any commit would result in a different cache key, right? I wonder how feasible it would be to just use something like... key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-${{ RANDOM_STRING }}
restore-keys: |
${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}-${{ RANDOM_STRING }}
${{ github.workflow }}-${{ github.job }}-${{ matrix.go }}-${{ runner.os }}- I assume the full github commit hash is a good approximation for "random". |
The cache key needs to be unique if the tests could result in different results, so those different results get cached. The restore keys value will ensure a recent cache is selected.
The commit head would work too. I'm taking a hash of all files in the working directory. A commit hash would also be sufficient. Could also just use the github actions build number. The environment (like the versions of services like Postgres that might be in the matrix) is still important, so we still need those values in the cache key. |
I've found this repo very helpful, thank you! I've noticed that using the actions-cache as demonstrated in the repo doesn't result in tests being cached. I know on my local machine when I rerun tests for packages that haven't changed the results are cached, but when I run on GitHub Actions even with all the cache directories setup the tests aren't cached.
It'd help speed up tests for a lot of Go projects if we could figure that out.
The text was updated successfully, but these errors were encountered: