mirror of
https://gitea.com/actions/setup-node.git
synced 2024-11-24 19:19:32 +01:00
feature: support Azure DevOps Artifacts
This commit is contained in:
parent
5b32c9063c
commit
38c86467c6
2 changed files with 21 additions and 6 deletions
|
@ -4,7 +4,11 @@ import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
export function configAuthentication(registryUrl: string, alwaysAuth: string) {
|
export function configAuthentication(
|
||||||
|
registryUrl: string,
|
||||||
|
alwaysAuth: string,
|
||||||
|
username?: 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'
|
||||||
|
@ -13,13 +17,14 @@ export function configAuthentication(registryUrl: string, alwaysAuth: string) {
|
||||||
registryUrl += '/';
|
registryUrl += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
|
writeRegistryToFile(registryUrl, npmrc, alwaysAuth, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeRegistryToFile(
|
function writeRegistryToFile(
|
||||||
registryUrl: string,
|
registryUrl: string,
|
||||||
fileLocation: string,
|
fileLocation: string,
|
||||||
alwaysAuth: string
|
alwaysAuth: string,
|
||||||
|
username?: string
|
||||||
) {
|
) {
|
||||||
let scope: string = core.getInput('scope');
|
let scope: string = core.getInput('scope');
|
||||||
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
||||||
|
@ -44,8 +49,17 @@ function writeRegistryToFile(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove http: or https: from front of registry.
|
// Remove http: or https: from front of registry.
|
||||||
const authString: string =
|
const registryPrefix = registryUrl.replace(/(^\w+:|^)/, '');
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
|
||||||
|
if (username) {
|
||||||
|
newContents += registryPrefix + `:_username=${username}${os.EOL}`;
|
||||||
|
newContents += registryPrefix + `:_email=dummy value`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const authString: string = username
|
||||||
|
? registryPrefix + ':_password=${NODE_AUTH_TOKEN}'
|
||||||
|
: registryPrefix + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||||
|
|
||||||
const registryString = `${scope}registry=${registryUrl}`;
|
const registryString = `${scope}registry=${registryUrl}`;
|
||||||
const alwaysAuthString = `always-auth=${alwaysAuth}`;
|
const alwaysAuthString = `always-auth=${alwaysAuth}`;
|
||||||
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
||||||
|
|
|
@ -55,8 +55,9 @@ export async function run() {
|
||||||
|
|
||||||
const registryUrl: string = core.getInput('registry-url');
|
const registryUrl: string = core.getInput('registry-url');
|
||||||
const alwaysAuth: string = core.getInput('always-auth');
|
const alwaysAuth: string = core.getInput('always-auth');
|
||||||
|
const username: string | undefined = core.getInput('username');
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
|
|
Loading…
Reference in a new issue