diff --git a/content/actions/guides/building-and-testing-nodejs.md b/content/actions/guides/building-and-testing-nodejs.md index 00687c244f..b9468163cb 100644 --- a/content/actions/guides/building-and-testing-nodejs.md +++ b/content/actions/guides/building-and-testing-nodejs.md @@ -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 "Caching dependencies to speed up workflows" 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 "Caching dependencies to speed up workflows". ## 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 diff --git a/content/actions/guides/caching-dependencies-to-speed-up-workflows.md b/content/actions/guides/caching-dependencies-to-speed-up-workflows.md index b929150d94..9000798ce5 100644 --- a/content/actions/guides/caching-dependencies-to-speed-up-workflows.md +++ b/content/actions/guides/caching-dependencies-to-speed-up-workflows.md @@ -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 %} diff --git a/content/actions/guides/deploying-to-azure-app-service.md b/content/actions/guides/deploying-to-azure-app-service.md index 594ddce9ef..1dbaaa282d 100644 --- a/content/actions/guides/deploying-to-azure-app-service.md +++ b/content/actions/guides/deploying-to-azure-app-service.md @@ -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 }} diff --git a/content/actions/guides/publishing-nodejs-packages.md b/content/actions/guides/publishing-nodejs-packages.md index aa1d25467a..ccd1ba7c33 100644 --- a/content/actions/guides/publishing-nodejs-packages.md +++ b/content/actions/guides/publishing-nodejs-packages.md @@ -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 diff --git a/content/actions/learn-github-actions/introduction-to-github-actions.md b/content/actions/learn-github-actions/introduction-to-github-actions.md index 0bdb1291a3..4615581d5f 100644 --- a/content/actions/learn-github-actions/introduction-to-github-actions.md +++ b/content/actions/learn-github-actions/introduction-to-github-actions.md @@ -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