Skip to content

Commit e79375d

Browse files
Merge pull request #266 from actions/malob/cache-adr
Create ADR for integrating cache functionality to setup-node action
2 parents 5c355be + 5929471 commit e79375d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
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+
- More users will use cache for Node.js so more customers will have fast builds!
15+
16+
We will add support for NPM and Yarn dependencies caching.
17+
As the first stage, we won't support custom locations for `package-lock.json`, `yarn.lock` files and action will work only when files are located in repository root.
18+
19+
We don't pursue 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.
20+
21+
# Decision
22+
- Add `cache` input parameter to `actions/setup-node`. For now, input will accept the following values:
23+
- `npm` - enable caching for npm dependencies
24+
- `yarn` - enable caching for yarn dependencies
25+
- `''` - disable caching (default value)
26+
- 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`)
27+
- 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+
- The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) recommends)
29+
- The following key cache will be used `${{ runner.os }}-npm-${{ hashFiles('<package-lock-path>') }}`
30+
- Action will cache global cache:
31+
- Npm (retrieved via `npm config get cache`)
32+
- Yarn 1 (retrieved via `yarn cache dir`)
33+
- Yarn 2 (retrieved via `yarn config get cacheFolder`)
34+
35+
# Example of real use-cases
36+
Npm package manager:
37+
```yml
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-node@v2
41+
with:
42+
node-version: '14'
43+
cache: npm
44+
```
45+
46+
Yarn package manager:
47+
```yml
48+
steps:
49+
- uses: actions/checkout@v2
50+
- uses: actions/setup-node@v2
51+
with:
52+
node-version: '14'
53+
cache: yarn
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)