Compare commits

..

8 Commits

Author SHA1 Message Date
b6651e20e5 Merge pull request #88 from actions/arm-installer
Get correct url for arm dist
2019-11-25 10:31:44 -05:00
8de2f9fcbc Release from master 2019-08-21 22:58:23 -04:00
5273d0df9c Add auth 2019-08-06 18:29:44 -04:00
fc9ff49b90 Update version 2019-08-05 22:07:27 -04:00
552489ce4b Fix backup downloads 2019-08-05 22:05:24 -04:00
401832ee64 Update to 1.0.3 2019-08-05 16:51:20 -04:00
b0d4a002ac Update io 2019-08-05 16:49:04 -04:00
ea546c14bf Update package version 2019-08-05 15:42:48 -04:00
18 changed files with 73 additions and 186 deletions

90
.gitignore vendored
View File

@ -1,92 +1,2 @@
# Explicitly not ignoring node_modules so that they are included in package downloaded by runner
!node_modules/
__tests__/runner/*
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/

View File

@ -4,11 +4,10 @@
<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>
</p>
This action sets up a node environment for use in actions, including npm and yarn. It:
This action sets by node environment for use in actions by:
- sets up the specified version of node (downloading it if it's not already available)
- adds node, npm and yarn to the PATH
- registers problem matchers for error output
- optionally downloading and caching a version of node - npm by version spec and add to PATH
- registering problem matchers for error output
# Usage
@ -17,7 +16,7 @@ See [action.yml](action.yml)
Basic:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '10.x'
@ -35,7 +34,7 @@ jobs:
node: [ '10', '8' ]
name: Node ${{ matrix.node }} sample
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- name: Setup node
uses: actions/setup-node@v1
with:
@ -47,7 +46,7 @@ jobs:
Publish to npmjs and GPR with npm:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '10.x'
@ -67,11 +66,12 @@ steps:
Publish to npmjs and GPR with yarn:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: <registry url>
- run: npm install -g yarn
- run: yarn install
- run: yarn publish
env:
@ -84,24 +84,6 @@ steps:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Use private packages:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://registry.npmjs.org'
# Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN.
- run: npm install --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# `npm rebuild` will run all those post-install scritps for us.
- run: npm rebuild && npm run prepare --if-present
```
# License
The scripts and documentation in this project are released under the [MIT License](LICENSE)

View File

@ -2,30 +2,20 @@
exports[`installer tests Appends trailing slash to registry 1`] = `
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
registry=https://registry.npmjs.org/
always-auth=false"
registry=https://registry.npmjs.org/"
`;
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"
@ownername:registry=npm.pkg.github.com/"
`;
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"
@myscope:registry=https://registry.npmjs.org/"
`;
exports[`installer tests Sets up npmrc for npmjs 1`] = `
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
registry=https://registry.npmjs.org/
always-auth=false"
registry=https://registry.npmjs.org/"
`;

View File

@ -33,13 +33,13 @@ describe('installer tests', () => {
});
it('Sets up npmrc for npmjs', async () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
await auth.configAuthentication('https://registry.npmjs.org/');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Appends trailing slash to registry', async () => {
await auth.configAuthentication('https://registry.npmjs.org', 'false');
await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
@ -47,22 +47,16 @@ describe('installer tests', () => {
it('Configures scoped npm registries', async () => {
process.env['INPUT_SCOPE'] = 'myScope';
await auth.configAuthentication('https://registry.npmjs.org', 'false');
await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Automatically configures GPR scope', async () => {
await auth.configAuthentication('npm.pkg.github.com', 'false');
await auth.configAuthentication('npm.pkg.github.com');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Sets up npmrc for always-auth true', async () => {
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
});

View File

@ -2,9 +2,6 @@ name: 'Setup Node.js environment'
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
author: 'GitHub'
inputs:
always-auth:
description: 'Set always-auth in npmrc'
default: 'false'
node-version:
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
default: '10.x'
@ -15,7 +12,6 @@ inputs:
# Deprecated option, do not use. Will not be supported after October 1, 2019
version:
description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019'
deprecationMessage: 'The version property will not be supported after October 1, 2019. Use node-version instead'
runs:
using: 'node12'
main: 'lib/setup-node.js'

View File

@ -12,15 +12,15 @@ const os = __importStar(require("os"));
const path = __importStar(require("path"));
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
function configAuthentication(registryUrl, alwaysAuth) {
function configAuthentication(registryUrl) {
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
if (!registryUrl.endsWith('/')) {
registryUrl += '/';
}
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
writeRegistryToFile(registryUrl, npmrc);
}
exports.configAuthentication = configAuthentication;
function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
function writeRegistryToFile(registryUrl, fileLocation) {
let scope = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
@ -47,8 +47,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
const registryString = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
const alwaysAuthString = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
newContents += `${authString}${os.EOL}${registryString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token so npm doesn't complain about not being able to find it

View File

@ -25,7 +25,7 @@ const os = __importStar(require("os"));
const path = __importStar(require("path"));
const semver = __importStar(require("semver"));
let osPlat = os.platform();
let osArch = os.arch();
let osArch = translateArchToDistUrl(os.arch());
if (!tempDirectory) {
let baseLocation;
if (process.platform === 'win32') {
@ -90,13 +90,13 @@ function queryLatestMatch(versionSpec) {
let dataFileName;
switch (osPlat) {
case 'linux':
dataFileName = 'linux-' + osArch;
dataFileName = `linux-${osArch}`;
break;
case 'darwin':
dataFileName = 'osx-' + osArch + '-tar';
dataFileName = `osx-${osArch}-tar`;
break;
case 'win32':
dataFileName = 'win-' + osArch + '-exe';
dataFileName = `win-${osArch}-exe`;
break;
default:
throw new Error(`Unexpected OS '${osPlat}'`);
@ -149,10 +149,10 @@ function acquireNode(version) {
//
version = semver.clean(version) || '';
let fileName = osPlat == 'win32'
? 'node-v' + version + '-win-' + os.arch()
: 'node-v' + version + '-' + osPlat + '-' + os.arch();
let urlFileName = osPlat == 'win32' ? fileName + '.7z' : fileName + '.tar.gz';
let downloadUrl = 'https://nodejs.org/dist/v' + version + '/' + urlFileName;
? `node-v${version}-win-${osArch}`
: `node-v${version}-${osPlat}-${osArch}`;
let urlFileName = osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let downloadUrl = `https://nodejs.org/dist/v${version}/${urlFileName}`;
let downloadPath;
try {
downloadPath = yield tc.downloadTool(downloadUrl);
@ -202,8 +202,8 @@ function acquireNodeFromFallbackLocation(version) {
let exeUrl;
let libUrl;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = yield tc.downloadTool(libUrl);
@ -225,3 +225,13 @@ function acquireNodeFromFallbackLocation(version) {
return yield tc.cacheDir(tempDir, 'node', version);
});
}
// os.arch does not always match the relative download url, e.g.
// os.arch == 'arm' != node-v12.13.1-linux-armv7l.tar.gz
function translateArchToDistUrl(arch) {
switch (arch) {
case 'arm':
return 'armv7l';
default:
return arch;
}
}

View File

@ -35,9 +35,8 @@ function run() {
yield installer.getNode(version);
}
const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
auth.configAuthentication(registryUrl);
}
// TODO: setup proxy from runner proxy config
const matchersPath = path.join(__dirname, '..', '.github');

6
package-lock.json generated
View File

@ -3628,9 +3628,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
"dev": true
},
"lodash.get": {

View File

@ -4,7 +4,7 @@ import * as path from 'path';
import * as core from '@actions/core';
import * as github from '@actions/github';
export function configAuthentication(registryUrl: string, alwaysAuth: string) {
export function configAuthentication(registryUrl: string) {
const npmrc: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
'.npmrc'
@ -13,14 +13,10 @@ export function configAuthentication(registryUrl: string, alwaysAuth: string) {
registryUrl += '/';
}
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
writeRegistryToFile(registryUrl, npmrc);
}
function writeRegistryToFile(
registryUrl: string,
fileLocation: string,
alwaysAuth: string
) {
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
let scope: string = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
@ -49,8 +45,7 @@ function writeRegistryToFile(
const registryString: string = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
newContents += `${authString}${os.EOL}${registryString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token so npm doesn't complain about not being able to find it

View File

@ -9,7 +9,7 @@ import * as path from 'path';
import * as semver from 'semver';
let osPlat: string = os.platform();
let osArch: string = os.arch();
let osArch: string = translateArchToDistUrl(os.arch());
if (!tempDirectory) {
let baseLocation;
@ -86,13 +86,13 @@ async function queryLatestMatch(versionSpec: string): Promise<string> {
let dataFileName: string;
switch (osPlat) {
case 'linux':
dataFileName = 'linux-' + osArch;
dataFileName = `linux-${osArch}`;
break;
case 'darwin':
dataFileName = 'osx-' + osArch + '-tar';
dataFileName = `osx-${osArch}-tar`;
break;
case 'win32':
dataFileName = 'win-' + osArch + '-exe';
dataFileName = `win-${osArch}-exe`;
break;
default:
throw new Error(`Unexpected OS '${osPlat}'`);
@ -150,12 +150,11 @@ async function acquireNode(version: string): Promise<string> {
version = semver.clean(version) || '';
let fileName: string =
osPlat == 'win32'
? 'node-v' + version + '-win-' + os.arch()
: 'node-v' + version + '-' + osPlat + '-' + os.arch();
? `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;
osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let downloadUrl = `https://nodejs.org/dist/v${version}/${urlFileName}`;
let downloadPath: string;
@ -210,8 +209,8 @@ async function acquireNodeFromFallbackLocation(
let exeUrl: string;
let libUrl: string;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));
@ -232,3 +231,17 @@ async function acquireNodeFromFallbackLocation(
}
return await tc.cacheDir(tempDir, 'node', version);
}
// os.arch does not always match the relative download url, e.g.
// os.arch == 'arm' != node-v12.13.1-linux-armv7l.tar.gz
// All other currently supported architectures match, e.g.:
// os.arch = arm64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-arm64.tar.gz
// os.arch = x64 => https://nodejs.org/dist/v{VERSION}/node-v{VERSION}-{OS}-x64.tar.gz
function translateArchToDistUrl(arch: string): string {
switch (arch) {
case 'arm':
return 'armv7l';
default:
return arch;
}
}

View File

@ -19,9 +19,8 @@ async function run() {
}
const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
auth.configAuthentication(registryUrl);
}
// TODO: setup proxy from runner proxy config

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.