@CoderDave what if you want the cache action to work for different JOBS. In your case you only use it inside BUILD. In my case I want to use the automated dependencies in TEST, BUILD, ANALYSE
@@CoderDave Thank you so much, Dave. I will keep in touch with you always. Definitely, I will join your community as I am preparing to join CI team at College of Computer Science, University of Illinois. Take good care always. Cheers. Regards Cyril
Great and amazing video. Thanks a lot!!! Some advice on npm. We do not use `npm install` but `npm ci`. `npm install` do not use the package-lock.json file. `npm ci` do.
Thanks for your comment. Npm ci is only available in version 6, if someone is using version 5 they wouldn’t have it. Also, since I’m using it in Hosted Agents I don’t have the problem of needing to make sure it’s a clean state... because it is always a new clean agent by design. Finally, you can’t cache npm ci... in fact, if it finds an npm modules folder it deletes it and reinstall everything
Good question. The ID must be static, because it is used before runtime to generate an execution plan for the Action. It is used to reference that step in other steps
Dave, I was wondering... How would your caching know if the dependencies changed or not, i.e., whether it can use the result from the cache or not? Thanks
The cache knows that based on the `key` which is specified. In the example I used (and the file linked to my other comment), you see that they key for the cache is cmposed by the runner OS, a cachename variable and most importantly by the hash of the dependency definition file. Because of that, if a dependency changes the hash of the file will be different, making the cache key different... hence, the cache knows that it can't use the current cache value but will generate a new one PS: I've replied to your email as well
@@CoderDave Hi Dave, Just some concerns below: >>>> The cache knows that based on the `key` which is specified. >>>> the key [...] is composed [...] the hash of the dependency definition file. What if some dependency/ies have the same name but different content? In the Java world, one usually does that by naming dependencies SNAPSHOT. I don't know what's commonly done in the NPM world. Thank you so much. Regards
Hey, well that shouldn’t be a problem. You should never have 2 different libraries / dependencies with the same name but different content. If you have 2 version of the same library, then even if the name is the same the version changes and invalidate the cache If instead you have 2 different libraries with the same name it is a big problem not just for the cache but in general… how would any dependency manager know which library to consume? Plus any dependency repo requires unique names so you won’t be able to save the dependencies anywhere..
Npm ci is only available in version 6, if someone is using version 5 they wouldn’t have it. Also, since I’m using it in Hosted Agents I don’t have the problem of needing to make sure it’s a clean state... because it is always a new clean agent by design. Finally, you can’t cache npm ci... in fact, if it finds an npm modules folder it deletes it and reinstall everything
@@CoderDave It is correct, that npm ci would clear the node_modules folder. But the use case discussed here doesn't try to cache the the local node_modules but the global .npm cache.
Great advice , thank you!
You are so welcome!
@CoderDave what if you want the cache action to work for different JOBS. In your case you only use it inside BUILD. In my case I want to use the automated dependencies in TEST, BUILD, ANALYSE
I think it should be possible, just using the same key to retrieve from the caceh
Hi Dave,
Please, could you send me link to this project, let me try it myself.
I'm new to this, please.
Thank you. Regards
Hi, here is the link to the GitHub Actions file: github.com/n3wt0n/HKOSCon2020/blob/master/.github/workflows/npmCache.yml
@@CoderDave
Thank you so much, Dave.
I will keep in touch with you always.
Definitely, I will join your community as I am preparing to join CI team at College of Computer Science, University of Illinois.
Take good care always. Cheers.
Regards
Cyril
Great and amazing video. Thanks a lot!!! Some advice on npm. We do not use `npm install` but `npm ci`. `npm install` do not use the package-lock.json file. `npm ci` do.
Thanks for your comment. Npm ci is only available in version 6, if someone is using version 5 they wouldn’t have it. Also, since I’m using it in Hosted Agents I don’t have the problem of needing to make sure it’s a clean state... because it is always a new clean agent by design. Finally, you can’t cache npm ci... in fact, if it finds an npm modules folder it deletes it and reinstall everything
@CoderDave can the id value be dynamic or does it have to be a static value like what you have in the video with: myCacheStep
Good question. The ID must be static, because it is used before runtime to generate an execution plan for the Action. It is used to reference that step in other steps
@@CoderDave Thank you. I could not find this documented anywhere.
Dave, I was wondering...
How would your caching know if the dependencies changed or not, i.e.,
whether it can use the result from the cache or not?
Thanks
😇😇😇 Waiting for your response...
The cache knows that based on the `key` which is specified. In the example I used (and the file linked to my other comment), you see that they key for the cache is cmposed by the runner OS, a cachename variable and most importantly by the hash of the dependency definition file. Because of that, if a dependency changes the hash of the file will be different, making the cache key different... hence, the cache knows that it can't use the current cache value but will generate a new one
PS: I've replied to your email as well
@@CoderDave
Thank you so much, Dave...
@@CoderDave
Hi Dave,
Just some concerns below:
>>>> The cache knows that based on the `key` which is specified.
>>>> the key [...] is composed [...] the hash of the dependency definition file.
What if some dependency/ies have the same name but different content? In
the Java world, one usually does that by naming dependencies SNAPSHOT. I
don't know what's commonly done in the NPM world.
Thank you so much.
Regards
Hey, well that shouldn’t be a problem. You should never have 2 different libraries / dependencies with the same name but different content.
If you have 2 version of the same library, then even if the name is the same the version changes and invalidate the cache
If instead you have 2 different libraries with the same name it is a big problem not just for the cache but in general… how would any dependency manager know which library to consume? Plus any dependency repo requires unique names so you won’t be able to save the dependencies anywhere..
Don't you wish RUclips had a feature to track how many minutes and seconds a video has progressed so far ?
Is there a reason why you use npm install over npm ci in your pipeline?
Npm ci is only available in version 6, if someone is using version 5 they wouldn’t have it. Also, since I’m using it in Hosted Agents I don’t have the problem of needing to make sure it’s a clean state... because it is always a new clean agent by design. Finally, you can’t cache npm ci... in fact, if it finds an npm modules folder it deletes it and reinstall everything
@@CoderDave well explained thnx
@@CoderDave It is correct, that npm ci would clear the node_modules folder. But the use case discussed here doesn't try to cache the the local node_modules but the global .npm cache.
Life saver!
Very happy you liked it ☺️
This was an amazing video thanks a lot
Thanks! Really happy it’s been helpful ☺️
Amazing thnx!
Thanks 🙏🏻