mirror of
https://github.com/actions/setup-node.git
synced 2025-12-18 14:58:57 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c12f8017d |
17
.github/workflows/build-test.yml
vendored
17
.github/workflows/build-test.yml
vendored
@@ -3,14 +3,14 @@ name: build-test
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -18,13 +18,12 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node 16.x
|
- name: Setup node 12
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 12.x
|
||||||
cache: npm
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run format-check
|
- run: npm run format-check
|
||||||
- run: npm test
|
- run: npm test
|
||||||
11
.github/workflows/check-dist.yml
vendored
11
.github/workflows/check-dist.yml
vendored
@@ -21,13 +21,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node 16.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 12.x
|
||||||
cache: npm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@@ -45,7 +44,7 @@ jobs:
|
|||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
# If index.js was different than expected, upload the expected version as an artifact
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v2
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|||||||
12
.github/workflows/e2e-cache.yml
vendored
12
.github/workflows/e2e-cache.yml
vendored
@@ -10,7 +10,7 @@ on:
|
|||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
node-npm-depencies-caching:
|
node-npm-depencies-caching:
|
||||||
name: Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
name: Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [12, 14, 16]
|
node-version: [12, 14, 16]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Clean global cache
|
- name: Clean global cache
|
||||||
run: npm cache clean --force
|
run: npm cache clean --force
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [12, 14, 16]
|
node-version: [12, 14, 16]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v2
|
uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
@@ -75,9 +75,9 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [12, 14, 16]
|
node-version: [14, 16]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Yarn version
|
- name: Yarn version
|
||||||
run: yarn --version
|
run: yarn --version
|
||||||
- name: Generate yarn file
|
- name: Generate yarn file
|
||||||
@@ -109,7 +109,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [12, 14, 16]
|
node-version: [12, 14, 16]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Update yarn
|
- name: Update yarn
|
||||||
run: yarn set version berry
|
run: yarn set version berry
|
||||||
- name: Yarn version
|
- name: Yarn version
|
||||||
|
|||||||
4
.github/workflows/licensed.yml
vendored
4
.github/workflows/licensed.yml
vendored
@@ -13,12 +13,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check licenses
|
name: Check licenses
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Install licensed
|
- name: Install licensed
|
||||||
run: |
|
run: |
|
||||||
cd $RUNNER_TEMP
|
cd $RUNNER_TEMP
|
||||||
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.4.4/licensed-3.4.4-linux-x64.tar.gz
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz
|
||||||
sudo tar -xzf licensed.tar.gz
|
sudo tar -xzf licensed.tar.gz
|
||||||
sudo mv licensed /usr/local/bin/licensed
|
sudo mv licensed /usr/local/bin/licensed
|
||||||
- run: licensed status
|
- run: licensed status
|
||||||
|
|||||||
16
.github/workflows/proxy.yml
vendored
16
.github/workflows/proxy.yml
vendored
@@ -3,14 +3,14 @@ name: proxy
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-proxy:
|
test-proxy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -19,13 +19,13 @@ jobs:
|
|||||||
options: --dns 127.0.0.1
|
options: --dns 127.0.0.1
|
||||||
services:
|
services:
|
||||||
squid-proxy:
|
squid-proxy:
|
||||||
image: datadog/squid:latest
|
image: ubuntu/squid:latest
|
||||||
ports:
|
ports:
|
||||||
- 3128:3128
|
- 3128:3128
|
||||||
env:
|
env:
|
||||||
https_proxy: http://squid-proxy:3128
|
https_proxy: http://squid-proxy:3128
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Clear tool cache
|
- name: Clear tool cache
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
- name: Setup node 14
|
- name: Setup node 14
|
||||||
@@ -37,11 +37,13 @@ jobs:
|
|||||||
|
|
||||||
test-bypass-proxy:
|
test-bypass-proxy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
env:
|
env:
|
||||||
https_proxy: http://no-such-proxy:3128
|
https_proxy: http://no-such-proxy:3128
|
||||||
no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com
|
no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Clear tool cache
|
- name: Clear tool cache
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
- name: Setup node 11
|
- name: Setup node 11
|
||||||
|
|||||||
63
.github/workflows/versions.yml
vendored
63
.github/workflows/versions.yml
vendored
@@ -3,14 +3,14 @@ name: versions
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
local-cache:
|
local-cache:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [10, 12, 14]
|
node-version: [10, 12, 14]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -35,21 +35,13 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
|
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
check-latest: true
|
|
||||||
- if: runner.os != 'Windows'
|
|
||||||
name: Verify node and npm
|
|
||||||
run: |
|
|
||||||
. "$NVM_DIR/nvm.sh"
|
|
||||||
[[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]]
|
|
||||||
__tests__/verify-node.sh "${BASH_REMATCH[1]}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
manifest:
|
manifest:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -59,7 +51,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [10.15, 12.16.0, 14.2.0, 16.3.0]
|
node-version: [10.15, 12.16.0, 14.2.0, 16.3.0]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -76,7 +68,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [10, 12, 14]
|
node-version: [10, 12, 14]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node and check latest
|
- name: Setup Node and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -93,7 +85,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -109,7 +101,7 @@ jobs:
|
|||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
node-version: [11, 13]
|
node-version: [11, 13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node from dist
|
- name: Setup Node from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -125,7 +117,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
# test old versions which didn't have npm and layout different
|
# test old versions which didn't have npm and layout different
|
||||||
- name: Setup node 0.12.18 from dist
|
- name: Setup node 0.12.18 from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -138,7 +130,7 @@ jobs:
|
|||||||
arch:
|
arch:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup node 14 x86 from dist
|
- name: Setup node 14 x86 from dist
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -147,34 +139,3 @@ jobs:
|
|||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-arch.sh "ia32"
|
run: __tests__/verify-arch.sh "ia32"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
node-latest-aliases:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [current, latest, node]
|
|
||||||
steps:
|
|
||||||
- name: Get node version
|
|
||||||
run: |
|
|
||||||
latestNodeVersion=$(curl https://nodejs.org/dist/index.json | jq -r '. [0].version')
|
|
||||||
echo "::set-output name=LATEST_NODE_VERSION::$latestNodeVersion"
|
|
||||||
id: version
|
|
||||||
shell: bash
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup Node
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Retrieve version after install
|
|
||||||
run: |
|
|
||||||
updatedVersion=$(echo $(node --version))
|
|
||||||
echo "::set-output name=NODE_VERSION_UPDATED::$updatedVersion"
|
|
||||||
id: updatedVersion
|
|
||||||
shell: bash
|
|
||||||
- name: Compare versions
|
|
||||||
if: ${{ steps.version.outputs.LATEST_NODE_VERSION != steps.updatedVersion.outputs.NODE_VERSION_UPDATED}}
|
|
||||||
run: |
|
|
||||||
echo "Latest node version failed to download."
|
|
||||||
exit 1
|
|
||||||
|
|||||||
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/http-client-2.1.0.dep.yml
generated
Normal file
BIN
.licenses/npm/@actions/http-client-2.1.0.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@actions/io-1.1.2.dep.yml
generated
Normal file
BIN
.licenses/npm/@actions/io-1.1.2.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@actions/tool-cache.dep.yml
generated
BIN
.licenses/npm/@actions/tool-cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-asynciterator-polyfill.dep.yml
generated
BIN
.licenses/npm/@azure/core-asynciterator-polyfill.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-http.dep.yml
generated
BIN
.licenses/npm/@azure/core-http.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-lro.dep.yml
generated
BIN
.licenses/npm/@azure/core-lro.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-paging.dep.yml
generated
BIN
.licenses/npm/@azure/core-paging.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/storage-blob.dep.yml
generated
BIN
.licenses/npm/@azure/storage-blob.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@opentelemetry/api.dep.yml
generated
BIN
.licenses/npm/@opentelemetry/api.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/node.dep.yml
generated
BIN
.licenses/npm/@types/node.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/node-fetch.dep.yml
generated
BIN
.licenses/npm/node-fetch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/tr46.dep.yml
generated
BIN
.licenses/npm/tr46.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/uuid-3.3.2.dep.yml
generated
BIN
.licenses/npm/uuid-3.3.2.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/whatwg-url.dep.yml
generated
BIN
.licenses/npm/whatwg-url.dep.yml
generated
Binary file not shown.
@@ -1 +1 @@
|
|||||||
* @actions/actions-service
|
* @actions/spark
|
||||||
85
README.md
85
README.md
@@ -1,8 +1,8 @@
|
|||||||
# setup-node
|
# setup-node
|
||||||
|
|
||||||
[](https://github.com/actions/setup-node/actions/workflows/build-test.yml)
|
<p align="left">
|
||||||
[](https://github.com/actions/setup-node/actions/workflows/versions.yml)
|
<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>
|
||||||
[](https://github.com/actions/setup-node/actions/workflows/proxy.yml)
|
</p>
|
||||||
|
|
||||||
This action provides the following functionality for GitHub Actions users:
|
This action provides the following functionality for GitHub Actions users:
|
||||||
|
|
||||||
@@ -11,119 +11,104 @@ This action provides the following functionality for GitHub Actions users:
|
|||||||
- Registering problem matchers for error output
|
- Registering problem matchers for error output
|
||||||
- Configuring authentication for GPR or npm
|
- Configuring authentication for GPR or npm
|
||||||
|
|
||||||
## Usage
|
# Usage
|
||||||
|
|
||||||
See [action.yml](action.yml)
|
See [action.yml](action.yml)
|
||||||
|
|
||||||
**Basic:**
|
**Basic:**
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: '14'
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.
|
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.
|
||||||
|
|
||||||
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/).
|
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/).
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
### Supported version syntax
|
#### Supported version syntax
|
||||||
|
The `node-version` input supports the following syntax:
|
||||||
|
|
||||||
The `node-version` input supports the following values:
|
major versions: `12`, `14`, `16`
|
||||||
|
more specific versions: `10.15`, `14.2.0`, `16.3.0`
|
||||||
|
nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*`
|
||||||
|
|
||||||
- Major versions: `12`, `14`, `16`
|
## Caching packages dependencies
|
||||||
- More specific versions: `10.15`, `14.2.0`, `16.3.0`
|
|
||||||
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
|
|
||||||
- Latest release: `latest`/`current`/`node`
|
|
||||||
|
|
||||||
**Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist
|
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional, and caching is turned off by default.
|
||||||
|
|
||||||
### Checking in lockfiles
|
|
||||||
|
|
||||||
It's **always** recommended to commit the lockfile of your package manager for security and performance reasons. For more information consult the "Working with lockfiles" section of the [Advanced usage](docs/advanced-usage.md#working-with-lockfiles) guide.
|
|
||||||
|
|
||||||
## Caching global packages data
|
|
||||||
|
|
||||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional, and caching is turned off by default.
|
|
||||||
|
|
||||||
The action defaults to search for the dependency file (`package-lock.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories.
|
The action defaults to search for the dependency file (`package-lock.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories.
|
||||||
|
|
||||||
**Note:** The action does not cache `node_modules`
|
See the examples of using cache for `yarn` / `pnpm` and `cache-dependency-path` input in the [Advanced usage](docs/advanced-usage.md#caching-packages-dependencies) guide.
|
||||||
|
|
||||||
See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` input in the [Advanced usage](docs/advanced-usage.md#caching-packages-data) guide.
|
|
||||||
|
|
||||||
**Caching npm dependencies:**
|
**Caching npm dependencies:**
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
**Caching npm dependencies in monorepos:**
|
**Caching npm dependencies in monorepos:**
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: subdir/package-lock.json
|
cache-dependency-path: subdir/package-lock.json
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Matrix Testing
|
## Matrix Testing:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: [ 12, 14, 16 ]
|
node: [ '12', '14', '16' ]
|
||||||
name: Node ${{ matrix.node }} sample
|
name: Node ${{ matrix.node }} sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Advanced usage
|
## Advanced usage
|
||||||
|
|
||||||
1. [Check latest version](docs/advanced-usage.md#check-latest-version)
|
1. [Check latest version](docs/advanced-usage.md#check-latest-version)
|
||||||
2. [Using a node version file](docs/advanced-usage.md#node-version-file)
|
2. [Using a node version file](docs/advanced-usage.md#node-version-file)
|
||||||
3. [Using different architectures](docs/advanced-usage.md#architecture)
|
3. [Using different architectures](docs/advanced-usage.md#architecture)
|
||||||
4. [Caching packages data](docs/advanced-usage.md#caching-packages-data)
|
4. [Caching packages dependencies](docs/advanced-usage.md#caching-packages-dependencies)
|
||||||
5. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures)
|
5. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures)
|
||||||
6. [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
6. [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
||||||
7. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
7. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
||||||
8. [Using private packages](docs/advanced-usage.md#use-private-packages)
|
8. [Using private packages](docs/advanced-usage.md#use-private-packages)
|
||||||
|
|
||||||
## License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
|
||||||
## Contributions
|
# Contributions
|
||||||
|
|
||||||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md)
|
:wave: Be nice. See [our code of conduct](CONDUCT)
|
||||||
|
|||||||
@@ -1,28 +1,37 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as cache from '@actions/cache';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as utils from '../src/cache-utils';
|
import * as utils from '../src/cache-utils';
|
||||||
import {PackageManagerInfo, isCacheFeatureAvailable} from '../src/cache-utils';
|
import {PackageManagerInfo} from '../src/cache-utils';
|
||||||
|
|
||||||
describe('cache-utils', () => {
|
describe('cache-utils', () => {
|
||||||
|
const commonPath = '/some/random/path';
|
||||||
const versionYarn1 = '1.2.3';
|
const versionYarn1 = '1.2.3';
|
||||||
|
const versionYarn2 = '2.3.4';
|
||||||
|
|
||||||
let debugSpy: jest.SpyInstance;
|
let debugSpy: jest.SpyInstance;
|
||||||
let getCommandOutputSpy: jest.SpyInstance;
|
let getCommandOutputSpy: jest.SpyInstance;
|
||||||
let isFeatureAvailable: jest.SpyInstance;
|
|
||||||
let info: jest.SpyInstance;
|
function getPackagePath(name: string) {
|
||||||
let warningSpy: jest.SpyInstance;
|
if (name === utils.supportedPackageManagers.npm.getCacheFolderCommand) {
|
||||||
|
return `${commonPath}/npm`;
|
||||||
|
} else if (
|
||||||
|
name === utils.supportedPackageManagers.pnpm.getCacheFolderCommand
|
||||||
|
) {
|
||||||
|
return `${commonPath}/pnpm`;
|
||||||
|
} else {
|
||||||
|
if (name === utils.supportedPackageManagers.yarn1.getCacheFolderCommand) {
|
||||||
|
return `${commonPath}/yarn1`;
|
||||||
|
} else {
|
||||||
|
return `${commonPath}/yarn2`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||||
debugSpy = jest.spyOn(core, 'debug');
|
debugSpy = jest.spyOn(core, 'debug');
|
||||||
debugSpy.mockImplementation(msg => {});
|
debugSpy.mockImplementation(msg => {});
|
||||||
|
|
||||||
info = jest.spyOn(core, 'info');
|
|
||||||
warningSpy = jest.spyOn(core, 'warning');
|
|
||||||
|
|
||||||
isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
|
||||||
|
|
||||||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,32 +51,7 @@ describe('cache-utils', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isCacheFeatureAvailable for GHES is false', () => {
|
|
||||||
isFeatureAvailable.mockImplementation(() => false);
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
|
||||||
|
|
||||||
expect(() => isCacheFeatureAvailable()).toThrowError(
|
|
||||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isCacheFeatureAvailable for GHES has an interhal error', () => {
|
|
||||||
isFeatureAvailable.mockImplementation(() => false);
|
|
||||||
process.env['GITHUB_SERVER_URL'] = '';
|
|
||||||
isCacheFeatureAvailable();
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isCacheFeatureAvailable for GHES is available', () => {
|
|
||||||
isFeatureAvailable.mockImplementation(() => true);
|
|
||||||
|
|
||||||
expect(isCacheFeatureAvailable()).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env['GITHUB_SERVER_URL'] = '';
|
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,183 +1,157 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"version": "14.0.0",
|
"version": "14.0.0",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"lts": "Fermium",
|
"lts": "Fermium",
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200507.99",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200423.30",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-14.0.0-darwin-x64.tar.gz",
|
"filename": "node-14.0.0-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-14.0.0-linux-x64.tar.gz",
|
"filename": "node-14.0.0-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-14.0.0-win32-x64.7z",
|
"filename": "node-14.0.0-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"version": "13.13.0",
|
"version": "13.13.0",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200507.97",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200423.29",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-13.13.0-darwin-x64.tar.gz",
|
"filename": "node-13.13.0-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-13.13.0-linux-x64.tar.gz",
|
"filename": "node-13.13.0-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-13.13.0-win32-x64.7z",
|
"filename": "node-13.13.0-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"version": "12.16.2",
|
"version": "12.16.2",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"lts": "Erbium",
|
"lts": "Erbium",
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200507.95",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200423.28",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-12.16.2-darwin-x64.tar.gz",
|
"filename": "node-12.16.2-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-12.16.2-linux-x64.tar.gz",
|
"filename": "node-12.16.2-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-12.16.2-win32-x64.7z",
|
"filename": "node-12.16.2-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"version": "12.0.0",
|
"version": "10.20.1",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"lts": "Erbium",
|
"lts": "Dubnium",
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/12.0.0-20200507.71",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200423.27",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-12.0.0-darwin-x64.tar.gz",
|
"filename": "node-10.20.1-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-12.0.0-linux-x64.tar.gz",
|
"filename": "node-10.20.1-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-12.0.0-win32-x64.7z",
|
"filename": "node-10.20.1-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"version": "10.20.1",
|
"version": "8.17.0",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"lts": "Dubnium",
|
"lts": "Carbon",
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200507.70",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200423.26",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-10.20.1-darwin-x64.tar.gz",
|
"filename": "node-8.17.0-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-10.20.1-linux-x64.tar.gz",
|
"filename": "node-8.17.0-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-10.20.1-win32-x64.7z",
|
"filename": "node-8.17.0-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"version": "8.17.0",
|
"version": "6.17.1",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
"lts": "Carbon",
|
"lts": "Boron",
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200507.37",
|
"release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200423.25",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"filename": "node-8.17.0-darwin-x64.tar.gz",
|
"filename": "node-6.17.1-darwin-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "darwin",
|
"platform": "darwin",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-darwin-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-darwin-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-8.17.0-linux-x64.tar.gz",
|
"filename": "node-6.17.1-linux-x64.tar.gz",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-linux-x64.tar.gz"
|
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-linux-x64.tar.gz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "node-8.17.0-win32-x64.7z",
|
"filename": "node-6.17.1-win32-x64.zip",
|
||||||
"arch": "x64",
|
"arch": "x64",
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-win32-x64.7z"
|
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-win32-x64.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
{
|
]
|
||||||
"version": "6.17.1",
|
|
||||||
"stable": true,
|
|
||||||
"lts": "Boron",
|
|
||||||
"release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200529.2",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"filename": "node-6.17.1-darwin-x64.tar.gz",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "darwin",
|
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-darwin-x64.tar.gz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "node-6.17.1-linux-x64.tar.gz",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "linux",
|
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-linux-x64.tar.gz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "node-6.17.1-win32-x64.7z",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "win32",
|
|
||||||
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-win32-x64.7z"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -2,7 +2,6 @@ import * as core from '@actions/core';
|
|||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as im from '../src/installer';
|
import * as im from '../src/installer';
|
||||||
import * as cache from '@actions/cache';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import osm = require('os');
|
import osm = require('os');
|
||||||
@@ -37,7 +36,6 @@ describe('setup-node', () => {
|
|||||||
let execSpy: jest.SpyInstance;
|
let execSpy: jest.SpyInstance;
|
||||||
let authSpy: jest.SpyInstance;
|
let authSpy: jest.SpyInstance;
|
||||||
let parseNodeVersionSpy: jest.SpyInstance;
|
let parseNodeVersionSpy: jest.SpyInstance;
|
||||||
let isCacheActionAvailable: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// @actions/core
|
// @actions/core
|
||||||
@@ -69,9 +67,6 @@ describe('setup-node', () => {
|
|||||||
existsSpy = jest.spyOn(fs, 'existsSync');
|
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
||||||
|
|
||||||
// @actions/tool-cache
|
|
||||||
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
|
||||||
|
|
||||||
// disable authentication portion for installer tests
|
// disable authentication portion for installer tests
|
||||||
authSpy = jest.spyOn(auth, 'configAuthentication');
|
authSpy = jest.spyOn(auth, 'configAuthentication');
|
||||||
authSpy.mockImplementation(() => {});
|
authSpy.mockImplementation(() => {});
|
||||||
@@ -126,7 +121,7 @@ describe('setup-node', () => {
|
|||||||
'mocktoken'
|
'mocktoken'
|
||||||
);
|
);
|
||||||
expect(versions).toBeDefined();
|
expect(versions).toBeDefined();
|
||||||
expect(versions?.length).toBe(7);
|
expect(versions?.length).toBe(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can mock dist versions', async () => {
|
it('can mock dist versions', async () => {
|
||||||
@@ -135,28 +130,50 @@ describe('setup-node', () => {
|
|||||||
expect(versions?.length).toBe(23);
|
expect(versions?.length).toBe(23);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it('can find 12.16.2 from manifest on osx', async () => {
|
||||||
['12.16.2', 'darwin', '12.16.2', 'Erbium'],
|
os.platform = 'darwin';
|
||||||
['12', 'linux', '12.16.2', 'Erbium'],
|
os.arch = 'x64';
|
||||||
['10', 'win32', '10.20.1', 'Dubnium'],
|
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||||
['*', 'linux', '14.0.0', 'Fermium']
|
'actions',
|
||||||
])(
|
'node-versions',
|
||||||
'can find %s from manifest on %s',
|
'mocktoken'
|
||||||
async (versionSpec, platform, expectedVersion, expectedLts) => {
|
);
|
||||||
os.platform = platform;
|
expect(versions).toBeDefined();
|
||||||
os.arch = 'x64';
|
let match = await tc.findFromManifest('12.16.2', true, versions);
|
||||||
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
|
expect(match).toBeDefined();
|
||||||
'actions',
|
expect(match?.version).toBe('12.16.2');
|
||||||
'node-versions',
|
expect((match as any).lts).toBe('Erbium');
|
||||||
'mocktoken'
|
});
|
||||||
);
|
|
||||||
expect(versions).toBeDefined();
|
it('can find 12 from manifest on linux', async () => {
|
||||||
let match = await tc.findFromManifest(versionSpec, true, versions);
|
os.platform = 'linux';
|
||||||
expect(match).toBeDefined();
|
os.arch = 'x64';
|
||||||
expect(match?.version).toBe(expectedVersion);
|
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||||
expect((match as any).lts).toBe(expectedLts);
|
'actions',
|
||||||
}
|
'node-versions',
|
||||||
);
|
'mocktoken'
|
||||||
|
);
|
||||||
|
expect(versions).toBeDefined();
|
||||||
|
let match = await tc.findFromManifest('12.16.2', true, versions);
|
||||||
|
expect(match).toBeDefined();
|
||||||
|
expect(match?.version).toBe('12.16.2');
|
||||||
|
expect((match as any).lts).toBe('Erbium');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can find 10 from manifest on windows', async () => {
|
||||||
|
os.platform = 'win32';
|
||||||
|
os.arch = 'x64';
|
||||||
|
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
|
||||||
|
'actions',
|
||||||
|
'node-versions',
|
||||||
|
'mocktoken'
|
||||||
|
);
|
||||||
|
expect(versions).toBeDefined();
|
||||||
|
let match = await tc.findFromManifest('10', true, versions);
|
||||||
|
expect(match).toBeDefined();
|
||||||
|
expect(match?.version).toBe('10.20.1');
|
||||||
|
expect((match as any).lts).toBe('Dubnium');
|
||||||
|
});
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// Found in cache tests
|
// Found in cache tests
|
||||||
@@ -228,7 +245,7 @@ describe('setup-node', () => {
|
|||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
let expectedUrl =
|
let expectedUrl =
|
||||||
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz';
|
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
@@ -266,7 +283,7 @@ describe('setup-node', () => {
|
|||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
let expectedUrl =
|
let expectedUrl =
|
||||||
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz';
|
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
@@ -351,6 +368,7 @@ describe('setup-node', () => {
|
|||||||
inputs['node-version'] = version;
|
inputs['node-version'] = version;
|
||||||
inputs['architecture'] = arch;
|
inputs['architecture'] = arch;
|
||||||
inputs['always-auth'] = false;
|
inputs['always-auth'] = false;
|
||||||
|
inputs['cache'] = '';
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
let expectedUrl =
|
let expectedUrl =
|
||||||
@@ -435,7 +453,7 @@ describe('setup-node', () => {
|
|||||||
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
const expectedUrl =
|
const expectedUrl =
|
||||||
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz';
|
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
@@ -627,49 +645,6 @@ describe('setup-node', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('cache on GHES', () => {
|
|
||||||
it('Should throw an error, because cache is not supported', async () => {
|
|
||||||
inputs['node-version'] = '12';
|
|
||||||
inputs['cache'] = 'npm';
|
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
|
|
||||||
let toolPath = path.normalize('/cache/node/12.16.1/x64');
|
|
||||||
findSpy.mockImplementation(() => toolPath);
|
|
||||||
|
|
||||||
// expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
|
||||||
isCacheActionAvailable.mockImplementation(() => false);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
|
||||||
`::error::Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.${osm.EOL}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should throw an internal error', async () => {
|
|
||||||
inputs['node-version'] = '12';
|
|
||||||
inputs['cache'] = 'npm';
|
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
|
|
||||||
let toolPath = path.normalize('/cache/node/12.16.1/x64');
|
|
||||||
findSpy.mockImplementation(() => toolPath);
|
|
||||||
|
|
||||||
// expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
|
||||||
process.env['GITHUB_SERVER_URL'] = '';
|
|
||||||
isCacheActionAvailable.mockImplementation(() => false);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('LTS version', () => {
|
describe('LTS version', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
@@ -677,102 +652,145 @@ describe('setup-node', () => {
|
|||||||
inputs.stable = 'true';
|
inputs.stable = 'true';
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it('find latest LTS version and resolve it from local cache (lts/erbium)', async () => {
|
||||||
['erbium', '12.16.2'],
|
// arrange
|
||||||
['*', '14.0.0'],
|
inputs['node-version'] = 'lts/erbium';
|
||||||
['-1', '12.16.2']
|
|
||||||
])(
|
|
||||||
'find latest LTS version and resolve it from local cache (lts/%s)',
|
|
||||||
async (lts, expectedVersion) => {
|
|
||||||
// arrange
|
|
||||||
inputs['node-version'] = `lts/${lts}`;
|
|
||||||
|
|
||||||
const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
|
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
||||||
findSpy.mockReturnValue(toolPath);
|
findSpy.mockReturnValue(toolPath);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
'Attempt to resolve LTS alias from manifest...'
|
'Attempt to resolve LTS alias from manifest...'
|
||||||
);
|
);
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
'Getting manifest from actions/node-versions@main'
|
'Getting manifest from actions/node-versions@main'
|
||||||
);
|
);
|
||||||
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
`LTS alias '${lts}' for Node version 'lts/${lts}'`
|
`LTS alias 'erbium' for Node version 'lts/erbium'`
|
||||||
);
|
);
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
`Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'`
|
`Found LTS release '12.16.2' for Node version 'lts/erbium'`
|
||||||
);
|
);
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
it.each([
|
it('find latest LTS version and install it from manifest (lts/erbium)', async () => {
|
||||||
[
|
// arrange
|
||||||
'erbium',
|
inputs['node-version'] = 'lts/erbium';
|
||||||
'12.16.2',
|
|
||||||
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'*',
|
|
||||||
'14.0.0',
|
|
||||||
'https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-linux-x64.tar.gz'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'-1',
|
|
||||||
'12.16.2',
|
|
||||||
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'
|
|
||||||
]
|
|
||||||
])(
|
|
||||||
'find latest LTS version and install it from manifest (lts/%s)',
|
|
||||||
async (lts, expectedVersion, expectedUrl) => {
|
|
||||||
// arrange
|
|
||||||
inputs['node-version'] = `lts/${lts}`;
|
|
||||||
|
|
||||||
const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
|
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
const expectedMajor = expectedVersion.split('.')[0];
|
const expectedUrl =
|
||||||
|
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
|
||||||
|
|
||||||
// act
|
// act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
'Attempt to resolve LTS alias from manifest...'
|
'Attempt to resolve LTS alias from manifest...'
|
||||||
);
|
);
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
'Getting manifest from actions/node-versions@main'
|
'Getting manifest from actions/node-versions@main'
|
||||||
);
|
);
|
||||||
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
`LTS alias '${lts}' for Node version 'lts/${lts}'`
|
`LTS alias 'erbium' for Node version 'lts/erbium'`
|
||||||
);
|
);
|
||||||
expect(dbgSpy).toHaveBeenCalledWith(
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
`Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'`
|
`Found LTS release '12.16.2' for Node version 'lts/erbium'`
|
||||||
);
|
);
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 12...');
|
||||||
`Attempting to download ${expectedMajor}...`
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
);
|
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
);
|
||||||
`Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}`
|
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
||||||
);
|
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
||||||
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
);
|
||||||
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
});
|
||||||
);
|
|
||||||
}
|
it('find latest LTS version and resolve it from local cache (lts/*)', async () => {
|
||||||
);
|
// arrange
|
||||||
|
inputs['node-version'] = 'lts/*';
|
||||||
|
|
||||||
|
const toolPath = path.normalize('/cache/node/14.0.0/x64');
|
||||||
|
findSpy.mockReturnValue(toolPath);
|
||||||
|
|
||||||
|
// act
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Attempt to resolve LTS alias from manifest...'
|
||||||
|
);
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
'Getting manifest from actions/node-versions@main'
|
||||||
|
);
|
||||||
|
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
`LTS alias '*' for Node version 'lts/*'`
|
||||||
|
);
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
`Found LTS release '14.0.0' for Node version 'lts/*'`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
|
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('find latest LTS version and install it from manifest (lts/*)', async () => {
|
||||||
|
// arrange
|
||||||
|
inputs['node-version'] = 'lts/*';
|
||||||
|
|
||||||
|
const toolPath = path.normalize('/cache/node/14.0.0/x64');
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
const expectedUrl =
|
||||||
|
'https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz';
|
||||||
|
|
||||||
|
// act
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Attempt to resolve LTS alias from manifest...'
|
||||||
|
);
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
'Getting manifest from actions/node-versions@main'
|
||||||
|
);
|
||||||
|
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
`LTS alias '*' for Node version 'lts/*'`
|
||||||
|
);
|
||||||
|
expect(dbgSpy).toHaveBeenCalledWith(
|
||||||
|
`Found LTS release '14.0.0' for Node version 'lts/*'`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 14...');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Acquiring 14.0.0 - ${os.arch} from ${expectedUrl}`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
|
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('fail with unable to parse LTS alias (lts/)', async () => {
|
it('fail with unable to parse LTS alias (lts/)', async () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -844,57 +862,4 @@ describe('setup-node', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('latest alias syntax', () => {
|
|
||||||
it.each(['latest', 'current', 'node'])(
|
|
||||||
'download the %s version if alias is provided',
|
|
||||||
async inputVersion => {
|
|
||||||
// Arrange
|
|
||||||
inputs['node-version'] = inputVersion;
|
|
||||||
|
|
||||||
os.platform = 'darwin';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
getManifestSpy.mockImplementation(() => {
|
|
||||||
throw new Error('Unable to download manifest');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// assert
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Unable to download manifest');
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('latest alias syntax from cache', () => {
|
|
||||||
it.each(['latest', 'current', 'node'])(
|
|
||||||
'download the %s version if alias is provided',
|
|
||||||
async inputVersion => {
|
|
||||||
// Arrange
|
|
||||||
inputs['node-version'] = inputVersion;
|
|
||||||
const expectedVersion = nodeTestDist[0];
|
|
||||||
|
|
||||||
os.platform = 'darwin';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
const toolPath = path.normalize(
|
|
||||||
`/cache/node/${expectedVersion.version}/x64`
|
|
||||||
);
|
|
||||||
findSpy.mockReturnValue(toolPath);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// assert
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
26
action.yml
26
action.yml
@@ -1,37 +1,41 @@
|
|||||||
name: 'Setup Node.js environment'
|
name: 'Setup Node.js environment'
|
||||||
description: 'Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH.'
|
description: 'Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH'
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
always-auth:
|
always-auth:
|
||||||
description: 'Set always-auth in npmrc.'
|
description: 'Set always-auth in npmrc'
|
||||||
default: 'false'
|
default: 'false'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
|
||||||
node-version-file:
|
node-version-file:
|
||||||
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version.'
|
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version'
|
||||||
architecture:
|
architecture:
|
||||||
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
check-latest:
|
check-latest:
|
||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
|
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||||
default: false
|
default: false
|
||||||
registry-url:
|
registry-url:
|
||||||
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.'
|
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN'
|
||||||
scope:
|
scope:
|
||||||
description: 'Optional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).'
|
description: 'Optional scope for authenticating against scoped registries'
|
||||||
token:
|
token:
|
||||||
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
|
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
cache:
|
cache:
|
||||||
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
|
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm'
|
||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
|
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
|
||||||
# TODO: add input to control forcing to pull from cloud or dist.
|
# TODO: add input to control forcing to pull from cloud or dist.
|
||||||
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
|
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
|
||||||
|
# Deprecated option, do not use. Will not be supported after October 1, 2019
|
||||||
|
version:
|
||||||
|
description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019'
|
||||||
|
deprecationMessage: 'The version property will not be supported after October 1, 2019. Use node-version instead'
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit.'
|
description: 'A boolean value to indicate if a cache was hit'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node12'
|
||||||
main: 'dist/setup/index.js'
|
main: 'dist/setup/index.js'
|
||||||
post: 'dist/cache-save/index.js'
|
post: 'dist/cache-save/index.js'
|
||||||
post-if: success()
|
post-if: success()
|
||||||
54908
dist/cache-save/index.js
vendored
54908
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
77371
dist/setup/index.js
vendored
77371
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,39 +1,4 @@
|
|||||||
## Working with lockfiles
|
# Advanced usage
|
||||||
|
|
||||||
All supported package managers recommend that you **always** commit the lockfile, although implementations vary doing so generally provides the following benefits:
|
|
||||||
|
|
||||||
- Enables faster installation for CI and production environments, due to being able to skip package resolution.
|
|
||||||
- Describes a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.
|
|
||||||
- Provides a facility for users to "time-travel" to previous states of `node_modules` without having to commit the directory itself.
|
|
||||||
- Facilitates greater visibility of tree changes through readable source control diffs.
|
|
||||||
|
|
||||||
In order to get the most out of using your lockfile on continuous integration follow the conventions outlined below for your respective package manager.
|
|
||||||
|
|
||||||
### NPM
|
|
||||||
|
|
||||||
Ensure that `package-lock.json` is always committed, use `npm ci` instead of `npm install` when installing packages.
|
|
||||||
|
|
||||||
**See also:**
|
|
||||||
- [Documentation of `package-lock.json`](https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json)
|
|
||||||
- [Documentation of `npm ci`](https://docs.npmjs.com/cli/v8/commands/npm-ci)
|
|
||||||
|
|
||||||
### Yarn
|
|
||||||
|
|
||||||
To ensure that `yarn.lock` is always committed, use `yarn install --immutable` when installing packages.
|
|
||||||
|
|
||||||
**See also:**
|
|
||||||
- [Documentation of `yarn.lock`](https://classic.yarnpkg.com/en/docs/yarn-lock)
|
|
||||||
- [Documentation of `--frozen-lockfile` option](https://classic.yarnpkg.com/en/docs/cli/install#toc-yarn-install-frozen-lockfile)
|
|
||||||
- [QA - Should lockfiles be committed to the repoistory?](https://yarnpkg.com/getting-started/qa/#should-lockfiles-be-committed-to-the-repository)
|
|
||||||
- [Documentation of `yarn install`](https://yarnpkg.com/cli/install)
|
|
||||||
|
|
||||||
### PNPM
|
|
||||||
|
|
||||||
Ensure that `pnpm-lock.yaml` is always committed, when on CI pass `--frozen-lockfile` to `pnpm install` when installing packages.
|
|
||||||
|
|
||||||
**See also:**
|
|
||||||
- [Working with Git - Lockfiles](https://pnpm.io/git#lockfiles)
|
|
||||||
- [Documentation of `--frozen-lockfile` option](https://pnpm.io/cli/install#--frozen-lockfile)
|
|
||||||
|
|
||||||
## Check latest version
|
## Check latest version
|
||||||
|
|
||||||
@@ -45,28 +10,28 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Node version file
|
## Node version file
|
||||||
|
|
||||||
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
||||||
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
|
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
|
||||||
> The action will search for the node version file relative to the repository root.
|
> The action will search for the node version file relative to the repository root.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -81,28 +46,28 @@ jobs:
|
|||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Caching packages data
|
## Caching packages dependencies
|
||||||
The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions.
|
The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions.
|
||||||
|
|
||||||
**Caching yarn dependencies:**
|
**Caching yarn dependencies:**
|
||||||
Yarn caching handles both yarn versions: 1 or 2.
|
Yarn caching handles both yarn versions: 1 or 2.
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
- run: yarn install --frozen-lockfile # optional, --immutable
|
- run: yarn install
|
||||||
- run: yarn test
|
- run: yarn test
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -116,43 +81,43 @@ steps:
|
|||||||
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
|
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: pnpm/action-setup@v2
|
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
|
||||||
with:
|
with:
|
||||||
version: 6.32.9
|
version: 6.10.0
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'pnpm'
|
cache: 'pnpm'
|
||||||
- run: pnpm install --frozen-lockfile
|
- run: pnpm install
|
||||||
- run: pnpm test
|
- run: pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
**Using wildcard patterns to cache dependencies**
|
**Using wildcard patterns to cache dependencies**
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: '**/package-lock.json'
|
cache-dependency-path: '**/package-lock.json'
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
**Using a list of file paths to cache dependencies**
|
**Using a list of file paths to cache dependencies**
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: |
|
cache-dependency-path: |
|
||||||
server/app/package-lock.json
|
server/app/package-lock.json
|
||||||
frontend/app/package-lock.json
|
frontend/app/package-lock.json
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -181,29 +146,29 @@ jobs:
|
|||||||
architecture: x86
|
architecture: x86
|
||||||
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
|
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node_version }}
|
node-version: ${{ matrix.node_version }}
|
||||||
architecture: ${{ matrix.architecture }}
|
architecture: ${{ matrix.architecture }}
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Publish to npmjs and GPR with npm
|
## Publish to npmjs and GPR with npm
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
- run: npm ci
|
- run: npm install
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
@@ -214,16 +179,16 @@ steps:
|
|||||||
## Publish to npmjs and GPR with yarn
|
## Publish to npmjs and GPR with yarn
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: <registry url>
|
registry-url: <registry url>
|
||||||
- run: yarn install --frozen-lockfile
|
- run: yarn install
|
||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
@@ -234,14 +199,14 @@ steps:
|
|||||||
## Use private packages
|
## Use private packages
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
# Skip post-install scripts here, as a malicious
|
# Skip post-install scripts here, as a malicious
|
||||||
# script could steal NODE_AUTH_TOKEN.
|
# script could steal NODE_AUTH_TOKEN.
|
||||||
- run: npm ci --ignore-scripts
|
- run: npm install --ignore-scripts
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
# `npm rebuild` will run all those post-install scripts for us.
|
# `npm rebuild` will run all those post-install scripts for us.
|
||||||
|
|||||||
5258
package-lock.json
generated
5258
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "3.1.1",
|
"version": "2.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup node action",
|
"description": "setup node action",
|
||||||
"main": "lib/setup-node.js",
|
"main": "lib/setup-node.js",
|
||||||
@@ -23,21 +23,21 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^2.0.2",
|
"@actions/cache": "^1.0.8",
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.0",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/glob": "^0.2.0",
|
"@actions/glob": "^0.2.0",
|
||||||
"@actions/http-client": "^1.0.11",
|
"@actions/http-client": "^1.0.11",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.5.4",
|
"@actions/tool-cache": "^1.7.2",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
"@types/node": "^16.11.25",
|
"@types/node": "^12.0.4",
|
||||||
"@types/semver": "^6.0.0",
|
"@types/semver": "^6.0.0",
|
||||||
"@vercel/ncc": "^0.33.4",
|
"@zeit/ncc": "^0.21.0",
|
||||||
"jest": "^27.2.5",
|
"jest": "^27.2.5",
|
||||||
"jest-circus": "^27.2.5",
|
"jest-circus": "^27.2.5",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as cache from '@actions/cache';
|
|
||||||
|
|
||||||
type SupportedPackageManagers = {
|
type SupportedPackageManagers = {
|
||||||
[prop: string]: PackageManagerInfo;
|
[prop: string]: PackageManagerInfo;
|
||||||
@@ -96,28 +95,3 @@ export const getCacheDirectoryPath = async (
|
|||||||
|
|
||||||
return stdOut;
|
return stdOut;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isGhes(): boolean {
|
|
||||||
const ghUrl = new URL(
|
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
||||||
);
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isCacheFeatureAvailable(): boolean {
|
|
||||||
if (!cache.isFeatureAvailable()) {
|
|
||||||
if (isGhes()) {
|
|
||||||
throw new Error(
|
|
||||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
core.warning(
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export async function getNode(
|
|||||||
) {
|
) {
|
||||||
// Store manifest data to avoid multiple calls
|
// Store manifest data to avoid multiple calls
|
||||||
let manifest: INodeRelease[] | undefined;
|
let manifest: INodeRelease[] | undefined;
|
||||||
let nodeVersions: INodeVersion[] | undefined;
|
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = translateArchToDistUrl(arch);
|
let osArch: string = translateArchToDistUrl(arch);
|
||||||
|
|
||||||
@@ -50,12 +49,6 @@ export async function getNode(
|
|||||||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLatestSyntax(versionSpec)) {
|
|
||||||
nodeVersions = await getVersionsFromDist();
|
|
||||||
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
|
|
||||||
core.info(`getting latest node version...`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkLatest) {
|
if (checkLatest) {
|
||||||
core.info('Attempt to resolve the latest version from manifest...');
|
core.info('Attempt to resolve the latest version from manifest...');
|
||||||
const resolvedVersion = await resolveVersionFromManifest(
|
const resolvedVersion = await resolveVersionFromManifest(
|
||||||
@@ -126,7 +119,7 @@ export async function getNode(
|
|||||||
// Download from nodejs.org
|
// Download from nodejs.org
|
||||||
//
|
//
|
||||||
if (!downloadPath) {
|
if (!downloadPath) {
|
||||||
info = await getInfoFromDist(versionSpec, arch, nodeVersions);
|
info = await getInfoFromDist(versionSpec, arch);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
||||||
@@ -223,21 +216,13 @@ function resolveLtsAliasFromManifest(
|
|||||||
|
|
||||||
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
|
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
|
||||||
|
|
||||||
// Supported formats are `lts/<alias>`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest.
|
// Supported formats are `lts/<alias>` and `lts/*`. Where asterisk means highest possible LTS.
|
||||||
const n = Number(alias);
|
|
||||||
const aliases = Object.fromEntries(
|
|
||||||
manifest
|
|
||||||
.filter(x => x.lts && x.stable === stable)
|
|
||||||
.map(x => [x.lts!.toLowerCase(), x])
|
|
||||||
.reverse()
|
|
||||||
);
|
|
||||||
const numbered = Object.values(aliases);
|
|
||||||
const release =
|
const release =
|
||||||
alias === '*'
|
alias === '*'
|
||||||
? numbered[numbered.length - 1]
|
? manifest.find(x => !!x.lts && x.stable === stable)
|
||||||
: n < 0
|
: manifest.find(
|
||||||
? numbered[numbered.length - 1 + n]
|
x => x.lts?.toLowerCase() === alias && x.stable === stable
|
||||||
: aliases[alias];
|
);
|
||||||
|
|
||||||
if (!release) {
|
if (!release) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -280,18 +265,14 @@ async function getInfoFromManifest(
|
|||||||
|
|
||||||
async function getInfoFromDist(
|
async function getInfoFromDist(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string = os.arch(),
|
arch: string = os.arch()
|
||||||
nodeVersions?: INodeVersion[]
|
|
||||||
): Promise<INodeVersionInfo | null> {
|
): Promise<INodeVersionInfo | null> {
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = translateArchToDistUrl(arch);
|
let osArch: string = translateArchToDistUrl(arch);
|
||||||
|
|
||||||
let version: string = await queryDistForMatch(
|
let version: string;
|
||||||
versionSpec,
|
|
||||||
arch,
|
|
||||||
nodeVersions
|
|
||||||
);
|
|
||||||
|
|
||||||
|
version = await queryDistForMatch(versionSpec, arch);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -368,8 +349,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
|||||||
|
|
||||||
async function queryDistForMatch(
|
async function queryDistForMatch(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string = os.arch(),
|
arch: string = os.arch()
|
||||||
nodeVersions?: INodeVersion[]
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = translateArchToDistUrl(arch);
|
let osArch: string = translateArchToDistUrl(arch);
|
||||||
@@ -390,17 +370,8 @@ async function queryDistForMatch(
|
|||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeVersions) {
|
|
||||||
core.debug('No dist manifest cached');
|
|
||||||
nodeVersions = await getVersionsFromDist();
|
|
||||||
}
|
|
||||||
|
|
||||||
let versions: string[] = [];
|
let versions: string[] = [];
|
||||||
|
let nodeVersions = await getVersionsFromDist();
|
||||||
if (isLatestSyntax(versionSpec)) {
|
|
||||||
core.info(`getting latest node version...`);
|
|
||||||
return nodeVersions[0].version;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
||||||
// ensure this version supports your os and platform
|
// ensure this version supports your os and platform
|
||||||
@@ -502,7 +473,3 @@ export function parseNodeVersionFile(contents: string): string {
|
|||||||
}
|
}
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLatestSyntax(versionSpec): boolean {
|
|
||||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
|
||||||
}
|
|
||||||
|
|||||||
16
src/main.ts
16
src/main.ts
@@ -4,7 +4,7 @@ import fs from 'fs';
|
|||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
import {URL} from 'url';
|
||||||
import os = require('os');
|
import os = require('os');
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@@ -45,7 +45,10 @@ export async function run() {
|
|||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache) {
|
||||||
|
if (isGhes()) {
|
||||||
|
throw new Error('Caching is not supported on GHES');
|
||||||
|
}
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
await restoreCache(cache, cacheDependencyPath);
|
await restoreCache(cache, cacheDependencyPath);
|
||||||
}
|
}
|
||||||
@@ -63,8 +66,15 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isGhes(): boolean {
|
||||||
|
const ghUrl = new URL(
|
||||||
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
|
);
|
||||||
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||||
|
}
|
||||||
|
|
||||||
function resolveVersionInput(): string {
|
function resolveVersionInput(): string {
|
||||||
let version = core.getInput('node-version');
|
let version = core.getInput('node-version') || core.getInput('version');
|
||||||
const versionFileInput = core.getInput('node-version-file');
|
const versionFileInput = core.getInput('node-version-file');
|
||||||
|
|
||||||
if (version && versionFileInput) {
|
if (version && versionFileInput) {
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user