Compare commits
19 Commits
v1.1.1
...
ff5ec869e5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff5ec869e5 | ||
|
|
f20c85e5e5 | ||
|
|
da3e59948e | ||
|
|
3c9d73515f | ||
|
|
c09ef151f8 | ||
|
|
985b557393 | ||
|
|
1be350f27e | ||
|
|
6b65ca8e49 | ||
|
|
feb12fe291 | ||
|
|
a9f1343a9a | ||
|
|
920661f1be | ||
|
|
8e12aec29e | ||
|
|
f338d8591f | ||
|
|
9776256210 | ||
|
|
287437bd45 | ||
|
|
dd1cda5071 | ||
|
|
0930c1111e | ||
|
|
409b7dfb5b | ||
|
|
2b9c956517 |
30
README.md
30
README.md
@@ -1,9 +1,5 @@
|
|||||||
# setup-node
|
# setup-node
|
||||||
|
|
||||||
<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>
|
|
||||||
</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
|
||||||
@@ -19,7 +15,7 @@ steps:
|
|||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '10.x'
|
version: '10.x'
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
@@ -38,50 +34,38 @@ jobs:
|
|||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
version: ${{ matrix.node }}
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
Publish to npmjs and GPR with npm:
|
Set up auth with npm:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '10.x'
|
version: '10.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: <registry url>
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
|
||||||
- run: npm publish
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Publish to npmjs and GPR with yarn:
|
Set up auth with yarn:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: '10.x'
|
version: '10.x'
|
||||||
registry-url: <registry url>
|
registry-url: <registry url>
|
||||||
- run: npm install -g yarn
|
- run: npm install -g yarn
|
||||||
- run: yarn install
|
- run: yarn install
|
||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
|
||||||
- run: yarn publish
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
// 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/"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`installer tests Automatically configures GPR scope 1`] = `
|
|
||||||
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
|
|
||||||
@owner: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/"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`installer tests Sets up npmrc for npmjs 1`] = `
|
|
||||||
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
|
||||||
registry=https://registry.npmjs.org/"
|
|
||||||
`;
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
import io = require('@actions/io');
|
|
||||||
import fs = require('fs');
|
|
||||||
import path = require('path');
|
|
||||||
|
|
||||||
const tempDir = path.join(
|
|
||||||
__dirname,
|
|
||||||
'runner',
|
|
||||||
path.join(
|
|
||||||
Math.random()
|
|
||||||
.toString(36)
|
|
||||||
.substring(7)
|
|
||||||
),
|
|
||||||
'temp'
|
|
||||||
);
|
|
||||||
|
|
||||||
const rcFile = path.join(tempDir, '.npmrc');
|
|
||||||
|
|
||||||
process.env['GITHUB_REPOSITORY'] = 'owner/repo';
|
|
||||||
process.env['RUNNER_TEMP'] = tempDir;
|
|
||||||
import * as auth from '../src/authutil';
|
|
||||||
|
|
||||||
describe('installer tests', () => {
|
|
||||||
beforeAll(async () => {
|
|
||||||
await io.rmRF(tempDir);
|
|
||||||
await io.mkdirP(tempDir);
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
if (fs.existsSync(rcFile)) {
|
|
||||||
fs.unlinkSync(rcFile);
|
|
||||||
}
|
|
||||||
process.env['INPUT_SCOPE'] = '';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Sets up npmrc for npmjs', async () => {
|
|
||||||
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');
|
|
||||||
|
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Configures scoped npm registries', async () => {
|
|
||||||
process.env['INPUT_SCOPE'] = 'myScope';
|
|
||||||
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');
|
|
||||||
|
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -4,7 +4,7 @@ import os = require('os');
|
|||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
const toolDir = path.join(
|
const toolDir = path.join(
|
||||||
__dirname,
|
process.cwd(),
|
||||||
'runner',
|
'runner',
|
||||||
path.join(
|
path.join(
|
||||||
Math.random()
|
Math.random()
|
||||||
@@ -14,7 +14,7 @@ const toolDir = path.join(
|
|||||||
'tools'
|
'tools'
|
||||||
);
|
);
|
||||||
const tempDir = path.join(
|
const tempDir = path.join(
|
||||||
__dirname,
|
process.cwd(),
|
||||||
'runner',
|
'runner',
|
||||||
path.join(
|
path.join(
|
||||||
Math.random()
|
Math.random()
|
||||||
@@ -36,6 +36,15 @@ describe('installer tests', () => {
|
|||||||
await io.rmRF(tempDir);
|
await io.rmRF(tempDir);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
try {
|
||||||
|
await io.rmRF(toolDir);
|
||||||
|
await io.rmRF(tempDir);
|
||||||
|
} catch {
|
||||||
|
console.log('Failed to remove test directories');
|
||||||
|
}
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
it('Acquires version of node if no matching version is installed', async () => {
|
it('Acquires version of node if no matching version is installed', async () => {
|
||||||
await installer.getNode('10.16.0');
|
await installer.getNode('10.16.0');
|
||||||
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());
|
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());
|
||||||
|
|||||||
11
action.yml
11
action.yml
@@ -1,17 +1,14 @@
|
|||||||
name: 'Setup Node.js environment'
|
name: 'Setup Node.js for use with actions'
|
||||||
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
|
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
node-version:
|
version:
|
||||||
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
|
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0, lts'
|
||||||
default: '10.x'
|
default: '10.x'
|
||||||
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'
|
||||||
# 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'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'lib/setup-node.js'
|
main: 'lib/setup-node.js'
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ const path = __importStar(require("path"));
|
|||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const github = __importStar(require("@actions/github"));
|
const github = __importStar(require("@actions/github"));
|
||||||
function configAuthentication(registryUrl) {
|
function configAuthentication(registryUrl) {
|
||||||
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
|
// const npmrc: string = path.resolve(
|
||||||
if (!registryUrl.endsWith('/')) {
|
// process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
registryUrl += '/';
|
// '.npmrc'
|
||||||
}
|
// );
|
||||||
|
const npmrc = path.resolve(process.cwd(), '.npmrc');
|
||||||
writeRegistryToFile(registryUrl, npmrc);
|
writeRegistryToFile(registryUrl, npmrc);
|
||||||
}
|
}
|
||||||
exports.configAuthentication = configAuthentication;
|
exports.configAuthentication = configAuthentication;
|
||||||
@@ -44,9 +45,9 @@ function writeRegistryToFile(registryUrl, fileLocation) {
|
|||||||
const registryString = scope
|
const registryString = scope
|
||||||
? `${scope}:registry=${registryUrl}`
|
? `${scope}:registry=${registryUrl}`
|
||||||
: `registry=${registryUrl}`;
|
: `registry=${registryUrl}`;
|
||||||
newContents += `${authString}${os.EOL}${registryString}`;
|
newContents += `${registryString}${os.EOL}${authString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||||
// Export empty node_auth_token so npm doesn't complain about not being able to find it
|
// 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');
|
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ function run() {
|
|||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||||
//
|
//
|
||||||
let version = core.getInput('version');
|
const version = core.getInput('version');
|
||||||
if (!version) {
|
|
||||||
version = core.getInput('node-version');
|
|
||||||
}
|
|
||||||
if (version) {
|
if (version) {
|
||||||
// TODO: installer doesn't support proxy
|
// TODO: installer doesn't support proxy
|
||||||
yield installer.getNode(version);
|
yield installer.getNode(version);
|
||||||
|
|||||||
@@ -5,19 +5,17 @@ import * as core from '@actions/core';
|
|||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
export function configAuthentication(registryUrl: string) {
|
export function configAuthentication(registryUrl: string) {
|
||||||
const npmrc: string = path.resolve(
|
// const npmrc: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
// process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
'.npmrc'
|
// '.npmrc'
|
||||||
);
|
// );
|
||||||
if (!registryUrl.endsWith('/')) {
|
const npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
||||||
registryUrl += '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
writeRegistryToFile(registryUrl, npmrc);
|
writeRegistryToFile(registryUrl, npmrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||||
let scope: string = core.getInput('scope');
|
let scope = core.getInput('scope');
|
||||||
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
||||||
scope = github.context.repo.owner;
|
scope = github.context.repo.owner;
|
||||||
}
|
}
|
||||||
@@ -37,14 +35,14 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove http: or https: from front of registry.
|
// Remove http: or https: from front of registry.
|
||||||
const authString: string =
|
const authString =
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
registryUrl.replace(/(^\w+:|^)/, '') + `:_authToken=${NODE_AUTH_TOKEN}`;
|
||||||
const registryString: string = scope
|
const registryString = scope
|
||||||
? `${scope}:registry=${registryUrl}`
|
? `${scope}:registry=${registryUrl}`
|
||||||
: `registry=${registryUrl}`;
|
: `registry=${registryUrl}`;
|
||||||
newContents += `${authString}${os.EOL}${registryString}`;
|
newContents += `${registryString}${os.EOL}${authString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
// core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||||
// Export empty node_auth_token so npm doesn't complain about not being able to find it
|
// 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');
|
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ async function run() {
|
|||||||
// Version is optional. If supplied, install / use from the tool cache
|
// Version is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then task is still used to setup proxy, auth, etc...
|
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||||
//
|
//
|
||||||
let version = core.getInput('version');
|
const version = core.getInput('version');
|
||||||
if (!version) {
|
|
||||||
version = core.getInput('node-version');
|
|
||||||
}
|
|
||||||
if (version) {
|
if (version) {
|
||||||
// TODO: installer doesn't support proxy
|
// TODO: installer doesn't support proxy
|
||||||
await installer.getNode(version);
|
await installer.getNode(version);
|
||||||
|
|||||||
Reference in New Issue
Block a user