1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2025-04-09 18:35:51 +00:00

Add setting for always-auth

- https://docs.npmjs.com/misc/config#always-auth
- Allow private repos for stuff like artifactory to work
This commit is contained in:
David J. Felix 2019-08-28 20:03:12 -04:00
parent 7af5963081
commit 9c950f557c
5 changed files with 33 additions and 10 deletions

View file

@ -2,6 +2,9 @@ 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'

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) {
function configAuthentication({ registryUrl, alwaysAuth }) {
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
if (!registryUrl.endsWith('/')) {
registryUrl += '/';
}
writeRegistryToFile(registryUrl, npmrc);
writeRegistryToFile({ registryUrl, fileLocation: npmrc, alwaysAuth });
}
exports.configAuthentication = configAuthentication;
function writeRegistryToFile(registryUrl, fileLocation) {
function writeRegistryToFile({ registryUrl, fileLocation, alwaysAuth }) {
let scope = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
@ -47,7 +47,8 @@ function writeRegistryToFile(registryUrl, fileLocation) {
const registryString = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
newContents += `${authString}${os.EOL}${registryString}`;
const alwaysAuthString = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
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

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

View file

@ -4,7 +4,14 @@ import * as path from 'path';
import * as core from '@actions/core';
import * as github from '@actions/github';
export function configAuthentication(registryUrl: string) {
interface ConfigureAuthenticationParams {
registryUrl: string;
alwaysAuth: string;
}
export function configAuthentication({
registryUrl,
alwaysAuth
}: ConfigureAuthenticationParams) {
const npmrc: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
'.npmrc'
@ -13,10 +20,19 @@ export function configAuthentication(registryUrl: string) {
registryUrl += '/';
}
writeRegistryToFile(registryUrl, npmrc);
writeRegistryToFile({registryUrl, fileLocation: npmrc, alwaysAuth});
}
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
interface WriteRegistryToFileParams {
registryUrl: string;
fileLocation: string;
alwaysAuth: string;
}
function writeRegistryToFile({
registryUrl,
fileLocation,
alwaysAuth
}: WriteRegistryToFileParams) {
let scope: string = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
@ -45,7 +61,8 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
const registryString: string = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
newContents += `${authString}${os.EOL}${registryString}`;
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
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

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