gradle / actions

A collection of GitHub Actions to accelerate your Gradle Builds on GitHub
https://github.com/marketplace/actions/build-with-gradle
MIT License
169 stars 42 forks source link

Allow cache entries to be reused on different runner operating systems #27

Open hfhbd opened 1 year ago

hfhbd commented 1 year ago

GitHub Actions/Cache supports enableCrossOsArchive to reuse the same cache from different operating systems. This is very handy for matrix builds using multiple OS to further reduce the CI time (and costs).

https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache

bigdaz commented 1 year ago

Thanks for the report. To make this work, we'd need to do the following:

  1. Identify which parts of Gradle User Home can be safely reused across operating systems. For example, downloaded jars are likely to be compatible, compiled build scrips may not be.
  2. All cache keys currently embed RUNNER_OS value at the lowest level. This would have to be removed for non-shareable caches. Perhaps it could be removed in general since OS entries are implicitly separate without enableCrossOsArchive.
  3. For sharable entries, pass enableCrossOsArchive: true on these calls to save and restore the cache.

PRs welcome!

bigdaz commented 7 months ago

I took a look and found another snag: since the paths to Gradle User Home are different on Linux vs Windows, just passing enableCrossOsArchive: true when saving and restoring isn't enough. Any files to be shared would need to be first moved to an OS agnostic location before calling saveCache or restoreCache. Without this, the entry pattern values are different, and the entries won't be shared.

hfhbd commented 4 months ago

Given that with the latest version we also take the arch as key and not all dependencies/caches (like Kotlin MPP) supports multi OS out of the box, I think we can close this issue.

bigdaz commented 4 months ago

I think this might still be useful for entries extracted from Gradle User Home. For example, we extract the dependency jars into a separate entry that can be reused even as other parts of Gradle User Home change.

Some of these extracted entries are not inherently tied to OS/arch and should/could be reusable between different OSes.