DeLaGuardo / setup-clojure

GitHub Action to provision clojure's most popular build tools for Linux, Mac OS X and Windows.
MIT License
185 stars 28 forks source link

Are downloads cached? #6

Closed aviflax closed 2 years ago

aviflax commented 4 years ago

Hi, I’m interested in using this action, but I can’t tell whether it caches Clojure and whichever tools are specified (in my case it’d be tools.deps along with the CLI tools.) I’m generally uncomfortable with automations that download the same dependencies every time they run, so I personally tend to include very comprehensive caching in my automations (example).

I did search the code and saw that it’s using @actions/tool-cache which seems promising, but when I read the docs I found this:

Finally, you can cache these directories in our tool-cache. This is useful if you want to switch back and forth between versions of a tool, or save a tool between runs for self-hosted runners.

(emphasis mine)

This seems to imply that @actions/tool-cache does not actually, you know, cache anything, when running on GitHub’s runners. But of course, there’s a very good chance I’m just missing something here.

Bottom line: does this action currently its downloads when running on GitHub’s runners?

Thank you!

rymndhng commented 4 years ago

Take this with a grain of salt (since I'm not the maintainer), but I believe it does cache. If you read further down the doc you linked:

You can also cache files for reuse.

const tc = require('@actions/tool-cache');
const cachedPath = await tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');

Also a cursory look at the code confirms that the functions are used. See https://github.com/DeLaGuardo/setup-clojure/search?q=cacheDir

pmonks commented 3 years ago

GitHub's cache action does this, and is leveraged by the setup-java action for exactly this purpose.

I too am in favour of setup-clojure doing something similar, though in looking through the setup-java action's code to try to see how this might be done (for a PR), I realised I'm way out of my depth when it comes to the specifics of implementing GitHub actions.

zharinov commented 2 years ago

I did some research and can conclude that GitHub action should be widespread enough in order to benefit from tool cache.

Here is the result of ls /opt/hostedtoolcache/ command executed in the action step:

CodeQL
Java_Adopt_jdk
Java_Temurin-Hotspot_jdk
PyPy
Python
Ruby
go
node

It seems like each next run is more likely to be performed in some other random machine. For some reason, I assumed GitHub has mechanism that assigns previously used physical runners when possible, so we often hit the tool cache. Seems like it's not the case.

zharinov commented 2 years ago

If I understand correctly, there is two separate cache concepts for GitHub actions:

What we probably want is to leverage the second one to store Java distributions, Clojure tools, .m2 and git-based dependencies as well.

What I want to try is to pre-populate @actions/tool-cache items with previously saved @actions/cache items such that setup-java, setup-graalvm and setup-clojure itself would frequently find their respective tooling.