mirror of
https://gitea.com/actions/setup-node.git
synced 2025-07-27 18:38:53 +08:00
Compare commits
23 Commits
start-v2
...
hross-zeit
Author | SHA1 | Date | |
---|---|---|---|
94d165561a | |||
59e61b8951 | |||
321b6ccb03 | |||
1ae8f4b1fd | |||
0e2f9cde8b | |||
e434342e4e | |||
7c6182c745 | |||
a47b2f66c6 | |||
89ea387bde | |||
44c9c18728 | |||
e715d9a456 | |||
b1f2e78536 | |||
55897e37f3 | |||
46903d1fb1 | |||
28505ad4d3 | |||
2d53d29868 | |||
1e163ded31 | |||
ffde538781 | |||
0cc027b656 | |||
e99a7e62b2 | |||
0dc69b3a71 | |||
52eb8a7524 | |||
6b7f6c9fa6 |
32
.github/workflows/build-test.yml
vendored
Normal file
32
.github/workflows/build-test.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
name: build-test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- 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
|
56
.github/workflows/proxy.yml
vendored
Normal file
56
.github/workflows/proxy.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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
|
99
.github/workflows/versions.yml
vendored
Normal file
99
.github/workflows/versions.yml
vendored
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
name: versions
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- 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
|
94
.github/workflows/workflow.yml
vendored
94
.github/workflows/workflow.yml
vendored
@ -1,94 +0,0 @@
|
|||||||
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: ubuntu-latest
|
|
||||||
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
|
|
37
README.md
37
README.md
@ -1,13 +1,30 @@
|
|||||||
# setup-node
|
# setup-node
|
||||||
|
|
||||||
<p align="left">
|
<p align="left">
|
||||||
<a href="https://github.com/actions/setup-node"><img alt="GitHub Actions status" src="https://github.com/actions/setup-node/workflows/Main%20workflow/badge.svg"></a>
|
<a href="https://github.com/actions/setup-node/actions?query=workflow%3Abuild-test"><img alt="build-test status" src="https://github.com/actions/setup-node/workflows/build-test/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aversions"><img alt="versions status" src="https://github.com/actions/setup-node/workflows/versions/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aproxy"><img alt="proxy status" src="https://github.com/actions/setup-node/workflows/proxy/badge.svg"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
This action sets by node environment for use in actions by:
|
This action sets by node environment for use in actions by:
|
||||||
|
|
||||||
- optionally downloading and caching a version of node - npm by version spec and add to PATH
|
- optionally downloading and caching a version of node - npm by version spec and add to PATH
|
||||||
- registering problem matchers for error output
|
- registering problem matchers for error output
|
||||||
|
- configuring authentication for GPR or npm
|
||||||
|
|
||||||
|
# v2-beta
|
||||||
|
|
||||||
|
A beta release which adds reliability for pulling node distributions from a cache of node releases is available by referencing the `v2-beta` tag.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2-beta
|
||||||
|
with:
|
||||||
|
node-version: '12'
|
||||||
|
```
|
||||||
|
|
||||||
|
It will first check the local cache for a semver match. The hosted images have been updated with the latest of each LTS from v8, v10, v12, and v14. `self-hosted` machines will benefit from the cache as well only downloading once. It will pull LTS versions from `main` branch of [node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json) repository and on miss or failure, it will fall back to the previous behavior of download directly from [node dist](https://nodejs.org/dist/).
|
||||||
|
|
||||||
|
The `node-version` input is optional. If not supplied, node which is in your PATH will be used. However, this action will still register problem matchers and support auth features. So setting up the node environment is still a valid scenario without downloading and caching versions.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
@ -19,7 +36,21 @@ steps:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '10.x'
|
node-version: '12'
|
||||||
|
- run: npm install
|
||||||
|
- run: npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Check latest version:
|
||||||
|
> In basic example, without `check-latest` flag, the action tries to resolve version from local cache firstly and download only if it is not found. Local cache on image is updated with a couple of weeks latency.
|
||||||
|
`check-latest` flag forces the action to check if the cached version is the latest one. It reduces latency significantly but it is much more likely to incur version downloading.
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '12'
|
||||||
|
check-latest: true
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
@ -31,7 +62,7 @@ jobs:
|
|||||||
runs-on: ubuntu-16.04
|
runs-on: ubuntu-16.04
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: [ '10', '8' ]
|
node: [ '10', '12' ]
|
||||||
name: Node ${{ matrix.node }} sample
|
name: Node ${{ matrix.node }} sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -8,6 +8,7 @@ import path from 'path';
|
|||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as im from '../src/installer';
|
import * as im from '../src/installer';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
|
import {context} from '@actions/github';
|
||||||
|
|
||||||
let nodeTestManifest = require('./data/versions-manifest.json');
|
let nodeTestManifest = require('./data/versions-manifest.json');
|
||||||
let nodeTestDist = require('./data/node-dist-index.json');
|
let nodeTestDist = require('./data/node-dist-index.json');
|
||||||
@ -24,6 +25,7 @@ describe('setup-node', () => {
|
|||||||
let findSpy: jest.SpyInstance;
|
let findSpy: jest.SpyInstance;
|
||||||
let cnSpy: jest.SpyInstance;
|
let cnSpy: jest.SpyInstance;
|
||||||
let logSpy: jest.SpyInstance;
|
let logSpy: jest.SpyInstance;
|
||||||
|
let warningSpy: jest.SpyInstance;
|
||||||
let getManifestSpy: jest.SpyInstance;
|
let getManifestSpy: jest.SpyInstance;
|
||||||
let getDistSpy: jest.SpyInstance;
|
let getDistSpy: jest.SpyInstance;
|
||||||
let platSpy: jest.SpyInstance;
|
let platSpy: jest.SpyInstance;
|
||||||
@ -77,8 +79,9 @@ describe('setup-node', () => {
|
|||||||
|
|
||||||
// writes
|
// writes
|
||||||
cnSpy = jest.spyOn(process.stdout, 'write');
|
cnSpy = jest.spyOn(process.stdout, 'write');
|
||||||
logSpy = jest.spyOn(console, 'log');
|
logSpy = jest.spyOn(core, 'info');
|
||||||
dbgSpy = jest.spyOn(core, 'debug');
|
dbgSpy = jest.spyOn(core, 'debug');
|
||||||
|
warningSpy = jest.spyOn(core, 'warning');
|
||||||
cnSpy.mockImplementation(line => {
|
cnSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
// process.stderr.write('write:' + line + '\n');
|
// process.stderr.write('write:' + line + '\n');
|
||||||
@ -333,4 +336,154 @@ describe('setup-node', () => {
|
|||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('check-latest flag', () => {
|
||||||
|
it('use local version and dont check manifest if check-latest is not specified', async () => {
|
||||||
|
os.platform = 'linux';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
inputs['node-version'] = '12';
|
||||||
|
inputs['check-latest'] = 'false';
|
||||||
|
|
||||||
|
const toolPath = path.normalize('/cache/node/12.16.1/x64');
|
||||||
|
findSpy.mockReturnValue(toolPath);
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
expect(logSpy).not.toHaveBeenCalledWith(
|
||||||
|
'Attempt to resolve the latest version from manifest...'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('check latest version and resolve it from local cache', async () => {
|
||||||
|
os.platform = 'linux';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
inputs['node-version'] = '12';
|
||||||
|
inputs['check-latest'] = 'true';
|
||||||
|
|
||||||
|
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
||||||
|
findSpy.mockReturnValue(toolPath);
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Attempt to resolve the latest version from manifest...'
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('check latest version and install it from manifest', async () => {
|
||||||
|
os.platform = 'linux';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
inputs['node-version'] = '12';
|
||||||
|
inputs['check-latest'] = 'true';
|
||||||
|
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
||||||
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
const expectedUrl =
|
||||||
|
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Attempt to resolve the latest version from manifest...'
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Acquiring 12.16.2 from ${expectedUrl}`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fallback to dist if version if not found in manifest', async () => {
|
||||||
|
os.platform = 'linux';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
// a version which is not in the manifest but is in node dist
|
||||||
|
let versionSpec = '11';
|
||||||
|
|
||||||
|
inputs['node-version'] = versionSpec;
|
||||||
|
inputs['check-latest'] = 'true';
|
||||||
|
inputs['always-auth'] = false;
|
||||||
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
|
// ... 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(
|
||||||
|
'Attempt to resolve the latest version from manifest...'
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Failed to resolve version ${versionSpec} from manifest`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Attempting to download ${versionSpec}...`
|
||||||
|
);
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fallback to dist if manifest is not available', async () => {
|
||||||
|
os.platform = 'linux';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
// a version which is not in the manifest but is in node dist
|
||||||
|
let versionSpec = '12';
|
||||||
|
|
||||||
|
inputs['node-version'] = versionSpec;
|
||||||
|
inputs['check-latest'] = 'true';
|
||||||
|
inputs['always-auth'] = false;
|
||||||
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
|
// ... but not in the local cache
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
getManifestSpy.mockImplementation(() => {
|
||||||
|
throw new Error('Unable to download manifest');
|
||||||
|
});
|
||||||
|
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
let toolPath = path.normalize('/cache/node/12.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(
|
||||||
|
'Attempt to resolve the latest version from manifest...'
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
'Unable to resolve version from manifest...'
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Failed to resolve version ${versionSpec} from manifest`
|
||||||
|
);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Attempting to download ${versionSpec}...`
|
||||||
|
);
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,9 @@ inputs:
|
|||||||
default: 'false'
|
default: 'false'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
|
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
|
||||||
|
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
|
||||||
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:
|
||||||
|
22585
dist/index.js
vendored
22585
dist/index.js
vendored
File diff suppressed because one or more lines are too long
27
package-lock.json
generated
27
package-lock.json
generated
@ -10,9 +10,9 @@
|
|||||||
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg=="
|
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg=="
|
||||||
},
|
},
|
||||||
"@actions/exec": {
|
"@actions/exec": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.4.tgz",
|
||||||
"integrity": "sha512-TogJGnueOmM7ntCi0ASTUj4LapRRtDfj57Ja4IhPmg2fls28uVOPbAn8N+JifaOumN2UG3oEO/Ixek2A4NcYSA==",
|
"integrity": "sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/io": "^1.0.1"
|
"@actions/io": "^1.0.1"
|
||||||
}
|
}
|
||||||
@ -40,11 +40,11 @@
|
|||||||
"integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg=="
|
"integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg=="
|
||||||
},
|
},
|
||||||
"@actions/tool-cache": {
|
"@actions/tool-cache": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.5.4.tgz",
|
||||||
"integrity": "sha512-40A1St0GEo+QvHV1YRjStEoQcKKMaip+zNXPgGHcjYXCdZ7cl1LGlwOpsVVqwk+6ue/shFTS76KC1A02mVVCQA==",
|
"integrity": "sha512-72ijIBM0s/dx2D0eYYxaxaeKWeVatOK8OHPNctJ5cyKjZp1j12egX+nW/N+tnQRNMVxTp9WjudZO5wizUBxC/w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/core": "^1.2.0",
|
"@actions/core": "^1.2.3",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.0",
|
||||||
"@actions/http-client": "^1.0.8",
|
"@actions/http-client": "^1.0.8",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.0.1",
|
||||||
@ -52,6 +52,11 @@
|
|||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@actions/core": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
|
||||||
|
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
|
||||||
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
||||||
@ -1418,10 +1423,10 @@
|
|||||||
"integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==",
|
"integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@zeit/ncc": {
|
"@vercel/ncc": {
|
||||||
"version": "0.21.0",
|
"version": "0.23.0",
|
||||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz",
|
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.23.0.tgz",
|
||||||
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==",
|
"integrity": "sha512-Fcr1qlG9t54X4X9qbo/+jr1+t5Qc6H3TgIRBXmKkF/WDs6YFulAN6ilq2Ehx38RbgIOFxaZnjlAQ50GyexnMpQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"abab": {
|
"abab": {
|
||||||
|
@ -24,17 +24,18 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.2",
|
"@actions/core": "^1.2.2",
|
||||||
|
"@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.2",
|
"@actions/tool-cache": "^1.5.4",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.13",
|
"@types/jest": "^24.0.13",
|
||||||
"@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",
|
"@vercel/ncc": "^0.23.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"jest-circus": "^24.7.1",
|
"jest-circus": "^24.7.1",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
|
113
src/installer.ts
113
src/installer.ts
@ -6,7 +6,7 @@ import * as io from '@actions/io';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import {Url} from 'url';
|
import fs = require('fs');
|
||||||
|
|
||||||
//
|
//
|
||||||
// Node versions interface
|
// Node versions interface
|
||||||
@ -19,7 +19,6 @@ export interface INodeVersion {
|
|||||||
|
|
||||||
interface INodeVersionInfo {
|
interface INodeVersionInfo {
|
||||||
downloadUrl: string;
|
downloadUrl: string;
|
||||||
token: string | null;
|
|
||||||
resolvedVersion: string;
|
resolvedVersion: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
}
|
}
|
||||||
@ -27,40 +26,82 @@ interface INodeVersionInfo {
|
|||||||
export async function getNode(
|
export async function getNode(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
token: string
|
checkLatest: boolean,
|
||||||
|
auth: string | undefined
|
||||||
) {
|
) {
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = translateArchToDistUrl(os.arch());
|
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 info: INodeVersionInfo | null = null;
|
|
||||||
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) {
|
||||||
console.log(`Found in cache @ ${toolPath}`);
|
core.info(`Found in cache @ ${toolPath}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Attempting to download ${versionSpec}...`);
|
core.info(`Attempting to download ${versionSpec}...`);
|
||||||
let info = await getInfoFromManifest(versionSpec, stable, token);
|
let downloadPath = '';
|
||||||
if (!info) {
|
let info: INodeVersionInfo | null = null;
|
||||||
console.log(
|
|
||||||
|
//
|
||||||
|
// Try download from internal distribution (popular versions only)
|
||||||
|
//
|
||||||
|
try {
|
||||||
|
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'
|
'Not found in manifest. Falling back to download directly from Node'
|
||||||
);
|
);
|
||||||
info = await getInfoFromDist(versionSpec);
|
}
|
||||||
|
} 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) {
|
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}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
||||||
|
|
||||||
let downloadPath = '';
|
|
||||||
try {
|
try {
|
||||||
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, token);
|
downloadPath = await tc.downloadTool(info.downloadUrl);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
||||||
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
|
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
|
||||||
@ -68,22 +109,36 @@ export async function getNode(
|
|||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Extract
|
// Extract
|
||||||
//
|
//
|
||||||
|
core.info('Extracting ...');
|
||||||
let extPath: string;
|
let extPath: string;
|
||||||
|
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
|
||||||
if (osPlat == 'win32') {
|
if (osPlat == 'win32') {
|
||||||
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
|
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
|
||||||
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
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 {
|
} else {
|
||||||
extPath = await tc.extractTar(downloadPath);
|
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
|
// 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);
|
toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion);
|
||||||
|
core.info('Done');
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -103,15 +158,15 @@ export async function getNode(
|
|||||||
async function getInfoFromManifest(
|
async function getInfoFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
token: string
|
auth: string | undefined
|
||||||
): Promise<INodeVersionInfo | null> {
|
): Promise<INodeVersionInfo | null> {
|
||||||
let info: INodeVersionInfo | null = null;
|
let info: INodeVersionInfo | null = null;
|
||||||
const releases = await tc.getManifestFromRepo(
|
const releases = await tc.getManifestFromRepo(
|
||||||
'actions',
|
'actions',
|
||||||
'node-versions',
|
'node-versions',
|
||||||
token
|
auth,
|
||||||
|
'main'
|
||||||
);
|
);
|
||||||
console.log(`matching ${versionSpec}...`);
|
|
||||||
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
||||||
|
|
||||||
if (rel && rel.files.length > 0) {
|
if (rel && rel.files.length > 0) {
|
||||||
@ -119,7 +174,6 @@ async function getInfoFromManifest(
|
|||||||
info.resolvedVersion = rel.version;
|
info.resolvedVersion = rel.version;
|
||||||
info.downloadUrl = rel.files[0].download_url;
|
info.downloadUrl = rel.files[0].download_url;
|
||||||
info.fileName = rel.files[0].filename;
|
info.fileName = rel.files[0].filename;
|
||||||
info.token = token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
@ -131,7 +185,6 @@ async function getInfoFromDist(
|
|||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = translateArchToDistUrl(os.arch());
|
let osArch: string = translateArchToDistUrl(os.arch());
|
||||||
|
|
||||||
let info: INodeVersionInfo | null = null;
|
|
||||||
let version: string;
|
let version: string;
|
||||||
|
|
||||||
version = await queryDistForMatch(versionSpec);
|
version = await queryDistForMatch(versionSpec);
|
||||||
@ -158,6 +211,20 @@ async function getInfoFromDist(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
function evaluateVersions(versions: string[], versionSpec: string): string {
|
function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||||
let version = '';
|
let version = '';
|
||||||
@ -262,6 +329,8 @@ 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);
|
||||||
@ -279,7 +348,9 @@ async function acquireNodeFromFallbackLocation(
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await tc.cacheDir(tempDir, 'node', version);
|
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 does not always match the relative download url, e.g.
|
||||||
|
14
src/main.ts
14
src/main.ts
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||||||
import * as installer from './installer';
|
import * as installer from './installer';
|
||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import {URL} from 'url';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
@ -14,11 +15,13 @@ export async function run() {
|
|||||||
version = core.getInput('version');
|
version = core.getInput('version');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`version: ${version}`);
|
|
||||||
if (version) {
|
if (version) {
|
||||||
let token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
|
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||||
await installer.getNode(version, stable, token);
|
const checkLatest =
|
||||||
|
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||||
|
await installer.getNode(version, stable, checkLatest, auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
const registryUrl: string = core.getInput('registry-url');
|
const registryUrl: string = core.getInput('registry-url');
|
||||||
@ -39,3 +42,10 @@ export async function run() {
|
|||||||
core.setFailed(error.message);
|
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';
|
||||||
|
}
|
||||||
|
@ -13,7 +13,7 @@ rm -rf ./node
|
|||||||
export RUNNER_TOOL_CACHE=$(pwd)
|
export RUNNER_TOOL_CACHE=$(pwd)
|
||||||
export RUNNER_TEMP="${RUNNER_TOOL_CACHE}/temp"
|
export RUNNER_TEMP="${RUNNER_TOOL_CACHE}/temp"
|
||||||
export INPUT_STABLE=true
|
export INPUT_STABLE=true
|
||||||
export INPUT_VERSION="12.x"
|
export INPUT_VERSION="12" #"0.12.7" #"12" #"11.15.0"
|
||||||
# export your PAT with repo scope before running
|
# export your PAT with repo scope before running
|
||||||
export INPUT_TOKEN=$GITHUB_TOKEN
|
export INPUT_TOKEN=$GITHUB_TOKEN
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user