From d9aab2aba42682d8d25f49f0be491c3e8d56ccdb Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 13 Jul 2021 16:28:09 +0300 Subject: [PATCH 1/4] dra --- docs/adrs/0000-caching-dependencies.md | 2 +- ...0001-support-caching-deps-for-monorepos.md | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 docs/adrs/0001-support-caching-deps-for-monorepos.md diff --git a/docs/adrs/0000-caching-dependencies.md b/docs/adrs/0000-caching-dependencies.md index 99a6932e..c862a8d4 100644 --- a/docs/adrs/0000-caching-dependencies.md +++ b/docs/adrs/0000-caching-dependencies.md @@ -1,7 +1,7 @@ # 0. Caching dependencies Date: 2021-05-21 -Status: Proposed +Status: Accepted # Context `actions/setup-node` is the 2nd most popular action in GitHub Actions. A lot of customers use it in conjunction with [actions/cache](https://github.com/actions/cache) to speed up dependencies installation. diff --git a/docs/adrs/0001-support-caching-deps-for-monorepos.md b/docs/adrs/0001-support-caching-deps-for-monorepos.md new file mode 100644 index 00000000..98167ec6 --- /dev/null +++ b/docs/adrs/0001-support-caching-deps-for-monorepos.md @@ -0,0 +1,48 @@ +# 0. Support caching dependencies for mono repos +Date: 2021-07-13 + +Status: Proposed + +## Context +Currently, `actions/setup-node` supports caching dependencies for Npm and Yarn package managers. +For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root. +Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities) + +Obviosly, it made build-in caching unusable for mono-repos and repos with complex structure. +We would like to revisit this decision and add customization for dependencies lock file location. + +## Proposal +We have the following options: +1. Allow to specify directory where `package-lock.json` or `yarn.lock` are located +2. Allow to specify path to the dependencies lock file (including directory path and filename) + +The second option looks more generic because it allows to: +- 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)) +- specify custom dependencies files like `src/npm-shrinkwrap.json` +- change default resolving priority if both `yarn.lock` and `package-lock.json` exist in repository + +## Decision + +Add `deps-lock-file` input that will accept path (relative to repository root) to dependencies lock file. +If path provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/packages.lock.json') }}` YAML construction does. +The hash of privided matched files will be used as a part of cache key. + +Yaml examples: +```yml +steps: +- uses: actions/checkout@v2 +- uses: actions/setup-node@v2 + with: + node-version: 14 + cache: npm + deps-lock-file: 'sub-project/package-lock.json' +``` +```yml +steps: +- uses: actions/checkout@v2 +- uses: actions/setup-node@v2 + with: + node-version: 14 + cache: yarn + deps-lock-file: 'sub-project/**/yarn.lock' +``` \ No newline at end of file From 5aa72c249a47160b814e62b58a7d20910c1cec29 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 13 Jul 2021 19:36:58 +0300 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Alena Sviridenko --- docs/adrs/0001-support-caching-deps-for-monorepos.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/adrs/0001-support-caching-deps-for-monorepos.md b/docs/adrs/0001-support-caching-deps-for-monorepos.md index 98167ec6..c1478643 100644 --- a/docs/adrs/0001-support-caching-deps-for-monorepos.md +++ b/docs/adrs/0001-support-caching-deps-for-monorepos.md @@ -8,7 +8,7 @@ Currently, `actions/setup-node` supports caching dependencies for Npm and Yarn p For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root. Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities) -Obviosly, it made build-in caching unusable for mono-repos and repos with complex structure. +Obviously, it made build-in caching unusable for mono-repos and repos with complex structure. We would like to revisit this decision and add customization for dependencies lock file location. ## Proposal @@ -24,8 +24,8 @@ The second option looks more generic because it allows to: ## Decision Add `deps-lock-file` input that will accept path (relative to repository root) to dependencies lock file. -If path provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/packages.lock.json') }}` YAML construction does. -The hash of privided matched files will be used as a part of cache key. +If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/packages.lock.json') }}` YAML construction does. +The hash of provided matched files will be used as a part of cache key. Yaml examples: ```yml @@ -45,4 +45,4 @@ steps: node-version: 14 cache: yarn deps-lock-file: 'sub-project/**/yarn.lock' -``` \ No newline at end of file +``` From 3c1fbef7d3e6be825fd4c4d2dc8fecd28d42df04 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 13 Jul 2021 20:35:24 +0300 Subject: [PATCH 3/4] Update 0001-support-caching-deps-for-monorepos.md --- docs/adrs/0001-support-caching-deps-for-monorepos.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/adrs/0001-support-caching-deps-for-monorepos.md b/docs/adrs/0001-support-caching-deps-for-monorepos.md index c1478643..923e1896 100644 --- a/docs/adrs/0001-support-caching-deps-for-monorepos.md +++ b/docs/adrs/0001-support-caching-deps-for-monorepos.md @@ -23,8 +23,8 @@ The second option looks more generic because it allows to: ## Decision -Add `deps-lock-file` input that will accept path (relative to repository root) to dependencies lock file. -If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/packages.lock.json') }}` YAML construction does. +Add `package-lock-file` input that will accept path (relative to repository root) to dependencies lock file. +If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does. The hash of provided matched files will be used as a part of cache key. Yaml examples: @@ -35,7 +35,7 @@ steps: with: node-version: 14 cache: npm - deps-lock-file: 'sub-project/package-lock.json' + package-lock-file: 'sub-project/package-lock.json' ``` ```yml steps: @@ -44,5 +44,5 @@ steps: with: node-version: 14 cache: yarn - deps-lock-file: 'sub-project/**/yarn.lock' + package-lock-file: 'sub-project/**/yarn.lock' ``` From f43d8a1f27404e4f3fe2c5c1832c5e4e066bad96 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Thu, 15 Jul 2021 13:23:09 +0300 Subject: [PATCH 4/4] Update 0001-support-caching-deps-for-monorepos.md --- docs/adrs/0001-support-caching-deps-for-monorepos.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/adrs/0001-support-caching-deps-for-monorepos.md b/docs/adrs/0001-support-caching-deps-for-monorepos.md index 923e1896..0677873d 100644 --- a/docs/adrs/0001-support-caching-deps-for-monorepos.md +++ b/docs/adrs/0001-support-caching-deps-for-monorepos.md @@ -23,7 +23,7 @@ The second option looks more generic because it allows to: ## Decision -Add `package-lock-file` input that will accept path (relative to repository root) to dependencies lock file. +Add `cache-dependency-path` input that will accept path (relative to repository root) to dependencies lock file. If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does. The hash of provided matched files will be used as a part of cache key. @@ -35,7 +35,7 @@ steps: with: node-version: 14 cache: npm - package-lock-file: 'sub-project/package-lock.json' + cache-dependency-path: 'sub-project/package-lock.json' ``` ```yml steps: @@ -44,5 +44,5 @@ steps: with: node-version: 14 cache: yarn - package-lock-file: 'sub-project/**/yarn.lock' + cache-dependency-path: 'sub-project/**/yarn.lock' ```