DEV Community

Discussion on: How to cache node_modules in GitHub Actions with Yarn

Collapse
 
nk1tz profile image
Nathan • Edited

Great idea.

After implementing your second solution, I noticed the dependency installation was not being shortened.
I ran the CI a few times with no changes. The cache step was taking 0-1s and the proceeding yarn install step always took the same amount of time it used to.

Maybe I'm reaching the limits of cache space? Unlikely as my dependency installation time is much smaller than your 4 minutes.

However your first solution has worked for me, but as you mentioned the savings are minor.

Is there any special you also needed to do alongside solution #2 to make it work?

Thank you,

Collapse
 
mattpocockuk profile image
Matt Pocock • Edited

Yes, it's possible you're reaching the end of your cached space. There is a final step at the end of each GH action where it saves the cache. Is this step passing?

Collapse
 
mattpocockuk profile image
Matt Pocock

Also, is your repo a monorepo or a single project repo?

Collapse
 
chadlavicasebook profile image
Chad Lavimoniere

You all should refer to this example:

github.com/actions/cache/blob/main...

you're still getting a yarn install because you're never checking whether the cache hits. Honestly I don't know how the OP ever got this to work in the first place.

The whole point here is you need to create the cache, then see if it hits, and use whether or not it hits to determine whether or not you should take a given action.