Skip to content

Commit f2b87bb

Browse files
Squashed commit of the following:
commit 446068a Author: Alena Sviridenko <alenasviridenko@github.com> Date: Tue Jun 22 17:51:35 2021 +0300 updated headers commit d7e254e Author: Alena Sviridenko <alenasviridenko@github.com> Date: Thu Jun 17 17:35:34 2021 +0300 updated links commit ffd9956 Author: AlyonaSviridenko <alenasviridenko@github.com> Date: Thu Jun 17 17:33:41 2021 +0300 Added advanced usage commit 1e068f0 Author: AlyonaSviridenko <alenasviridenko@github.com> Date: Thu Jun 17 15:07:42 2021 +0300 Updated readme with caching commit 7528c33 Author: Maxim Lobanov <v-malob@microsoft.com> Date: Wed Jun 16 14:43:46 2021 +0300 Update versions.yml
1 parent 1088324 commit f2b87bb

File tree

3 files changed

+165
-136
lines changed

3 files changed

+165
-136
lines changed

.github/workflows/versions.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- '**.md'
77
push:
88
branches:
9-
- main
9+
- main
1010
- releases/*
1111
paths-ignore:
1212
- '**.md'

README.md

+32-135
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,69 @@
44
<a href="https://github.com/actions/setup-node/actions?query=workflow%3Abuild-test"><img alt="build-test status" src="https://github.com/actions/setup-node/workflows/build-test/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aversions"><img alt="versions status" src="https://github.com/actions/setup-node/workflows/versions/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aproxy"><img alt="proxy status" src="https://github.com/actions/setup-node/workflows/proxy/badge.svg"></a>
55
</p>
66

7-
This action sets by node environment for use in actions by:
7+
This action provides the following functionality for GitHub Actions runners:
88

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
1213

13-
# v2
14+
# Usage
1415

15-
This release adds reliability for pulling node distributions from a cache of node releases.
16+
See [action.yml](action.yml)
1617

18+
**Basic:**
1719
```yaml
1820
steps:
1921
- uses: actions/checkout@v2
2022
- uses: actions/setup-node@v2
2123
with:
2224
node-version: '14'
25+
- run: npm install
26+
- run: npm test
2327
```
2428
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.
2630

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/).
2832

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).
3034

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.
3238

33-
Basic:
3439
```yaml
3540
steps:
3641
- uses: actions/checkout@v2
3742
- uses: actions/setup-node@v2
3843
with:
3944
node-version: '14'
45+
cache: 'npm'
4046
- run: npm install
4147
- run: npm test
4248
```
4349

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:**
5251
```yaml
5352
steps:
5453
- uses: actions/checkout@v2
5554
- uses: actions/setup-node@v2
5655
with:
5756
node-version: '14'
58-
check-latest: true
57+
cache: 'yarn'
5958
- run: npm install
6059
- run: npm test
6160
```
61+
Yarn caching handles both yarn versions: 1 or 2.
6262

63-
Matrix Testing:
63+
> At the moment, only `lock` files in the project root are supported.
64+
65+
### Matrix Testing:
6466
```yaml
6567
jobs:
6668
build:
67-
runs-on: ubuntu-16.04
69+
runs-on: ubuntu-latest
6870
strategy:
6971
matrix:
7072
node: [ '12', '14' ]
@@ -78,119 +80,14 @@ jobs:
7880
- run: npm install
7981
- run: npm test
8082
```
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
98-
- run: npm install
99-
- run: npm test
100-
```
101-
102-
Multiple Operating Systems and Architectures:
103-
104-
```yaml
105-
jobs:
106-
build:
107-
runs-on: ${{ matrix.os }}
108-
strategy:
109-
matrix:
110-
os:
111-
- ubuntu-latest
112-
- macos-latest
113-
- windows-latest
114-
node_version:
115-
- 10
116-
- 12
117-
- 14
118-
architecture:
119-
- x64
120-
# an extra windows-x86 run:
121-
include:
122-
- os: windows-2016
123-
node_version: 12
124-
architecture: x86
125-
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
126-
steps:
127-
- uses: actions/checkout@v2
128-
- name: Setup node
129-
uses: actions/setup-node@v2
130-
with:
131-
node-version: ${{ matrix.node_version }}
132-
architecture: ${{ matrix.architecture }}
133-
- run: npm install
134-
- run: npm test
135-
```
136-
137-
Publish to npmjs and GPR with npm:
138-
```yaml
139-
steps:
140-
- uses: actions/checkout@v2
141-
- uses: actions/setup-node@v2
142-
with:
143-
node-version: '10.x'
144-
registry-url: 'https://registry.npmjs.org'
145-
- run: npm install
146-
- run: npm publish
147-
env:
148-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
149-
- uses: actions/setup-node@v2
150-
with:
151-
registry-url: 'https://npm.pkg.github.com'
152-
- run: npm publish
153-
env:
154-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155-
```
156-
157-
Publish to npmjs and GPR with yarn:
158-
```yaml
159-
steps:
160-
- uses: actions/checkout@v2
161-
- uses: actions/setup-node@v2
162-
with:
163-
node-version: '10.x'
164-
registry-url: <registry url>
165-
- run: yarn install
166-
- run: yarn publish
167-
env:
168-
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
169-
- uses: actions/setup-node@v2
170-
with:
171-
registry-url: 'https://npm.pkg.github.com'
172-
- run: yarn publish
173-
env:
174-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175-
```
176-
177-
Use private packages:
178-
```yaml
179-
steps:
180-
- uses: actions/checkout@v2
181-
- uses: actions/setup-node@v2
182-
with:
183-
node-version: '10.x'
184-
registry-url: 'https://registry.npmjs.org'
185-
# Skip post-install scripts here, as a malicious
186-
# script could steal NODE_AUTH_TOKEN.
187-
- run: npm install --ignore-scripts
188-
env:
189-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
190-
# `npm rebuild` will run all those post-install scripts for us.
191-
- run: npm rebuild && npm run prepare --if-present
192-
```
193-
83+
## Advanced usage
84+
85+
1. [Check latest version](docs/advanced-usage.md#check-latest-version)
86+
2. [Using different architectures](docs/advanced-usage.md#architecture)
87+
3. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures)
88+
4. [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
89+
5. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
90+
6. [Using private packages](docs/advanced-usage.md#use-private-packages)
19491

19592
# License
19693

docs/advanced-usage.md

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Advanced usage
2+
3+
### Check latest version:
4+
5+
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
38+
- run: npm install
39+
- run: npm test
40+
```
41+
42+
### Multiple Operating Systems and Architectures:
43+
44+
```yaml
45+
jobs:
46+
build:
47+
runs-on: ${{ matrix.os }}
48+
strategy:
49+
matrix:
50+
os:
51+
- ubuntu-latest
52+
- macos-latest
53+
- windows-latest
54+
node_version:
55+
- 10
56+
- 12
57+
- 14
58+
architecture:
59+
- x64
60+
# an extra windows-x86 run:
61+
include:
62+
- os: windows-2016
63+
node_version: 12
64+
architecture: x86
65+
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
66+
steps:
67+
- uses: actions/checkout@v2
68+
- name: Setup node
69+
uses: actions/setup-node@v2
70+
with:
71+
node-version: ${{ matrix.node_version }}
72+
architecture: ${{ matrix.architecture }}
73+
- run: npm install
74+
- run: npm test
75+
```
76+
77+
### Publish to npmjs and GPR with npm:
78+
```yaml
79+
steps:
80+
- uses: actions/checkout@v2
81+
- uses: actions/setup-node@v2
82+
with:
83+
node-version: '14.x'
84+
registry-url: 'https://registry.npmjs.org'
85+
- run: npm install
86+
- run: npm publish
87+
env:
88+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
89+
- uses: actions/setup-node@v2
90+
with:
91+
registry-url: 'https://npm.pkg.github.com'
92+
- run: npm publish
93+
env:
94+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
```
96+
97+
### Publish to npmjs and GPR with yarn:
98+
```yaml
99+
steps:
100+
- uses: actions/checkout@v2
101+
- uses: actions/setup-node@v2
102+
with:
103+
node-version: '14.x'
104+
registry-url: <registry url>
105+
- run: yarn install
106+
- run: yarn publish
107+
env:
108+
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
109+
- uses: actions/setup-node@v2
110+
with:
111+
registry-url: 'https://npm.pkg.github.com'
112+
- run: yarn publish
113+
env:
114+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
```
116+
117+
### Use private packages:
118+
```yaml
119+
steps:
120+
- uses: actions/checkout@v2
121+
- uses: actions/setup-node@v2
122+
with:
123+
node-version: '14.x'
124+
registry-url: 'https://registry.npmjs.org'
125+
# Skip post-install scripts here, as a malicious
126+
# script could steal NODE_AUTH_TOKEN.
127+
- run: npm install --ignore-scripts
128+
env:
129+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
130+
# `npm rebuild` will run all those post-install scripts for us.
131+
- run: npm rebuild && npm run prepare --if-present
132+
```

0 commit comments

Comments
 (0)