1
0
mirror of synced 2025-12-20 02:19:14 -05:00

Update setup-node docs in accordance with new cache functionality (#20214)

This commit is contained in:
MaksimZhukov
2021-07-01 16:14:54 +03:00
committed by GitHub
parent d4e2cce848
commit af158bc17d
12 changed files with 53 additions and 44 deletions

View File

@@ -92,7 +92,7 @@ strategy:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
``` ```
@@ -122,7 +122,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- run: npm ci - run: npm ci
@@ -150,7 +150,7 @@ This example installs the dependencies defined in the *package.json* file. For m
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- name: Install dependencies - name: Install dependencies
@@ -164,7 +164,7 @@ Using `npm ci` installs the versions in the *package-lock.json* or *npm-shrinkwr
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- name: Install dependencies - name: Install dependencies
@@ -180,7 +180,7 @@ This example installs the dependencies defined in the *package.json* file. For m
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- name: Install dependencies - name: Install dependencies
@@ -193,7 +193,7 @@ Alternatively, you can pass `--frozen-lockfile` to install the versions in the *
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- name: Install dependencies - name: Install dependencies
@@ -215,7 +215,7 @@ Before installing dependencies, use the `setup-node` action to create the *.npmr
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
always-auth: true always-auth: true
node-version: '12.x' node-version: '12.x'
@@ -238,29 +238,34 @@ always-auth=true
### Example caching dependencies ### 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} ```yaml{:copy}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - uses: actions/setup-node@v2
uses: actions/setup-node@v1
with: with:
node-version: '12.x' node-version: '14'
- name: Cache Node.js modules cache: 'npm'
uses: actions/cache@v2 - run: npm install
with: - run: npm test
# 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
``` ```
{% 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 ## 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: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- run: npm install - run: npm install

View File

@@ -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. 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 %} {% warning %}

View File

@@ -93,7 +93,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ env.NODE_VERSION }} - name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}

View File

@@ -219,7 +219,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
# Setup .npmrc file to publish to npm # Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
node-version: '10.x' node-version: '10.x'
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'
@@ -229,7 +229,7 @@ jobs:
env:{% raw %} env:{% raw %}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Setup .npmrc file to publish to GitHub Packages # Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
registry-url: 'https://npm.pkg.github.com' registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file # Defaults to the user or organization that owns the workflow file

View File

@@ -76,7 +76,7 @@ You can create an example workflow in your repository that automatically trigger
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
- run: npm install -g bats - run: npm install -g bats
- run: bats -v - run: bats -v
``` ```
@@ -170,7 +170,7 @@ To help you understand how YAML syntax is used to create a workflow file, this s
<td> <td>
```yaml ```yaml
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
``` ```
</td> </td>
<td> <td>

View File

@@ -80,7 +80,7 @@ jobs:
matrix: matrix:
node: [6, 8, 10] node: [6, 8, 10]
steps: steps:
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
``` ```

View File

@@ -280,8 +280,8 @@ jobs:
matrix: matrix:
os: [macos-latest, ubuntu-latest] os: [macos-latest, ubuntu-latest]
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
node-version: 12 node-version: 12
- run: npm install -g bats - run: npm install -g bats

View File

@@ -410,7 +410,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: '12.x' node-version: '12.x'
- run: npm install - run: npm install

View File

@@ -625,9 +625,9 @@ steps:
# Reference a specific commit # Reference a specific commit
- uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e - uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e
# Reference the major version of a release # Reference the major version of a release
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
# Reference a minor version of a release # Reference a specific version
- uses: actions/setup-node@v1.2 - uses: actions/setup-node@v2.2.0
# Reference a branch # Reference a branch
- uses: actions/setup-node@main - uses: actions/setup-node@main
``` ```

View File

@@ -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" mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
mkdir -p "${{ runner.tool_cache }}" mkdir -p "${{ runner.tool_cache }}"
- name: Setup Node 10 - name: Setup Node 10
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: 10.x node-version: 10.x
- name: Setup Node 12 - name: Setup Node 12
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: 12.x node-version: 12.x
- name: Archive tool cache - name: Archive tool cache

View File

@@ -123,7 +123,7 @@ jobs:
steps: {% raw %} steps: {% raw %}
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node-version }}{% endraw %} node-version: ${{ matrix.node-version }}{% endraw %}
- uses: actions/download-artifact@main - uses: actions/download-artifact@main
@@ -251,7 +251,7 @@ run-npm-test:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- uses: actions/download-artifact@main - uses: actions/download-artifact@main

View File

@@ -63,7 +63,7 @@ In this guide, you'll create a {% data variables.product.prodname_actions %} wor
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
node-version: 12 node-version: 12
- run: npm ci - run: npm ci
@@ -77,7 +77,7 @@ In this guide, you'll create a {% data variables.product.prodname_actions %} wor
contents: read{% endif %} contents: read{% endif %}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with: with:
node-version: 12 node-version: 12
registry-url: {% ifversion ghae %}https://npm.YOUR-HOSTNAME.com/{% else %}https://npm.pkg.github.com/{% endif %} registry-url: {% ifversion ghae %}https://npm.YOUR-HOSTNAME.com/{% else %}https://npm.pkg.github.com/{% endif %}