|
| 1 | +# 0. Support caching dependencies for mono repos |
| 2 | +Date: 2021-07-13 |
| 3 | + |
| 4 | +Status: Proposed |
| 5 | + |
| 6 | +## Context |
| 7 | +Currently, `actions/setup-node` supports caching dependencies for Npm and Yarn package managers. |
| 8 | +For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root. |
| 9 | +Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities) |
| 10 | + |
| 11 | +Obviously, it made build-in caching unusable for mono-repos and repos with complex structure. |
| 12 | +We would like to revisit this decision and add customization for dependencies lock file location. |
| 13 | + |
| 14 | +## Proposal |
| 15 | +We have the following options: |
| 16 | +1. Allow to specify directory where `package-lock.json` or `yarn.lock` are located |
| 17 | +2. Allow to specify path to the dependencies lock file (including directory path and filename) |
| 18 | + |
| 19 | +The second option looks more generic because it allows to: |
| 20 | +- specify multiple dependencies files using file patterns like `**/package-lock.json` ([one of recommended approaches in actions/cache](https://github.com/actions/cache/blob/main/examples.md#macos-and-ubuntu)) |
| 21 | +- specify custom dependencies files like `src/npm-shrinkwrap.json` |
| 22 | +- change default resolving priority if both `yarn.lock` and `package-lock.json` exist in repository |
| 23 | + |
| 24 | +## Decision |
| 25 | + |
| 26 | +Add `cache-dependency-path` input that will accept path (relative to repository root) to dependencies lock file. |
| 27 | +If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does. |
| 28 | +The hash of provided matched files will be used as a part of cache key. |
| 29 | + |
| 30 | +Yaml examples: |
| 31 | +```yml |
| 32 | +steps: |
| 33 | +- uses: actions/checkout@v2 |
| 34 | +- uses: actions/setup-node@v2 |
| 35 | + with: |
| 36 | + node-version: 14 |
| 37 | + cache: npm |
| 38 | + cache-dependency-path: 'sub-project/package-lock.json' |
| 39 | +``` |
| 40 | +```yml |
| 41 | +steps: |
| 42 | +- uses: actions/checkout@v2 |
| 43 | +- uses: actions/setup-node@v2 |
| 44 | + with: |
| 45 | + node-version: 14 |
| 46 | + cache: yarn |
| 47 | + cache-dependency-path: 'sub-project/**/yarn.lock' |
| 48 | +``` |
0 commit comments