Caching Dependencies to SPEED UP Workflows in GitHub Actions

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 31

  • @DevsLikeUs
    @DevsLikeUs 4 года назад +1

    Great advice , thank you!

    • @CoderDave
      @CoderDave  4 года назад +1

      You are so welcome!

  • @omoruboreoluwatobi6115
    @omoruboreoluwatobi6115 2 года назад +1

    @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
      @CoderDave  2 года назад

      I think it should be possible, just using the same key to retrieve from the caceh

  • @Cyril_C_C
    @Cyril_C_C 3 года назад +2

    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

    • @CoderDave
      @CoderDave  3 года назад +2

      Hi, here is the link to the GitHub Actions file: github.com/n3wt0n/HKOSCon2020/blob/master/.github/workflows/npmCache.yml

    • @Cyril_C_C
      @Cyril_C_C 3 года назад +1

      @@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

  • @alexandervu6015
    @alexandervu6015 3 года назад +1

    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.

    • @CoderDave
      @CoderDave  3 года назад +1

      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

  • @travissimmons8129
    @travissimmons8129 2 года назад +1

    @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

    • @CoderDave
      @CoderDave  2 года назад

      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

    • @travissimmons8129
      @travissimmons8129 2 года назад +1

      @@CoderDave Thank you. I could not find this documented anywhere.

  • @Cyril_C_C
    @Cyril_C_C 3 года назад +2

    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

    • @Cyril_C_C
      @Cyril_C_C 3 года назад +1

      😇😇😇 Waiting for your response...

    • @CoderDave
      @CoderDave  3 года назад +3

      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

    • @Cyril_C_C
      @Cyril_C_C 3 года назад +2

      @@CoderDave
      Thank you so much, Dave...

    • @Cyril_C_C
      @Cyril_C_C 3 года назад +1

      @@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

    • @CoderDave
      @CoderDave  3 года назад +1

      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..

  • @Chrosam
    @Chrosam Год назад

    Don't you wish RUclips had a feature to track how many minutes and seconds a video has progressed so far ?

  • @pascalie23109612
    @pascalie23109612 3 года назад +1

    Is there a reason why you use npm install over npm ci in your pipeline?

    • @CoderDave
      @CoderDave  3 года назад +2

      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

    • @moustafakamal9399
      @moustafakamal9399 3 года назад +1

      @@CoderDave well explained thnx

    • @stephanschuster9106
      @stephanschuster9106 2 года назад

      @@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.

  • @ashikurrahman4875
    @ashikurrahman4875 Год назад

    Life saver!

    • @CoderDave
      @CoderDave  Год назад

      Very happy you liked it ☺️

  • @jonyijoe
    @jonyijoe 3 года назад +1

    This was an amazing video thanks a lot

    • @CoderDave
      @CoderDave  3 года назад +1

      Thanks! Really happy it’s been helpful ☺️

  • @moustafakamal9399
    @moustafakamal9399 3 года назад +1

    Amazing thnx!