Dynamic paths for `save_cache` command

Hi there :wave:

Context:
Iโ€™m currently trying to reduce installation time for my monorepo.

The current install-dependencies command contains the following save_cache command.

      - save_cache:
          name: "Save src dependencies"
          key: v2-cache-{{ arch }}-{{ checksum "yarn.lock" }}
          paths:
            - ./node_modules

Issue:

The truth is that is not efficient as some of my modules have their own node_modules and they are not cached.

:point_right: Note: I also try to use the recommended way to cache yarn dependencies, but it doesnโ€™t have the expected effect.

Then I thought that I could:

  • run a script that outputs all the paths of my sub-folders (modules) that contains a node_modules folder.
  • set them in a variable (array of string , or even a string with commas)
  • use it as keys for save_cache command.

My issue is mainly with the two last points. Here is the job I implemented:

generate-paths-for-caching:
    steps:
      - run:
          name: "get modules with node_modules"
          command: |
            export PATHS=$(node ./npm/utils/ci/get-packages-path-to-cache.js)
            echo $PATHS >> $BASH_ENV

I tried to used what Iโ€™ve seen on the documentation.

It seems to work as all the paths generated by my scripts are stored in the $BASH_ENV file.

But What I can I do with that? How can I use it in the save_cache command?

1 Like