Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1f314fca9 | ||
|
|
108628bcbd | ||
|
|
eb416799cf | ||
|
|
5f10e344c2 | ||
|
|
40e244d750 | ||
|
|
c8711b5525 | ||
|
|
d5ae932ee7 | ||
|
|
56899e050a | ||
|
|
4bb8c45053 | ||
|
|
a251a519bf |
@@ -1,32 +0,0 @@
|
|||||||
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, macos-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
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
name: proxy
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 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: datadog/squid:latest
|
|
||||||
ports:
|
|
||||||
- 3128:3128
|
|
||||||
env:
|
|
||||||
https_proxy: http://squid-proxy:3128
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Clear tool cache
|
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
|
||||||
- name: Setup node 10
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: 10.x
|
|
||||||
- name: Verify node and npm
|
|
||||||
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@v2
|
|
||||||
- name: Clear tool cache
|
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
|
||||||
- name: Setup node 11
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: 11
|
|
||||||
- name: Verify node and npm
|
|
||||||
run: __tests__/verify-node.sh 11
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
name: versions
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- releases/*
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
local-cache:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [10, 12, 14]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- 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
|
|
||||||
|
|
||||||
manifest:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [10.15, 12.16.0, 14.2.0]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- 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.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [10, 11, 12, 14]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- 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
|
|
||||||
|
|
||||||
node-dist:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [11, 13]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- 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.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
# test old versions which didn't have npm and layout different
|
|
||||||
- name: Setup node 0.12.18 from dist
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: 0.12.18
|
|
||||||
- name: Verify node
|
|
||||||
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
|
|
||||||
shell: bash
|
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
name: Main workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- releases/*
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-latest, windows-latest]
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
|
- name: Setup node 10
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: Verify node and npm
|
||||||
|
run: __tests__/verify-node.sh 10
|
||||||
|
|
||||||
|
test-fallback:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
|
||||||
|
- name: Setup node 0.12.18 # For non LTS versions of Node, the zip is not always available
|
||||||
|
uses: ./ # and falls back to downloading node.exe and node.lib
|
||||||
|
with:
|
||||||
|
node-version: 0.12.18
|
||||||
|
- name: Verify node
|
||||||
|
shell: bash
|
||||||
|
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
|
||||||
|
|
||||||
|
test-proxy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ubuntu:latest
|
||||||
|
options: --dns 127.0.0.1
|
||||||
|
services:
|
||||||
|
squid-proxy:
|
||||||
|
image: datadog/squid:latest
|
||||||
|
ports:
|
||||||
|
- 3128:3128
|
||||||
|
env:
|
||||||
|
https_proxy: http://squid-proxy:3128
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
|
- name: Setup node 10
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: Verify node and npm
|
||||||
|
run: __tests__/verify-node.sh 10
|
||||||
|
|
||||||
|
test-bypass-proxy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
https_proxy: http://no-such-proxy:3128
|
||||||
|
no_proxy: github.com,nodejs.org,registry.npmjs.org
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
|
- name: Setup node 10
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: Verify node and npm
|
||||||
|
run: __tests__/verify-node.sh 10
|
||||||
@@ -2,9 +2,6 @@ node_modules/
|
|||||||
lib/
|
lib/
|
||||||
__tests__/runner/*
|
__tests__/runner/*
|
||||||
|
|
||||||
validate/temp
|
|
||||||
validate/node
|
|
||||||
|
|
||||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|||||||
Vendored
-21
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Debug Jest Tests on Nix",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"--inspect-brk",
|
|
||||||
"${workspaceRoot}/node_modules/.bin/jest",
|
|
||||||
"--runInBand"
|
|
||||||
],
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"internalConsoleOptions": "neverOpen",
|
|
||||||
"port": 9229
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`installer tests Appends trailing slash to registry 1`] = `
|
||||||
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`installer tests Automatically configures GPR scope 1`] = `
|
||||||
|
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
@ownername:registry=npm.pkg.github.com/
|
||||||
|
always-auth=false"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`installer tests Configures scoped npm registries 1`] = `
|
||||||
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
@myscope:registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`installer tests Sets up npmrc for always-auth true 1`] = `
|
||||||
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=true"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`installer tests Sets up npmrc for npmjs 1`] = `
|
||||||
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
|
`;
|
||||||
+26
-82
@@ -1,26 +1,22 @@
|
|||||||
import os = require('os');
|
import * as io from '@actions/io';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as io from '@actions/io';
|
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
|
|
||||||
let rcFile: string;
|
let rcFile: string;
|
||||||
|
|
||||||
describe('authutil tests', () => {
|
describe('installer tests', () => {
|
||||||
const _runnerDir = path.join(__dirname, 'runner');
|
|
||||||
|
|
||||||
let cnSpy: jest.SpyInstance;
|
|
||||||
let logSpy: jest.SpyInstance;
|
|
||||||
let dbgSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const randPath = path.join(
|
const tempDir = path.join(
|
||||||
Math.random()
|
__dirname,
|
||||||
.toString(36)
|
'runner',
|
||||||
.substring(7)
|
path.join(
|
||||||
|
Math.random()
|
||||||
|
.toString(36)
|
||||||
|
.substring(7)
|
||||||
|
),
|
||||||
|
'temp'
|
||||||
);
|
);
|
||||||
const tempDir = path.join(_runnerDir, randPath, 'temp');
|
|
||||||
await io.rmRF(tempDir);
|
await io.rmRF(tempDir);
|
||||||
await io.mkdirP(tempDir);
|
await io.mkdirP(tempDir);
|
||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
@@ -28,96 +24,44 @@ describe('authutil tests', () => {
|
|||||||
rcFile = path.join(tempDir, '.npmrc');
|
rcFile = path.join(tempDir, '.npmrc');
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
await io.rmRF(rcFile);
|
if (fs.existsSync(rcFile)) {
|
||||||
// if (fs.existsSync(rcFile)) {
|
fs.unlinkSync(rcFile);
|
||||||
// fs.unlinkSync(rcFile);
|
}
|
||||||
// }
|
|
||||||
process.env['INPUT_SCOPE'] = '';
|
process.env['INPUT_SCOPE'] = '';
|
||||||
|
});
|
||||||
// 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');
|
|
||||||
});
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
function dbg(message: string) {
|
|
||||||
process.stderr.write('dbg::' + message + '::\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
if (_runnerDir) {
|
|
||||||
await io.rmRF(_runnerDir);
|
|
||||||
}
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
function readRcFile(rcFile: string) {
|
|
||||||
let rc = {};
|
|
||||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
|
||||||
for (const line of contents.split(os.EOL)) {
|
|
||||||
let parts = line.split('=');
|
|
||||||
if (parts.length == 2) {
|
|
||||||
rc[parts[0].trim()] = parts[1].trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
it('Sets up npmrc for npmjs', async () => {
|
it('Sets up npmrc for npmjs', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
|
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
|
||||||
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
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');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Appends trailing slash to registry', async () => {
|
it('Appends trailing slash to registry', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||||
|
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
let rc = readRcFile(rcFile);
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
|
||||||
expect(rc['always-auth']).toBe('false');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Configures scoped npm registries', async () => {
|
it('Configures scoped npm registries', async () => {
|
||||||
process.env['INPUT_SCOPE'] = 'myScope';
|
process.env['INPUT_SCOPE'] = 'myScope';
|
||||||
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||||
|
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
let rc = readRcFile(rcFile);
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
|
|
||||||
expect(rc['always-auth']).toBe('false');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Automatically configures GPR scope', async () => {
|
it('Automatically configures GPR scope', async () => {
|
||||||
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
||||||
|
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
let rc = readRcFile(rcFile);
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
|
|
||||||
expect(rc['always-auth']).toBe('false');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sets up npmrc for always-auth true', async () => {
|
it('Sets up npmrc for always-auth true', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
let rc = readRcFile(rcFile);
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
|
||||||
expect(rc['always-auth']).toBe('true');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,152 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
+109
-475
File diff suppressed because it is too large
Load Diff
+3
-10
@@ -1,24 +1,17 @@
|
|||||||
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 and add it to the PATH, additionally providing proxy support'
|
||||||
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: 10.x, 10.15.1, >=10.15.0'
|
||||||
check-latest:
|
default: '10.x'
|
||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
|
||||||
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'
|
description: 'Optional scope for authenticating against scoped registries'
|
||||||
token:
|
|
||||||
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
|
|
||||||
# Deprecated option, do not use. Will not be supported after October 1, 2019
|
# Deprecated option, do not use. Will not be supported after October 1, 2019
|
||||||
version:
|
version:
|
||||||
description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019'
|
description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019'
|
||||||
|
|||||||
Vendored
+309
-1455
File diff suppressed because it is too large
Load Diff
Vendored
+1278
File diff suppressed because it is too large
Load Diff
Generated
+622
-3253
File diff suppressed because it is too large
Load Diff
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "2.0.0",
|
"version": "1.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,12 +23,12 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.2",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.3",
|
"@actions/exec": "^1.0.3",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/http-client": "^1.0.6",
|
"@actions/http-client": "^1.0.6",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.5.4",
|
"@actions/tool-cache": "^1.3.3",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -36,10 +36,10 @@
|
|||||||
"@types/node": "^12.0.4",
|
"@types/node": "^12.0.4",
|
||||||
"@types/semver": "^6.0.0",
|
"@types/semver": "^6.0.0",
|
||||||
"@zeit/ncc": "^0.21.0",
|
"@zeit/ncc": "^0.21.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.8.0",
|
||||||
"jest-circus": "^24.7.1",
|
"jest-circus": "^24.7.1",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.17.1",
|
||||||
"ts-jest": "^24.3.0",
|
"ts-jest": "^24.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+92
-224
@@ -1,144 +1,54 @@
|
|||||||
import os = require('os');
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as hc from '@actions/http-client';
|
import * as hc from '@actions/http-client';
|
||||||
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 os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import fs = require('fs');
|
|
||||||
|
let osPlat: string = os.platform();
|
||||||
|
let osArch: string = translateArchToDistUrl(os.arch());
|
||||||
|
|
||||||
//
|
//
|
||||||
// Node versions interface
|
// Node versions interface
|
||||||
// see https://nodejs.org/dist/index.json
|
// see https://nodejs.org/dist/index.json
|
||||||
//
|
//
|
||||||
export interface INodeVersion {
|
interface INodeVersion {
|
||||||
version: string;
|
version: string;
|
||||||
files: string[];
|
files: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface INodeVersionInfo {
|
export async function getNode(versionSpec: string) {
|
||||||
downloadUrl: string;
|
|
||||||
resolvedVersion: string;
|
|
||||||
fileName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getNode(
|
|
||||||
versionSpec: string,
|
|
||||||
stable: boolean,
|
|
||||||
checkLatest: boolean,
|
|
||||||
auth: string | undefined
|
|
||||||
) {
|
|
||||||
let osPlat: string = os.platform();
|
|
||||||
let osArch: string = translateArchToDistUrl(os.arch());
|
|
||||||
|
|
||||||
if (checkLatest) {
|
|
||||||
core.info('Attempt to resolve the latest version from manifest...');
|
|
||||||
const resolvedVersion = await resolveVersionFromManifest(
|
|
||||||
versionSpec,
|
|
||||||
stable,
|
|
||||||
auth
|
|
||||||
);
|
|
||||||
if (resolvedVersion) {
|
|
||||||
versionSpec = resolvedVersion;
|
|
||||||
core.info(`Resolved as '${versionSpec}'`);
|
|
||||||
} else {
|
|
||||||
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath: string;
|
let toolPath: string;
|
||||||
toolPath = tc.find('node', versionSpec);
|
toolPath = tc.find('node', versionSpec);
|
||||||
|
|
||||||
// If not found in cache, download
|
// If not found in cache, download
|
||||||
if (toolPath) {
|
if (!toolPath) {
|
||||||
core.info(`Found in cache @ ${toolPath}`);
|
let version: string;
|
||||||
} else {
|
const c = semver.clean(versionSpec) || '';
|
||||||
core.info(`Attempting to download ${versionSpec}...`);
|
// If explicit version
|
||||||
let downloadPath = '';
|
if (semver.valid(c) != null) {
|
||||||
let info: INodeVersionInfo | null = null;
|
// version to download
|
||||||
|
version = versionSpec;
|
||||||
//
|
} else {
|
||||||
// Try download from internal distribution (popular versions only)
|
// query nodejs.org for a matching version
|
||||||
//
|
version = await queryLatestMatch(versionSpec);
|
||||||
try {
|
if (!version) {
|
||||||
info = await getInfoFromManifest(versionSpec, stable, auth);
|
|
||||||
if (info) {
|
|
||||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
|
||||||
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
|
|
||||||
} else {
|
|
||||||
core.info(
|
|
||||||
'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)
|
|
||||||
) {
|
|
||||||
core.info(
|
|
||||||
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
core.info(err.message);
|
|
||||||
}
|
|
||||||
core.debug(err.stack);
|
|
||||||
core.info('Falling back to download directly from Node');
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Download from nodejs.org
|
|
||||||
//
|
|
||||||
if (!downloadPath) {
|
|
||||||
info = await getInfoFromDist(versionSpec);
|
|
||||||
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}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
// check cache
|
||||||
try {
|
toolPath = tc.find('node', version);
|
||||||
downloadPath = await tc.downloadTool(info.downloadUrl);
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
|
||||||
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
if (!toolPath) {
|
||||||
// Extract
|
// download, extract, cache
|
||||||
//
|
toolPath = await acquireNode(version);
|
||||||
core.info('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
|
|
||||||
//
|
|
||||||
core.info('Adding to the cache ...');
|
|
||||||
toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion);
|
|
||||||
core.info('Done');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -155,74 +65,41 @@ export async function getNode(
|
|||||||
core.addPath(toolPath);
|
core.addPath(toolPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInfoFromManifest(
|
async function queryLatestMatch(versionSpec: string): Promise<string> {
|
||||||
versionSpec: string,
|
// node offers a json list of versions
|
||||||
stable: boolean,
|
let dataFileName: string;
|
||||||
auth: string | undefined
|
switch (osPlat) {
|
||||||
): Promise<INodeVersionInfo | null> {
|
case 'linux':
|
||||||
let info: INodeVersionInfo | null = null;
|
dataFileName = `linux-${osArch}`;
|
||||||
const releases = await tc.getManifestFromRepo(
|
break;
|
||||||
'actions',
|
case 'darwin':
|
||||||
'node-versions',
|
dataFileName = `osx-${osArch}-tar`;
|
||||||
auth,
|
break;
|
||||||
'main'
|
case 'win32':
|
||||||
);
|
dataFileName = `win-${osArch}-exe`;
|
||||||
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
break;
|
||||||
|
default:
|
||||||
if (rel && rel.files.length > 0) {
|
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||||
info = <INodeVersionInfo>{};
|
|
||||||
info.resolvedVersion = rel.version;
|
|
||||||
info.downloadUrl = rel.files[0].download_url;
|
|
||||||
info.fileName = rel.files[0].filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
let versions: string[] = [];
|
||||||
}
|
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);
|
||||||
|
let nodeVersions = response.result || [];
|
||||||
|
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
||||||
|
// ensure this version supports your os and platform
|
||||||
|
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
|
||||||
|
versions.push(nodeVersion.version);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function getInfoFromDist(
|
// get the latest version that matches the version spec
|
||||||
versionSpec: string
|
let version: string = evaluateVersions(versions, versionSpec);
|
||||||
): Promise<INodeVersionInfo | null> {
|
return version;
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveVersionFromManifest(
|
|
||||||
versionSpec: string,
|
|
||||||
stable: boolean,
|
|
||||||
auth: string | undefined
|
|
||||||
): Promise<string | undefined> {
|
|
||||||
try {
|
|
||||||
const info = await getInfoFromManifest(versionSpec, stable, auth);
|
|
||||||
return info?.resolvedVersion;
|
|
||||||
} catch (err) {
|
|
||||||
core.info('Unable to resolve version from manifest...');
|
|
||||||
core.debug(err.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
|
||||||
@@ -253,49 +130,47 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queryDistForMatch(versionSpec: string): Promise<string> {
|
async function acquireNode(version: string): Promise<string> {
|
||||||
let osPlat: string = os.platform();
|
//
|
||||||
let osArch: string = translateArchToDistUrl(os.arch());
|
// 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 downloadUrl = `https://nodejs.org/dist/v${version}/${urlFileName}`;
|
||||||
|
|
||||||
// node offers a json list of versions
|
let downloadPath: string;
|
||||||
let dataFileName: string;
|
|
||||||
switch (osPlat) {
|
try {
|
||||||
case 'linux':
|
downloadPath = await tc.downloadTool(downloadUrl);
|
||||||
dataFileName = `linux-${osArch}`;
|
} catch (err) {
|
||||||
break;
|
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
||||||
case 'darwin':
|
return await acquireNodeFromFallbackLocation(version);
|
||||||
dataFileName = `osx-${osArch}-tar`;
|
}
|
||||||
break;
|
|
||||||
case 'win32':
|
throw err;
|
||||||
dataFileName = `win-${osArch}-exe`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions: string[] = [];
|
//
|
||||||
let nodeVersions = await module.exports.getVersionsFromDist();
|
// Extract
|
||||||
|
//
|
||||||
|
let extPath: string;
|
||||||
|
if (osPlat == 'win32') {
|
||||||
|
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
|
||||||
|
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
||||||
|
} else {
|
||||||
|
extPath = await tc.extractTar(downloadPath);
|
||||||
|
}
|
||||||
|
|
||||||
nodeVersions.forEach((nodeVersion: INodeVersion) => {
|
//
|
||||||
// ensure this version supports your os and platform
|
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
|
||||||
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
|
//
|
||||||
versions.push(nodeVersion.version);
|
let toolRoot = path.join(extPath, fileName);
|
||||||
}
|
return await tc.cacheDir(toolRoot, 'node', 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
|
// For non LTS versions of Node, the files we need (for Windows) are sometimes located
|
||||||
@@ -313,9 +188,6 @@ export async function getVersionsFromDist(): Promise<INodeVersion[]> {
|
|||||||
async function acquireNodeFromFallbackLocation(
|
async function acquireNodeFromFallbackLocation(
|
||||||
version: string
|
version: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let osPlat: string = os.platform();
|
|
||||||
let osArch: string = translateArchToDistUrl(os.arch());
|
|
||||||
|
|
||||||
// Create temporary folder to download in to
|
// Create temporary folder to download in to
|
||||||
const tempDownloadFolder: string =
|
const tempDownloadFolder: string =
|
||||||
'temp_' + Math.floor(Math.random() * 2000000000);
|
'temp_' + Math.floor(Math.random() * 2000000000);
|
||||||
@@ -329,8 +201,6 @@ async function acquireNodeFromFallbackLocation(
|
|||||||
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
|
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
|
||||||
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
|
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
|
||||||
|
|
||||||
core.info(`Downloading only node binary from ${exeUrl}`);
|
|
||||||
|
|
||||||
const exePath = await tc.downloadTool(exeUrl);
|
const exePath = await tc.downloadTool(exeUrl);
|
||||||
await io.cp(exePath, path.join(tempDir, 'node.exe'));
|
await io.cp(exePath, path.join(tempDir, 'node.exe'));
|
||||||
const libPath = await tc.downloadTool(libUrl);
|
const libPath = await tc.downloadTool(libUrl);
|
||||||
@@ -348,9 +218,7 @@ async function acquireNodeFromFallbackLocation(
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let toolPath = await tc.cacheDir(tempDir, 'node', version);
|
return 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 does not always match the relative download url, e.g.
|
||||||
|
|||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
import * as installer from './installer';
|
|
||||||
import * as auth from './authutil';
|
|
||||||
import * as path from 'path';
|
|
||||||
import {URL} from 'url';
|
|
||||||
|
|
||||||
export async function run() {
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// Version is optional. If supplied, install / use from the tool cache
|
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
|
||||||
//
|
|
||||||
let version = core.getInput('node-version');
|
|
||||||
if (!version) {
|
|
||||||
version = core.getInput('version');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version) {
|
|
||||||
let token = core.getInput('token');
|
|
||||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
|
||||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
|
||||||
const checkLatest =
|
|
||||||
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
|
||||||
await installer.getNode(version, stable, checkLatest, auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
const registryUrl: string = core.getInput('registry-url');
|
|
||||||
const alwaysAuth: string = core.getInput('always-auth');
|
|
||||||
if (registryUrl) {
|
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
|
||||||
}
|
|
||||||
|
|
||||||
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')}`
|
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isGhes(): boolean {
|
|
||||||
const ghUrl = new URL(
|
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
||||||
);
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
+47
-1
@@ -1,3 +1,49 @@
|
|||||||
import {run} from './main';
|
import * as core from '@actions/core';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
import * as installer from './installer';
|
||||||
|
import * as auth from './authutil';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
|
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||||
|
//
|
||||||
|
let version = core.getInput('version');
|
||||||
|
if (!version) {
|
||||||
|
version = core.getInput('node-version');
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
await installer.getNode(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output version of node and npm that are being used
|
||||||
|
await exec.exec('node', ['--version']);
|
||||||
|
|
||||||
|
// Older versions of Node don't include npm, so don't let this call fail
|
||||||
|
await exec.exec('npm', ['--version'], {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const registryUrl: string = core.getInput('registry-url');
|
||||||
|
const alwaysAuth: string = core.getInput('always-auth');
|
||||||
|
if (registryUrl) {
|
||||||
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
|
}
|
||||||
|
|
||||||
|
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')}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
],
|
],
|
||||||
"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,
|
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
#/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
|
|
||||||
Reference in New Issue
Block a user