setup-node/docs/adrs/0000-caching-dependencies.md

60 lines
3.1 KiB
Markdown
Raw Normal View History

2021-05-21 18:16:14 +03:00
# 0. Caching dependencies
Date: 2021-05-21
Status: Proposed
# 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.
See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#node---npm).
# Goals & Anti-Goals
Integration of caching functionality into `actions/setup-node` action will bring the following benefits for action users:
- Decrease the entry threshold for using the cache for Node.js dependencies and simplify initial configuration
- Simplify YAML pipelines because no need additional steps to enable caching
2021-05-21 18:28:06 +03:00
- More users will use cache for Node.js so more customers will have fast builds!
2021-05-21 18:16:14 +03:00
2021-06-02 15:52:17 +03:00
We will add support for NPM and Yarn dependencies caching.
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.
2021-05-21 18:16:14 +03:00
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.
2021-05-21 18:16:14 +03:00
# Decision
- Add `cache` input parameter to `actions/setup-node`. For now, input will accept the following values:
- `npm` - enable caching for npm dependencies
2021-06-02 15:52:17 +03:00
- `yarn` - enable caching for yarn dependencies
2021-05-21 18:16:14 +03:00
- `''` - disable caching (default value)
- 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`)
2021-06-02 15:52:17 +03:00
- 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
- 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)
2021-05-21 18:16:14 +03:00
- The following key cache will be used `${{ runner.os }}-npm-${{ hashFiles('<package-lock-path>') }}`
2021-06-02 15:52:17 +03:00
- Action will cache global cache:
- Npm (retrieved via `npm config get cache`)
- Yarn 1 (retrieved via `yarn cache dir`)
- Yarn 2 (retrieved via `yarn config get cacheFolder`)
2021-05-21 18:16:14 +03:00
# Example of real use-cases
2021-06-02 15:52:17 +03:00
Npm package manager:
2021-05-21 18:16:14 +03:00
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: npm
```
2021-06-02 15:52:17 +03:00
Yarn package manager:
2021-05-21 18:16:14 +03:00
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
2021-06-02 15:52:17 +03:00
cache: yarn
2021-05-21 18:16:14 +03:00
```
# Release process
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.
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).