Difference between revisions of "Uses: actions/setup-node"

From wikieduonline
Jump to navigation Jump to search
Line 21: Line 21:
  
 
== Official example ==
 
== Official example ==
<pre>
 
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
 
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
 
 
name: Node.js CI
 
 
on:
 
  push:
 
    branches: [ "main" ]
 
  pull_request:
 
    branches: [ "main" ]
 
  
jobs:
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests
  build:
+
across different versions of node
 +
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
 +
 +
name: Node.js CI
 +
 +
on:
 +
  push:
 +
    branches: [ "main" ]
 +
  pull_request:
 +
    branches: [ "main" ]
 +
 +
jobs:
 +
  build:
 +
 +
    runs-on: ubuntu-latest
  
    runs-on: ubuntu-latest
+
    strategy:
 
+
      matrix:
    strategy:
+
        [[node-version]]: [14.x, 16.x, 18.x]
      matrix:
 
        node-version: [14.x, 16.x, 18.x]
 
 
         # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
 
         # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
 
+
<pre>
 
     steps:
 
     steps:
 
     - uses: actions/checkout@v3
 
     - uses: actions/checkout@v3
Line 54: Line 55:
 
     - run: npm test
 
     - run: npm test
 
</pre>
 
</pre>
 
  
 
== Related ==
 
== Related ==

Revision as of 14:56, 19 July 2023

https://github.com/actions/setup-node

  • Optionally downloading and caching distribution of the requested Node.js version, and adding it to the PATH
  • Optionally caching npm/yarn/pnpm dependencies
  • Registering problem matchers for error output
  • Configuring authentication for GPR or npm
actions/setup[email protected]


Run actions/setup-node@v3
Found in cache @ /opt/hostedtoolcache/node/14.21.3/x64
Environment details
  node: v14.21.3
  npm: 6.14.18
  yarn: 1.22.19
/opt/hostedtoolcache/node/14.21.3/x64/bin/npm config get cache
/home/runner/.npm
npm cache is not found


Official example

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests 
across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest 
    strategy:
      matrix:
        node-version: [14.x, 16.x, 18.x]
       # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test

Related

See also

Advertising: