Merge remote-tracking branch 'origin/ethomson/update_description'

This commit is contained in:
precha1989 2023-06-10 02:20:00 +07:00
parent 869f4dd0c7
commit 856dafaeaf
13 changed files with 24606 additions and 10385 deletions

32
.github/workflows/build-test.yml vendored Normal file
View file

@ -0,0 +1,32 @@
name: build-test
on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- master
- releases/*
paths-ignore:
- '**.md'
jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm test
- name: Verify no unstaged changes
if: runner.os != 'windows'
run: __tests__/verify-no-unstaged-changes.sh

View file

@ -3,45 +3,49 @@ name: proxy
on:
pull_request:
paths-ignore:
- '**.md'
push:
- '**.md'
push:
branches:
- main
- master
- releases/*
paths-ignore:
- '**.md'
jobs:
test-proxy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
container:
image: ubuntu:latest
options: --dns 127.0.0.1
services:
squid-proxy:
image: ubuntu/squid:latest
image: datadog/squid:latest
ports:
- 3128:3128
env:
https_proxy: http://squid-proxy:3128
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup node 14
- name: Setup node 10
uses: ./
with:
node-version: 14.x
node-version: 10.x
- name: Verify node and npm
run: __tests__/verify-node.sh 14
run: __tests__/verify-node.sh 10
test-bypass-proxy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
env:
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
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup node 11

View file

@ -3,263 +3,45 @@ name: versions
on:
pull_request:
paths-ignore:
- '**.md'
push:
- '**.md'
push:
branches:
- main
- master
- releases/*
paths-ignore:
- '**.md'
jobs:
local-cache:
runs-on: ${{ matrix.os }}
versions:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10, 12, 14]
operating-system: [ubuntu-latest, windows-latest]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Setup Node
- uses: actions/checkout@v2
# test version that falls through to node dist
- name: Setup node 11 from dist
uses: ./
with:
node-version: ${{ matrix.node-version }}
node-version: 11
- name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash
lts-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
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
v8-canary-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version:
[
'20-v8-canary',
'20.0.0-v8-canary',
'20.0.0-v8-canary20221101e50e45c9f8'
]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: |
canaryVersion="${{ matrix.node-version }}"
majorVersion=$(echo $canaryVersion | cut -d- -f1)
__tests__/verify-node.sh "$majorVersion"
shell: bash
nightly-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version:
[16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: |
nightlyVersion="${{ matrix.node-version }}"
majorVersion=$(echo $nightlyVersion | cut -d- -f1)
__tests__/verify-node.sh "$majorVersion"
shell: bash
rc-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [16.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: |
rcVersion="${{ matrix.node-version }}"
majorVersion=$(echo $rcVersion | cut -d- -f1)
__tests__/verify-node.sh "$majorVersion"
shell: bash
manifest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.15, 12.16.0, 14.2.0, 16.3.0]
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash
check-latest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10, 12, 14]
steps:
- uses: actions/checkout@v3
- name: Setup Node and check latest
uses: ./
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash
version-file:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version-file: [.nvmrc, .tool-versions, package.json]
steps:
- uses: actions/checkout@v3
- name: Remove volta from package.json
shell: bash
run: cat <<< "$(jq 'del(.volta)' ./__tests__/data/package.json)" > ./__tests__/data/package.json
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
- name: Verify node
run: __tests__/verify-node.sh 14
version-file-volta:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/package.json'
- name: Verify node
run: __tests__/verify-node.sh 16
node-dist:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [11, 13]
steps:
- uses: actions/checkout@v3
- name: Setup Node from dist
uses: ./
with:
node-version: ${{ matrix.node-version }}
- name: Verify node and npm
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash
old-versions:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
# test old versions which didn't have npm and layout different
run: __tests__/verify-node.sh 11
# test old versions which didn't have npm and layout different
- name: Setup node 0.12.18 from dist
uses: ./
uses: ./
with:
node-version: 0.12.18
- name: Verify node
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
shell: bash
arch:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup node 14 x86 from dist
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
# test version from node manifest
- name: Setup node 12.16.2 from manifest
uses: ./
with:
node-version: '14'
architecture: 'x86'
- name: Verify node
run: __tests__/verify-arch.sh "ia32"
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 "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT
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 "NODE_VERSION_UPDATED=$updatedVersion" >> $GITHUB_OUTPUT
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
node-version: 12.16.2
- name: Verify node and npm
run: __tests__/verify-node.sh 12

View file

@ -1,4 +1,4 @@
import os from 'os';
import os = require('os');
import * as fs from 'fs';
import * as path from 'path';
import * as core from '@actions/core';
@ -15,9 +15,11 @@ describe('authutil tests', () => {
let dbgSpy: jest.SpyInstance;
beforeAll(async () => {
const randPath = path.join(Math.random().toString(36).substring(7));
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
const randPath = path.join(
Math.random()
.toString(36)
.substring(7)
);
const tempDir = path.join(_runnerDir, randPath, 'temp');
await io.rmRF(tempDir);
await io.mkdirP(tempDir);
@ -59,14 +61,13 @@ describe('authutil tests', () => {
if (_runnerDir) {
await io.rmRF(_runnerDir);
}
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
}, 100000);
function readRcFile(rcFile: string) {
const rc = {};
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
let rc = {};
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
for (const line of contents.split(os.EOL)) {
const parts = line.split('=');
let parts = line.split('=');
if (parts.length == 2) {
rc[parts[0].trim()] = parts[1].trim();
}
@ -78,8 +79,8 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
const rc = readRcFile(rcFile);
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
let rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
});
@ -88,7 +89,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
let rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
});
@ -98,7 +99,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
let rc = readRcFile(rcFile);
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('false');
});
@ -107,7 +108,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('npm.pkg.github.com', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
let rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
});
@ -115,98 +116,8 @@ describe('authutil tests', () => {
it('Sets up npmrc for always-auth true', async () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
let rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('true');
});
it('is already set the NODE_AUTH_TOKEN export it', async () => {
process.env.NODE_AUTH_TOKEN = 'foobar';
await auth.configAuthentication('npm.pkg.github.com', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
});
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
fs.writeFileSync(rcFile, 'registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should overwrite only non-scoped', async () => {
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should add non-scoped to scoped', async () => {
fs.writeFileSync(rcFile, '@myscope:registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should overwrite scoped with scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@myscope:registry=NNN`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should overwrite only scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should add scoped to non-scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should overwrite only one scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(
rcFile,
`@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM`
);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
it('configAuthentication should add scoped to another scoped', async () => {
process.env['INPUT_SCOPE'] = 'myscope';
fs.writeFileSync(rcFile, `@otherscope:registry=MMM`);
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
});

View file

@ -1,183 +1,152 @@
[
{
"version": "14.0.0",
"stable": true,
"lts": "Fermium",
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200507.99",
"files": [
{
"filename": "node-14.0.0-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-14.0.0-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-14.0.0-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-win32-x64.7z"
}
]
},
{
"version": "13.13.0",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200507.97",
"files": [
{
"filename": "node-13.13.0-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-13.13.0-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-13.13.0-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-win32-x64.7z"
}
]
},
{
"version": "12.16.2",
"stable": true,
"lts": "Erbium",
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200507.95",
"files": [
{
"filename": "node-12.16.2-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-12.16.2-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-12.16.2-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-win32-x64.7z"
}
]
},
{
"version": "12.0.0",
"stable": true,
"lts": "Erbium",
"release_url": "https://github.com/actions/node-versions/releases/tag/12.0.0-20200507.71",
"files": [
{
"filename": "node-12.0.0-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-12.0.0-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-12.0.0-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-win32-x64.7z"
}
]
},
{
"version": "10.20.1",
"stable": true,
"lts": "Dubnium",
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200507.70",
"files": [
{
"filename": "node-10.20.1-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-10.20.1-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-10.20.1-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-win32-x64.7z"
}
]
},
{
"version": "8.17.0",
"stable": true,
"lts": "Carbon",
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200507.37",
"files": [
{
"filename": "node-8.17.0-darwin-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-8.17.0-linux-x64.tar.gz",
"arch": "x64",
"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"
},
{
"filename": "node-8.17.0-win32-x64.7z",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-win32-x64.7z"
}
]
},
{
"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"
}
]
}
]
{
"version": "14.0.0",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200423.30",
"files": [
{
"filename": "node-14.0.0-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"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",
"arch": "x64",
"platform": "linux",
"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.zip",
"arch": "x64",
"platform": "win32",
"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",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200423.29",
"files": [
{
"filename": "node-13.13.0-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"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",
"arch": "x64",
"platform": "linux",
"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.zip",
"arch": "x64",
"platform": "win32",
"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",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200423.28",
"files": [
{
"filename": "node-12.16.2-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"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",
"arch": "x64",
"platform": "linux",
"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.zip",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-win32-x64.zip"
}
]
},
{
"version": "10.20.1",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200423.27",
"files": [
{
"filename": "node-10.20.1-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"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-10.20.1-linux-x64.tar.gz",
"arch": "x64",
"platform": "linux",
"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-10.20.1-win32-x64.zip",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-win32-x64.zip"
}
]
},
{
"version": "8.17.0",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200423.26",
"files": [
{
"filename": "node-8.17.0-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"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-8.17.0-linux-x64.tar.gz",
"arch": "x64",
"platform": "linux",
"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-8.17.0-win32-x64.zip",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-win32-x64.zip"
}
]
},
{
"version": "6.17.1",
"stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200423.25",
"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-20200423.25/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-20200423.25/node-6.17.1-linux-x64.tar.gz"
},
{
"filename": "node-6.17.1-win32-x64.zip",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-win32-x64.zip"
}
]
}
]

336
__tests__/installer.test.ts Normal file
View file

@ -0,0 +1,336 @@
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import fs from 'fs';
import cp from 'child_process';
import osm = require('os');
import path from 'path';
import * as main from '../src/main';
import * as im from '../src/installer';
import * as auth from '../src/authutil';
let nodeTestManifest = require('./data/versions-manifest.json');
let nodeTestDist = require('./data/node-dist-index.json');
// let matchers = require('../matchers.json');
// let matcherPattern = matchers.problemMatcher[0].pattern[0];
// let matcherRegExp = new RegExp(matcherPattern.regexp);
describe('setup-node', () => {
let inputs = {} as any;
let os = {} as any;
let inSpy: jest.SpyInstance;
let findSpy: jest.SpyInstance;
let cnSpy: jest.SpyInstance;
let logSpy: jest.SpyInstance;
let getManifestSpy: jest.SpyInstance;
let getDistSpy: jest.SpyInstance;
let platSpy: jest.SpyInstance;
let archSpy: jest.SpyInstance;
let dlSpy: jest.SpyInstance;
let exSpy: jest.SpyInstance;
let cacheSpy: jest.SpyInstance;
let dbgSpy: jest.SpyInstance;
let whichSpy: jest.SpyInstance;
let existsSpy: jest.SpyInstance;
let mkdirpSpy: jest.SpyInstance;
let execSpy: jest.SpyInstance;
let authSpy: jest.SpyInstance;
beforeEach(() => {
// @actions/core
inputs = {};
inSpy = jest.spyOn(core, 'getInput');
inSpy.mockImplementation(name => inputs[name]);
// node
os = {};
platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => os['platform']);
archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync');
// @actions/tool-cache
findSpy = jest.spyOn(tc, 'find');
dlSpy = jest.spyOn(tc, 'downloadTool');
exSpy = jest.spyOn(tc, 'extractTar');
cacheSpy = jest.spyOn(tc, 'cacheDir');
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
getDistSpy = jest.spyOn(im, 'getVersionsFromDist');
// io
whichSpy = jest.spyOn(io, 'which');
existsSpy = jest.spyOn(fs, 'existsSync');
mkdirpSpy = jest.spyOn(io, 'mkdirP');
// disable authentication portion for installer tests
authSpy = jest.spyOn(auth, 'configAuthentication');
authSpy.mockImplementation(() => {});
// gets
getManifestSpy.mockImplementation(
() => <tc.IToolRelease[]>nodeTestManifest
);
getDistSpy.mockImplementation(() => <im.INodeVersion>nodeTestDist);
// writes
cnSpy = jest.spyOn(process.stdout, 'write');
logSpy = jest.spyOn(console, 'log');
dbgSpy = jest.spyOn(core, 'debug');
cnSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('write:' + line + '\n');
});
logSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('log:' + line + '\n');
});
dbgSpy.mockImplementation(msg => {
// uncomment to see debug output
// process.stderr.write(msg + '\n');
});
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
//jest.restoreAllMocks();
});
afterAll(async () => {}, 100000);
//--------------------------------------------------
// Manifest find tests
//--------------------------------------------------
it('can mock manifest versions', async () => {
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
'actions',
'node-versions',
'mocktoken'
);
expect(versions).toBeDefined();
expect(versions?.length).toBe(6);
});
it('can mock dist versions', async () => {
let versions: im.INodeVersion[] = await im.getVersionsFromDist();
expect(versions).toBeDefined();
expect(versions?.length).toBe(23);
});
it('can find 12.16.2 from manifest on osx', async () => {
os.platform = 'darwin';
os.arch = 'x64';
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
'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');
});
it('can find 12 from manifest on linux', async () => {
os.platform = 'linux';
os.arch = 'x64';
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
'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');
});
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');
});
//--------------------------------------------------
// Found in cache tests
//--------------------------------------------------
it('finds version in cache with stable true', async () => {
inputs['node-version'] = '12';
inputs.stable = 'true';
let toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});
it('finds version in cache with stable not supplied', async () => {
inputs['node-version'] = '12';
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});
it('finds version in cache and adds it to the path', async () => {
inputs['node-version'] = '12';
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('handles unhandled find error and reports error', async () => {
let errMsg = 'unhandled error message';
inputs['node-version'] = '12';
findSpy.mockImplementation(() => {
throw new Error(errMsg);
});
await main.run();
expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL);
});
it('downloads a version from a manifest match', async () => {
os.platform = 'linux';
os.arch = 'x64';
// a version which is in the manifest
let versionSpec = '12.16.2';
let resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
let expectedUrl =
'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
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/node/12.16.2/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${resolvedVersion} from ${expectedUrl}`
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('falls back to a version from node dist', async () => {
os.platform = 'linux';
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
let versionSpec = '11.15.0';
let resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
let expectedUrl =
'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
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/node/11.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Node'
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('does not find a version that does not exist', async () => {
os.platform = 'linux';
os.arch = 'x64';
let versionSpec = '9.99.9';
inputs['node-version'] = versionSpec;
findSpy.mockImplementation(() => '');
await main.run();
expect(logSpy).toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Node'
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(cnSpy).toHaveBeenCalledWith(
`::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}`
);
});
it('reports a failed download', async () => {
let errMsg = 'unhandled download message';
os.platform = 'linux';
os.arch = 'x64';
// a version which is in the manifest
let versionSpec = '12.16.2';
let resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => {
throw new Error(errMsg);
});
await main.run();
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
});
});

View file

@ -1,39 +1,59 @@
<<<<<<< Updated upstream
name: 'Setup Node.js'
description: 'Set up a specific version of Node.js and add the command-line tools to the PATH'
=======
<<<<<<< Updated upstream
name: 'Setup Node.js'
description: 'Set up a specific version of Node.js and add the command-line tools to the PATH'
=======
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'
>>>>>>> Stashed changes
>>>>>>> Stashed changes
author: 'GitHub'
inputs:
always-auth:
description: 'Set always-auth in npmrc.'
description: 'Set always-auth in npmrc'
default: 'false'
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
node-version-file:
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
default: false
<<<<<<< Updated upstream
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
default: '10.x'
=======
<<<<<<< Updated upstream
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
default: '10.x'
=======
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
>>>>>>> Stashed changes
>>>>>>> Stashed changes
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:
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'
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
=======
token:
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
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 pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
default: ${{ github.token }}
# 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
outputs:
cache-hit:
description: 'A boolean value to indicate if a cache was hit.'
node-version:
description: 'The installed node version.'
>>>>>>> Stashed changes
>>>>>>> Stashed changes
# 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'
runs:
using: 'node16'
main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js'
post-if: success()
using: 'node12'
<<<<<<< Updated upstream
main: 'lib/setup-node.js'
=======
<<<<<<< Updated upstream
main: 'lib/setup-node.js'
=======
main: 'dist/index.js'
>>>>>>> Stashed changes
>>>>>>> Stashed changes

17182
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

16116
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,15 @@
{
"name": "setup-node",
"version": "3.4.1",
"version": "2.0.0",
"private": true,
"description": "setup node action",
"main": "lib/setup-node.js",
"scripts": {
"build": "ncc build -o dist/setup src/setup-node.ts && ncc build -o dist/cache-save src/cache-save.ts",
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write \"**/*.{ts,yml,yaml}\"",
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check \"**/*.{ts,yml,yaml}\"",
"lint": "eslint --config ./.eslintrc.js \"**/*.ts\"",
"lint:fix": "eslint --config ./.eslintrc.js \"**/*.ts\" --fix",
"test": "jest --coverage",
"pre-checkin": "npm run format && npm run lint:fix && npm run build && npm test"
"build": "tsc && ncc build",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"test": "jest",
"pre-checkin": "npm run format && npm run build && npm test"
},
"repository": {
"type": "git",
@ -25,32 +23,23 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.0.4",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.0",
"@actions/core": "^1.2.2",
"@actions/exec": "^1.0.3",
"@actions/github": "^1.1.0",
"@actions/glob": "^0.2.0",
"@actions/http-client": "^1.0.11",
"@actions/http-client": "^1.0.6",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.4",
"semver": "^6.1.1"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^16.11.25",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.4",
"@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@vercel/ncc": "^0.33.4",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0",
"jest": "^27.2.5",
"jest-circus": "^27.2.5",
"jest-each": "^27.2.5",
"prettier": "^2.8.4",
"ts-jest": "^27.0.5",
"typescript": "^4.2.3"
"@zeit/ncc": "^0.21.0",
"jest": "^24.9.0",
"jest-circus": "^24.7.1",
"prettier": "^1.19.1",
"ts-jest": "^24.3.0",
"typescript": "^3.8.3"
}
}

340
src/installer.ts Normal file
View file

@ -0,0 +1,340 @@
import os = require('os');
import * as assert from 'assert';
import * as core from '@actions/core';
import * as hc from '@actions/http-client';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import * as path from 'path';
import * as semver from 'semver';
import fs = require('fs');
//
// Node versions interface
// see https://nodejs.org/dist/index.json
//
export interface INodeVersion {
version: string;
files: string[];
}
interface INodeVersionInfo {
downloadUrl: string;
resolvedVersion: string;
fileName: string;
}
export async function getNode(
versionSpec: string,
stable: boolean,
auth: string | undefined
) {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(os.arch());
// check cache
let toolPath: string;
toolPath = tc.find('node', versionSpec);
// If not found in cache, download
if (toolPath) {
console.log(`Found in cache @ ${toolPath}`);
} else {
console.log(`Attempting to download ${versionSpec}...`);
let downloadPath = '';
let info: INodeVersionInfo | null = null;
//
// Try download from internal distribution (popular versions only)
//
try {
info = await getInfoFromManifest(versionSpec, stable, auth);
if (info) {
console.log(
`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`
);
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
} else {
console.log(
'Not found in manifest. Falling back to download directly from Node'
);
}
} catch (err) {
// Rate limit?
if (
err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
console.log(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
console.log(err.message);
}
core.debug(err.stack);
console.log('Falling back to download directly from Node');
}
//
// Download from nodejs.org
//
if (!downloadPath) {
info = await getInfoFromDist(versionSpec);
if (!info) {
throw new Error(
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
);
}
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
try {
downloadPath = await tc.downloadTool(info.downloadUrl);
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
}
throw err;
}
}
//
// Extract
//
console.log('Extracting ...');
let extPath: string;
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
if (osPlat == 'win32') {
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
// 7z extracts to folder matching file name
let nestedPath = path.join(extPath, path.basename(info.fileName, '.7z'));
if (fs.existsSync(nestedPath)) {
extPath = nestedPath;
}
} else {
extPath = await tc.extractTar(downloadPath, undefined, [
'xz',
'--strip',
'1'
]);
}
//
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
//
console.log('Adding to the cache ...');
toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion);
console.log('Done');
}
//
// a tool installer initimately knows details about the layout of that tool
// for example, node binary is in the bin folder after the extract on Mac/Linux.
// layouts could change by version, by platform etc... but that's the tool installers job
//
if (osPlat != 'win32') {
toolPath = path.join(toolPath, 'bin');
}
//
// prepend the tools path. instructs the agent to prepend for future tasks
core.addPath(toolPath);
}
async function getInfoFromManifest(
versionSpec: string,
stable: boolean,
auth: string | undefined
): Promise<INodeVersionInfo | null> {
let info: INodeVersionInfo | null = null;
const releases = await tc.getManifestFromRepo(
'actions',
'node-versions',
auth
);
console.log(`matching ${versionSpec}...`);
const rel = await tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) {
info = <INodeVersionInfo>{};
info.resolvedVersion = rel.version;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}
return info;
}
async function getInfoFromDist(
versionSpec: string
): Promise<INodeVersionInfo | null> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(os.arch());
let version: string;
version = await queryDistForMatch(versionSpec);
if (!version) {
return null;
}
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
version = semver.clean(version) || '';
let fileName: string =
osPlat == 'win32'
? `node-v${version}-win-${osArch}`
: `node-v${version}-${osPlat}-${osArch}`;
let urlFileName: string =
osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let url = `https://nodejs.org/dist/v${version}/${urlFileName}`;
return <INodeVersionInfo>{
downloadUrl: url,
resolvedVersion: version,
fileName: fileName
};
}
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
function evaluateVersions(versions: string[], versionSpec: string): string {
let version = '';
core.debug(`evaluating ${versions.length} versions`);
versions = versions.sort((a, b) => {
if (semver.gt(a, b)) {
return 1;
}
return -1;
});
for (let i = versions.length - 1; i >= 0; i--) {
const potential: string = versions[i];
const satisfied: boolean = semver.satisfies(potential, versionSpec);
if (satisfied) {
version = potential;
break;
}
}
if (version) {
core.debug(`matched: ${version}`);
} else {
core.debug('match not found');
}
return version;
}
async function queryDistForMatch(versionSpec: string): Promise<string> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(os.arch());
// node offers a json list of versions
let dataFileName: string;
switch (osPlat) {
case 'linux':
dataFileName = `linux-${osArch}`;
break;
case 'darwin':
dataFileName = `osx-${osArch}-tar`;
break;
case 'win32':
dataFileName = `win-${osArch}-exe`;
break;
default:
throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions: string[] = [];
let nodeVersions = await module.exports.getVersionsFromDist();
nodeVersions.forEach((nodeVersion: INodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
// get the latest version that matches the version spec
let version: string = evaluateVersions(versions, versionSpec);
return version;
}
export async function getVersionsFromDist(): Promise<INodeVersion[]> {
let dataUrl = 'https://nodejs.org/dist/index.json';
let httpClient = new hc.HttpClient('setup-node', [], {
allowRetries: true,
maxRetries: 3
});
let response = await httpClient.getJson<INodeVersion[]>(dataUrl);
return response.result || [];
}
// For non LTS versions of Node, the files we need (for Windows) are sometimes located
// in a different folder than they normally are for other versions.
// Normally the format is similar to: https://nodejs.org/dist/v5.10.1/node-v5.10.1-win-x64.7z
// In this case, there will be two files located at:
// /dist/v5.10.1/win-x64/node.exe
// /dist/v5.10.1/win-x64/node.lib
// If this is not the structure, there may also be two files located at:
// /dist/v0.12.18/node.exe
// /dist/v0.12.18/node.lib
// This method attempts to download and cache the resources from these alternative locations.
// Note also that the files are normally zipped but in this case they are just an exe
// and lib file in a folder, not zipped.
async function acquireNodeFromFallbackLocation(
version: string
): Promise<string> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(os.arch());
// Create temporary folder to download in to
const tempDownloadFolder: string =
'temp_' + Math.floor(Math.random() * 2000000000);
const tempDirectory = process.env['RUNNER_TEMP'] || '';
assert.ok(tempDirectory, 'Expected RUNNER_TEMP to be defined');
const tempDir: string = path.join(tempDirectory, tempDownloadFolder);
await io.mkdirP(tempDir);
let exeUrl: string;
let libUrl: string;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
console.log(`Downloading only node binary from ${exeUrl}`);
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl);
await io.cp(libPath, path.join(tempDir, 'node.lib'));
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl);
await io.cp(libPath, path.join(tempDir, 'node.lib'));
} else {
throw err;
}
}
let toolPath = await tc.cacheDir(tempDir, 'node', version);
core.addPath(toolPath);
return toolPath;
}
// os.arch does not always match the relative download url, e.g.
// os.arch == 'arm' != node-v12.13.1-linux-armv7l.tar.gz
// All other currently supported architectures match, e.g.:
// os.arch = arm64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-arm64.tar.gz
// os.arch = x64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-x64.tar.gz
function translateArchToDistUrl(arch: string): string {
switch (arch) {
case 'arm':
return 'armv7l';
default:
return arch;
}
}

View file

@ -1,14 +1,8 @@
import * as core from '@actions/core';
import fs from 'fs';
import os from 'os';
import * as installer from './installer';
import * as auth from './authutil';
import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory';
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
import {URL} from 'url';
export async function run() {
try {
@ -16,97 +10,41 @@ export async function run() {
// Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc...
//
const version = resolveVersionInput();
let arch = core.getInput('architecture');
const cache = core.getInput('cache');
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
core.warning(
'`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
);
}
if (!arch) {
arch = os.arch();
let version = core.getInput('node-version');
if (!version) {
version = core.getInput('version');
}
console.log(`version: ${version}`);
if (version) {
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;
const stable =
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const checkLatest =
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
const nodejsInfo = {
versionSpec: version,
checkLatest,
auth,
stable,
arch
};
const nodeDistribution = getNodejsDistribution(nodejsInfo);
await nodeDistribution.setupNodeJs();
let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`;
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
await installer.getNode(version, stable, auth);
}
await printEnvDetailsAndSetOutput();
const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
}
if (cache && isCacheFeatureAvailable()) {
const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(cache, cacheDependencyPath);
}
const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
core.info(
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
console.log(
`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`
);
core.info(
console.log(
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
);
} catch (err) {
core.setFailed(err.message);
} catch (error) {
core.setFailed(error.message);
}
}
function resolveVersionInput(): string {
let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) {
core.warning(
'Both node-version and node-version-file inputs are specified, only node-version will be used'
);
}
if (version) {
return version;
}
if (versionFileInput) {
const versionFilePath = path.join(
process.env.GITHUB_WORKSPACE!,
versionFileInput
);
if (!fs.existsSync(versionFilePath)) {
throw new Error(
`The specified node version file at: ${versionFilePath} does not exist`
);
}
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
core.info(`Resolved ${versionFileInput} as ${version}`);
}
return version;
function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
}

22
validate/test.sh Normal file
View file

@ -0,0 +1,22 @@
#/bin/bash
set -e
rm -rf ./temp
rm -rf ./node
# uncomment to use charles proxy or other debugging proxy
# export NODE_TLS_REJECT_UNAUTHORIZED=0
# export https_proxy=http://127.0.0.1:8888
export RUNNER_TOOL_CACHE=$(pwd)
export RUNNER_TEMP="${RUNNER_TOOL_CACHE}/temp"
export INPUT_STABLE=true
export INPUT_VERSION="12" #"0.12.7" #"12" #"11.15.0"
# export your PAT with repo scope before running
export INPUT_TOKEN=$GITHUB_TOKEN
echo "Getting ${INPUT_VERSION} ($INPUT_STABLE) with ${INPUT_TOKEN}..."
node ../dist/index.js