You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This action sets by node environment for use in actions by:
7
+
This action provides the following functionality for GitHub Actions runners:
8
8
9
-
- optionally downloading and caching a version of node - npm by version spec and add to PATH
10
-
- registering problem matchers for error output
11
-
- configuring authentication for GPR or npm
9
+
- Optionally downloading and caching distribution of the requested Node.js version, and adding it to the PATH
10
+
- Optionally caching npm/yarn dependencies
11
+
- Registering problem matchers for error output
12
+
- Configuring authentication for GPR or npm
12
13
13
-
# v2
14
+
# Usage
14
15
15
-
This release adds reliability for pulling node distributions from a cache of node releases.
16
+
See [action.yml](action.yml)
16
17
18
+
**Basic:**
17
19
```yaml
18
20
steps:
19
21
- uses: actions/checkout@v2
20
22
- uses: actions/setup-node@v2
21
23
with:
22
24
node-version: '14'
25
+
- run: npm install
26
+
- run: npm test
23
27
```
24
28
25
-
The action will first check the local cache for a semver match. The hosted images have been updated with the latest of each LTS from v8, v10, v12, and v14. `self-hosted` machines will benefit from the cache as well only downloading once. The action will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/).
29
+
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, this action will still register problem matchers and support auth features. So setting up the node environment is still a valid scenario without downloading and caching versions.
26
30
27
-
The `node-version` input is optional. If not supplied, the node version that is PATH will be used. However, this action will still register problem matchers and support auth features. So setting up the node environment is still a valid scenario without downloading and caching versions.
31
+
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/).
28
32
29
-
# Usage
33
+
For information regarding locally cached versions of Node.js on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments).
30
34
31
-
See [action.yml](action.yml)
35
+
### Caching packages dependencies
36
+
37
+
The action has a built-in functionality for caching and restoring npm/yarn dependencies. Supported package managers are `npm`, `yarn`. The `cache` input is optional, and caching is turned off by default.
32
38
33
-
Basic:
34
39
```yaml
35
40
steps:
36
41
- uses: actions/checkout@v2
37
42
- uses: actions/setup-node@v2
38
43
with:
39
44
node-version: '14'
45
+
cache: 'npm'
40
46
- run: npm install
41
47
- run: npm test
42
48
```
43
49
44
-
Check latest version:
45
-
46
-
In the basic example above, the `check-latest` flag defaults to `false`. When set to `false`, the action tries to first resolve a version of node from the local cache. For information regarding locally cached versions of Node on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). The local version of Node in cache gets updated every couple of weeks. If unable to find a specific version in the cache, the action will then attempt to download a version of Node. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node is always used.
47
-
48
-
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a version of Node will then be downloaded. Set `check-latest` to `true` it you want the most up-to-date version of Node to always be used.
49
-
50
-
> Setting `check-latest` to `true` has performance implications as downloading versions of Node is slower than using cached versions
51
-
50
+
**Caching yarn dependencies:**
52
51
```yaml
53
52
steps:
54
53
- uses: actions/checkout@v2
55
54
- uses: actions/setup-node@v2
56
55
with:
57
56
node-version: '14'
58
-
check-latest: true
57
+
cache: 'yarn'
59
58
- run: npm install
60
59
- run: npm test
61
60
```
61
+
Yarn caching handles both yarn versions: 1 or 2.
62
62
63
-
Matrix Testing:
63
+
> At the moment, only `lock` files in the project root are supported.
64
+
65
+
### Matrix Testing:
64
66
```yaml
65
67
jobs:
66
68
build:
67
-
runs-on: ubuntu-16.04
69
+
runs-on: ubuntu-latest
68
70
strategy:
69
71
matrix:
70
72
node: [ '12', '14' ]
@@ -78,119 +80,14 @@ jobs:
78
80
- run: npm install
79
81
- run: npm test
80
82
```
81
-
82
-
Architecture:
83
-
84
-
You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
85
-
86
-
When using `architecture`, `node-version` must be provided as well.
87
-
```yaml
88
-
jobs:
89
-
build:
90
-
runs-on: windows-latest
91
-
name: Node sample
92
-
steps:
93
-
- uses: actions/checkout@v2
94
-
- uses: actions/setup-node@v2
95
-
with:
96
-
node-version: '14'
97
-
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
The `check-latest` flag defaults to `false`. When set to `false`, the action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/). Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node.js is always used.
6
+
7
+
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a version of Node.js will then be downloaded. Set `check-latest` to `true` it you want the most up-to-date version of Node.js to always be used.
8
+
9
+
> Setting `check-latest` to `true` has performance implications as downloading versions of Node is slower than using cached versions.
10
+
11
+
```yaml
12
+
steps:
13
+
- uses: actions/checkout@v2
14
+
- uses: actions/setup-node@v2
15
+
with:
16
+
node-version: '14'
17
+
check-latest: true
18
+
- run: npm install
19
+
- run: npm test
20
+
```
21
+
22
+
### Architecture:
23
+
24
+
You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
25
+
26
+
When using `architecture`, `node-version` must be provided as well.
27
+
```yaml
28
+
jobs:
29
+
build:
30
+
runs-on: windows-latest
31
+
name: Node sample
32
+
steps:
33
+
- uses: actions/checkout@v2
34
+
- uses: actions/setup-node@v2
35
+
with:
36
+
node-version: '14'
37
+
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
0 commit comments