Update setup-node docs in accordance with new cache functionality (#20214)
This commit is contained in:
@@ -92,7 +92,7 @@ strategy:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
```
|
||||
@@ -122,7 +122,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- run: npm ci
|
||||
@@ -150,7 +150,7 @@ This example installs the dependencies defined in the *package.json* file. For m
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- name: Install dependencies
|
||||
@@ -164,7 +164,7 @@ Using `npm ci` installs the versions in the *package-lock.json* or *npm-shrinkwr
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- name: Install dependencies
|
||||
@@ -180,7 +180,7 @@ This example installs the dependencies defined in the *package.json* file. For m
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- name: Install dependencies
|
||||
@@ -193,7 +193,7 @@ Alternatively, you can pass `--frozen-lockfile` to install the versions in the *
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- name: Install dependencies
|
||||
@@ -215,7 +215,7 @@ Before installing dependencies, use the `setup-node` action to create the *.npmr
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
always-auth: true
|
||||
node-version: '12.x'
|
||||
@@ -238,29 +238,34 @@ always-auth=true
|
||||
|
||||
### Example caching dependencies
|
||||
|
||||
When using {% data variables.product.prodname_dotcom %}-hosted runners, you can cache dependencies using a unique key, and restore the dependencies when you run future workflows using the `cache` action. For more information, see "<a href="/actions/guides/caching-dependencies-to-speed-up-workflows" class="dotcom-only">Caching dependencies to speed up workflows</a>" and the [`cache` action](https://github.com/marketplace/actions/cache).
|
||||
When using {% data variables.product.prodname_dotcom %}-hosted runners, you can cache and restore the dependencies using the [`setup-node` action](https://github.com/actions/setup-node).
|
||||
|
||||
{% raw %}
|
||||
The following example caches dependencies for npm.
|
||||
```yaml{:copy}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- name: Cache Node.js modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.OS }}-node-
|
||||
${{ runner.OS }}-
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
node-version: '14'
|
||||
cache: 'npm'
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
The following example caches dependencies for Yarn.
|
||||
|
||||
```yaml{:copy}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
cache: 'yarn'
|
||||
- run: yarn
|
||||
- run: yarn test
|
||||
```
|
||||
|
||||
To cache dependencies, you must have a `package-lock.json` or `yarn.lock` file in the root of the repository. If you need more flexible customization, you can use the [`cache` action](https://github.com/marketplace/actions/cache). For more information, see "<a href="/actions/guides/caching-dependencies-to-speed-up-workflows" class="dotcom-only">Caching dependencies to speed up workflows</a>".
|
||||
|
||||
## Building and testing your code
|
||||
|
||||
@@ -270,7 +275,7 @@ You can use the same commands that you use locally to build and test your code.
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- run: npm install
|
||||
|
||||
@@ -22,7 +22,11 @@ Workflow runs often reuse the same outputs or downloaded dependencies from one r
|
||||
|
||||
Jobs on {% data variables.product.prodname_dotcom %}-hosted runners start in a clean virtual environment and must download dependencies each time, causing increased network utilization, longer runtime, and increased cost. To help speed up the time it takes to recreate these files, {% data variables.product.prodname_dotcom %} can cache dependencies you frequently use in workflows.
|
||||
|
||||
To cache dependencies for a job, you'll need to use {% data variables.product.prodname_dotcom %}'s `cache` action. The action retrieves a cache identified by a unique key. For more information, see [`actions/cache`](https://github.com/actions/cache). If you are caching Ruby gems, instead consider using the Ruby maintained action, which can cache bundle installs on initiation. For more information, see [`ruby/setup-ruby`](https://github.com/ruby/setup-ruby#caching-bundle-install-automatically).
|
||||
To cache dependencies for a job, you'll need to use {% data variables.product.prodname_dotcom %}'s `cache` action. The action retrieves a cache identified by a unique key. For more information, see [`actions/cache`](https://github.com/actions/cache).
|
||||
|
||||
If you are caching Ruby gems, instead consider using the Ruby maintained action, which can cache bundle installs on initiation. For more information, see [`ruby/setup-ruby`](https://github.com/ruby/setup-ruby#caching-bundle-install-automatically).
|
||||
|
||||
To cache and restore dependencies for npm or Yarn, you can use the [`actions/setup-node` action](https://github.com/actions/setup-node).
|
||||
|
||||
{% warning %}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
# Setup .npmrc file to publish to npm
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '10.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
@@ -229,7 +229,7 @@ jobs:
|
||||
env:{% raw %}
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
# Setup .npmrc file to publish to GitHub Packages
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
registry-url: 'https://npm.pkg.github.com'
|
||||
# Defaults to the user or organization that owns the workflow file
|
||||
|
||||
@@ -76,7 +76,7 @@ You can create an example workflow in your repository that automatically trigger
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
- run: npm install -g bats
|
||||
- run: bats -v
|
||||
```
|
||||
@@ -170,7 +170,7 @@ To help you understand how YAML syntax is used to create a workflow file, this s
|
||||
<td>
|
||||
|
||||
```yaml
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
```
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -80,7 +80,7 @@ jobs:
|
||||
matrix:
|
||||
node: [6, 8, 10]
|
||||
steps:
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
```
|
||||
|
||||
@@ -280,8 +280,8 @@ jobs:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
- run: npm install -g bats
|
||||
|
||||
@@ -410,7 +410,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12.x'
|
||||
- run: npm install
|
||||
|
||||
@@ -625,9 +625,9 @@ steps:
|
||||
# Reference a specific commit
|
||||
- uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e
|
||||
# Reference the major version of a release
|
||||
- uses: actions/setup-node@v1
|
||||
# Reference a minor version of a release
|
||||
- uses: actions/setup-node@v1.2
|
||||
- uses: actions/setup-node@v2
|
||||
# Reference a specific version
|
||||
- uses: actions/setup-node@v2.2.0
|
||||
# Reference a branch
|
||||
- uses: actions/setup-node@main
|
||||
```
|
||||
|
||||
@@ -57,11 +57,11 @@ You can populate the runner tool cache by running a {% data variables.product.pr
|
||||
mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
|
||||
mkdir -p "${{ runner.tool_cache }}"
|
||||
- name: Setup Node 10
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 10.x
|
||||
- name: Setup Node 12
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12.x
|
||||
- name: Archive tool cache
|
||||
|
||||
@@ -123,7 +123,7 @@ jobs:
|
||||
steps: {% raw %}
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}{% endraw %}
|
||||
- uses: actions/download-artifact@main
|
||||
@@ -251,7 +251,7 @@ run-npm-test:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- uses: actions/download-artifact@main
|
||||
|
||||
@@ -63,7 +63,7 @@ In this guide, you'll create a {% data variables.product.prodname_actions %} wor
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
- run: npm ci
|
||||
@@ -77,7 +77,7 @@ In this guide, you'll create a {% data variables.product.prodname_actions %} wor
|
||||
contents: read{% endif %}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
registry-url: {% ifversion ghae %}https://npm.YOUR-HOSTNAME.com/{% else %}https://npm.pkg.github.com/{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user