1
0
mirror of https://github.com/actions/setup-node.git synced 2025-12-17 22:38:59 +08:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Ross Brodbeck
94d165561a Change zeit -> vercel due to name change 2020-08-21 08:14:05 -04:00
71 changed files with 11523 additions and 11847 deletions

5
.gitattributes vendored
View File

@@ -1,5 +0,0 @@
# Set default behavior to automatically normalize line endings, and force everything to be LF, except for Windows batch files that require CRLF, so that if a repo is accessed in Unix via a file share from Windows, the scripts will work.
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
.licenses/** -diff linguist-generated=true

View File

@@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci

View File

@@ -1,20 +0,0 @@
name: Licensed
on:
push: {branches: main}
pull_request: {branches: main}
jobs:
test:
runs-on: ubuntu-latest
name: Check licenses
steps:
- uses: actions/checkout@v2
- run: npm ci
- name: Install licensed
run: |
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status

View File

@@ -96,17 +96,4 @@ jobs:
node-version: 0.12.18
- name: Verify node
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
shell: bash
arch:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup node 12 x86 from dist
uses: ./
with:
node-version: '12'
architecture: 'x86'
- name: Verify node
run: __tests__/verify-arch.sh "ia32"
shell: bash

View File

@@ -1,14 +0,0 @@
sources:
npm: true
allowed:
- apache-2.0
- bsd-2-clause
- bsd-3-clause
- isc
- mit
- cc0-1.0
- unlicense
reviewed:
npm:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
* @actions/spark

View File

@@ -10,14 +10,14 @@ This action sets by node environment for use in actions by:
- registering problem matchers for error output
- configuring authentication for GPR or npm
# v2
# v2-beta
This release adds reliability for pulling node distributions from a cache of node releases.
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
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
```
@@ -34,7 +34,7 @@ Basic:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: npm install
@@ -67,73 +67,18 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
```
Architecture:
You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
When using `architecture`, `node-version` must be provided as well.
```yaml
jobs:
build:
runs-on: windows-latest
name: Node sample
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '12'
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
- run: npm install
- run: npm test
```
Multiple Operating Systems and Architectures:
```yaml
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
node_version:
- 10
- 12
- 14
architecture:
- x64
# an extra windows-x86 run:
include:
- os: windows-2016
node_version: 12
architecture: x86
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
architecture: ${{ matrix.architecture }}
- run: npm install
- run: npm test
```
Publish to npmjs and GPR with npm:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://registry.npmjs.org'
@@ -141,7 +86,7 @@ steps:
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
registry-url: 'https://npm.pkg.github.com'
- run: npm publish
@@ -153,7 +98,7 @@ Publish to npmjs and GPR with yarn:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: <registry url>
@@ -161,7 +106,7 @@ steps:
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
registry-url: 'https://npm.pkg.github.com'
- run: yarn publish
@@ -173,7 +118,7 @@ Use private packages:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://registry.npmjs.org'

View File

@@ -20,8 +20,6 @@ describe('authutil tests', () => {
.toString(36)
.substring(7)
);
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
const tempDir = path.join(_runnerDir, randPath, 'temp');
await io.rmRF(tempDir);
await io.mkdirP(tempDir);
@@ -63,7 +61,6 @@ describe('authutil tests', () => {
if (_runnerDir) {
await io.rmRF(_runnerDir);
}
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
}, 100000);
function readRcFile(rcFile: string) {
@@ -123,13 +120,4 @@ describe('authutil tests', () => {
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(rc['always-auth']).toBe('true');
});
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
process.env.NODE_AUTH_TOKEN = 'foobar';
await auth.configAuthentication('npm.pkg.github.com', 'false');
expect(fs.statSync(rcFile)).toBeDefined();
let rc = readRcFile(rcFile);
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
expect(rc['always-auth']).toBe('false');
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
});
});

View File

@@ -42,8 +42,6 @@ describe('setup-node', () => {
beforeEach(() => {
// @actions/core
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
inputs = {};
inSpy = jest.spyOn(core, 'getInput');
inSpy.mockImplementation(name => inputs[name]);
@@ -104,9 +102,7 @@ describe('setup-node', () => {
//jest.restoreAllMocks();
});
afterAll(async () => {
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
}, 100000);
afterAll(async () => {}, 100000);
//--------------------------------------------------
// Manifest find tests
@@ -252,7 +248,7 @@ describe('setup-node', () => {
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${resolvedVersion} - ${os.arch} from ${expectedUrl}`
`Acquiring ${resolvedVersion} from ${expectedUrl}`
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
@@ -341,46 +337,6 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
});
it('Acquires specified architecture of node', async () => {
for (const {arch, version, osSpec} of [
{arch: 'x86', version: '12.16.2', osSpec: 'win32'},
{arch: 'x86', version: '14.0.0', osSpec: 'win32'}
]) {
os.platform = osSpec;
os.arch = arch;
const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz';
const platform = {
linux: 'linux',
darwin: 'darwin',
win32: 'win'
}[os.platform];
inputs['node-version'] = version;
inputs['architecture'] = arch;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
let expectedUrl =
arch === 'x64'
? `https://github.com/actions/node-versions/releases/download/${version}/node-${version}-${platform}-${arch}.zip`
: `https://nodejs.org/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;
// ... but not in the local cache
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize(`/cache/node/${version}/${arch}`);
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(dlSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${version} - ${arch} from ${expectedUrl}`
);
}
}, 100000);
describe('check-latest flag', () => {
it('use local version and dont check manifest if check-latest is not specified', async () => {
os.platform = 'linux';
@@ -443,7 +399,7 @@ describe('setup-node', () => {
);
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
`Acquiring 12.16.2 from ${expectedUrl}`
);
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
});

View File

@@ -1,11 +0,0 @@
#!/bin/sh
if [ -n "$1" ]; then
architecture="$(node -e 'console.log(process.arch)')"
if [ -z "$(echo $architecture | grep --fixed-strings $1)" ]; then
echo "Unexpected architecture"
exit 1
fi
else
echo "Skip testing architecture"
fi

View File

@@ -7,8 +7,6 @@ inputs:
default: 'false'
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
default: false

23055
dist/index.js vendored

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View File

@@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz",
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg=="
},
"@actions/exec": {
"version": "1.0.4",
@@ -1423,10 +1423,10 @@
"integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==",
"dev": true
},
"@zeit/ncc": {
"version": "0.21.0",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz",
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==",
"@vercel/ncc": {
"version": "0.23.0",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.23.0.tgz",
"integrity": "sha512-Fcr1qlG9t54X4X9qbo/+jr1+t5Qc6H3TgIRBXmKkF/WDs6YFulAN6ilq2Ehx38RbgIOFxaZnjlAQ50GyexnMpQ==",
"dev": true
},
"abab": {

View File

@@ -23,7 +23,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/core": "^1.2.2",
"@actions/exec": "^1.0.3",
"@actions/github": "^1.1.0",
"@actions/http-client": "^1.0.6",
@@ -35,7 +35,7 @@
"@types/jest": "^24.0.13",
"@types/node": "^12.0.4",
"@types/semver": "^6.0.0",
"@zeit/ncc": "^0.21.0",
"@vercel/ncc": "^0.23.0",
"jest": "^24.9.0",
"jest-circus": "^24.7.1",
"prettier": "^1.19.1",

View File

@@ -53,9 +53,6 @@ function writeRegistryToFile(
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
core.exportVariable(
'NODE_AUTH_TOKEN',
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
);
// Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
}

View File

@@ -20,7 +20,6 @@ export interface INodeVersion {
interface INodeVersionInfo {
downloadUrl: string;
resolvedVersion: string;
arch: string;
fileName: string;
}
@@ -28,19 +27,17 @@ export async function getNode(
versionSpec: string,
stable: boolean,
checkLatest: boolean,
auth: string | undefined,
arch: string = os.arch()
auth: string | undefined
) {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(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,
osArch
auth
);
if (resolvedVersion) {
versionSpec = resolvedVersion;
@@ -52,7 +49,7 @@ export async function getNode(
// check cache
let toolPath: string;
toolPath = tc.find('node', versionSpec, osArch);
toolPath = tc.find('node', versionSpec);
// If not found in cache, download
if (toolPath) {
@@ -66,11 +63,9 @@ export async function getNode(
// Try download from internal distribution (popular versions only)
//
try {
info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
info = await getInfoFromManifest(versionSpec, stable, auth);
if (info) {
core.info(
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
);
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
} else {
core.info(
@@ -97,24 +92,19 @@ export async function getNode(
// Download from nodejs.org
//
if (!downloadPath) {
info = await getInfoFromDist(versionSpec, arch);
info = await getInfoFromDist(versionSpec);
if (!info) {
throw new Error(
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
);
}
core.info(
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
);
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
try {
downloadPath = await tc.downloadTool(info.downloadUrl);
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return await acquireNodeFromFallbackLocation(
info.resolvedVersion,
info.arch
);
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
}
throw err;
@@ -147,12 +137,7 @@ export async function getNode(
// 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,
info.arch
);
toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion);
core.info('Done');
}
@@ -173,8 +158,7 @@ export async function getNode(
async function getInfoFromManifest(
versionSpec: string,
stable: boolean,
auth: string | undefined,
osArch: string = translateArchToDistUrl(os.arch())
auth: string | undefined
): Promise<INodeVersionInfo | null> {
let info: INodeVersionInfo | null = null;
const releases = await tc.getManifestFromRepo(
@@ -183,12 +167,11 @@ async function getInfoFromManifest(
auth,
'main'
);
const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch);
const rel = await tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) {
info = <INodeVersionInfo>{};
info.resolvedVersion = rel.version;
info.arch = rel.files[0].arch;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}
@@ -197,15 +180,14 @@ async function getInfoFromManifest(
}
async function getInfoFromDist(
versionSpec: string,
arch: string = os.arch()
versionSpec: string
): Promise<INodeVersionInfo | null> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch);
let osArch: string = translateArchToDistUrl(os.arch());
let version: string;
version = await queryDistForMatch(versionSpec, arch);
version = await queryDistForMatch(versionSpec);
if (!version) {
return null;
}
@@ -225,7 +207,6 @@ async function getInfoFromDist(
return <INodeVersionInfo>{
downloadUrl: url,
resolvedVersion: version,
arch: arch,
fileName: fileName
};
}
@@ -233,11 +214,10 @@ async function getInfoFromDist(
async function resolveVersionFromManifest(
versionSpec: string,
stable: boolean,
auth: string | undefined,
osArch: string = translateArchToDistUrl(os.arch())
auth: string | undefined
): Promise<string | undefined> {
try {
const info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
const info = await getInfoFromManifest(versionSpec, stable, auth);
return info?.resolvedVersion;
} catch (err) {
core.info('Unable to resolve version from manifest...');
@@ -273,12 +253,9 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
return version;
}
async function queryDistForMatch(
versionSpec: string,
arch: string = os.arch()
): Promise<string> {
async function queryDistForMatch(versionSpec: string): Promise<string> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch);
let osArch: string = translateArchToDistUrl(os.arch());
// node offers a json list of versions
let dataFileName: string;
@@ -334,11 +311,10 @@ export async function getVersionsFromDist(): Promise<INodeVersion[]> {
// Note also that the files are normally zipped but in this case they are just an exe
// and lib file in a folder, not zipped.
async function acquireNodeFromFallbackLocation(
version: string,
arch: string = os.arch()
version: string
): Promise<string> {
let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch);
let osArch: string = translateArchToDistUrl(os.arch());
// Create temporary folder to download in to
const tempDownloadFolder: string =
@@ -372,7 +348,7 @@ async function acquireNodeFromFallbackLocation(
throw err;
}
}
let toolPath = await tc.cacheDir(tempDir, 'node', version, arch);
let toolPath = await tc.cacheDir(tempDir, 'node', version);
core.addPath(toolPath);
return toolPath;
}

View File

@@ -3,7 +3,6 @@ import * as installer from './installer';
import * as auth from './authutil';
import * as path from 'path';
import {URL} from 'url';
import os = require('os');
export async function run() {
try {
@@ -16,27 +15,13 @@ export async function run() {
version = core.getInput('version');
}
let arch = core.getInput('architecture');
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
core.warning(
'`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
);
}
if (!arch) {
arch = os.arch();
}
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, arch);
await installer.getNode(version, stable, checkLatest, auth);
}
const registryUrl: string = core.getInput('registry-url');