Skip to content

Commit 24265e1

Browse files
author
Maxim Lobanov
committed
Create 0000-caching-dependencies.md
1 parent 5c355be commit 24265e1

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 0. Caching dependencies
2+
Date: 2021-05-21
3+
4+
Status: Proposed
5+
6+
# Context
7+
`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.
8+
See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#node---npm).
9+
10+
# Goals & Anti-Goals
11+
Integration of caching functionality into `actions/setup-node` action will bring the following benefits for action users:
12+
- Decrease the entry threshold for using the cache for Node.js dependencies and simplify initial configuration
13+
- Simplify YAML pipelines because no need additional steps to enable caching
14+
15+
As a result, more users will use the cache for Node.js builds and will be happy with fast builds.
16+
As the first stage, we will add support for NPM dependencies caching. We can consider adding the same functionality for Yarn later.
17+
18+
We don't persue the goal to provide wide customization of caching in scope of `actions/setup-node` action. The purpose of this integration is covering ~90% of basic use-cases. If user needs flexible customization, we should advice them to use `actions/cache` directly.
19+
20+
# Decision
21+
- Add `cache` input parameter to `actions/setup-node`. For now, input will accept the following values:
22+
- `npm` - enable caching for npm dependencies
23+
- `''` - disable caching (default value)
24+
- Potentially, we will be able to extend this input to support Yarn
25+
- Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major release (`v3`)
26+
- Add optional input `package-lock-path` that will allow to specify path to `package.lock.json` file path:
27+
- If input is not defined, action will try to search `package.lock.json` or `yarn.lock` (npm 7.x supports `yarn.lock` files) files in the repository root and throw error if no one is found
28+
- If input contains file path, action will use the specified file
29+
- If input contains folder path, action will try to search `package.lock.json` file in the specified folder
30+
- if input contains wildcards (like `**/package-lock.json`), hash of multiple files will be used
31+
- The hash of file provided in `package-lock-path` input will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) recommends)
32+
- The following key cache will be used `${{ runner.os }}-npm-${{ hashFiles('<package-lock-path>') }}`
33+
34+
# Example of real use-cases
35+
Default use case when `package.lock.json` or `yarn.lock` are located in repository root:
36+
```yml
37+
steps:
38+
- uses: actions/checkout@v2
39+
- uses: actions/setup-node@v2
40+
with:
41+
node-version: '14'
42+
cache: npm
43+
```
44+
45+
More flexible solution for monorepos:
46+
```yml
47+
steps:
48+
- uses: actions/checkout@v2
49+
- uses: actions/setup-node@v2
50+
with:
51+
node-version: '14'
52+
cache: npm
53+
package-lock-path: service1/yarn.lock
54+
```
55+
56+
# Release process
57+
58+
As soon as functionality is implemented, we will release minor update of action. No need to bump major version since there are no breaking changes for existing users.
59+
After that, we will update [starter-workflows](https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml) and [GitHub Action documentation](https://docs.github.com/en/actions/guides/building-and-testing-nodejs#example-caching-dependencies).

0 commit comments

Comments
 (0)