Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure DevOps Artifacts support for registry-url #746

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -25,6 +25,8 @@ inputs:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
cache-dependency-path:
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
username:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would suggest adding an explicit password value too, instead of doubling up on authToken as they are very much not one and the same.

description: 'Used to specify username/password authentication for NPM, used for Azure DevOps Artifacts and registries which expect a username and password.'
# TODO: add input to control forcing to pull from cloud or dist.
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
outputs:
Expand Down
18 changes: 13 additions & 5 deletions dist/setup/index.js
Expand Up @@ -71049,15 +71049,15 @@ const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017));
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
function configAuthentication(registryUrl, alwaysAuth) {
function configAuthentication(registryUrl, alwaysAuth, username) {
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
if (!registryUrl.endsWith('/')) {
registryUrl += '/';
}
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
writeRegistryToFile(registryUrl, npmrc, alwaysAuth, username);
}
exports.configAuthentication = configAuthentication;
function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth, username) {
let scope = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
Expand All @@ -71080,7 +71080,14 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
});
}
// Remove http: or https: from front of registry.
const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryPrefix = registryUrl.replace(/(^\w+:|^)/, '');
if (username) {
newContents += registryPrefix + `:username=${username}${os.EOL}`;
newContents += registryPrefix + `:email=dummy value` + os.EOL;
}
const authString = username
? registryPrefix + ':_password=${NODE_AUTH_TOKEN}'
: registryPrefix + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString = `${scope}registry=${registryUrl}`;
const alwaysAuthString = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
Expand Down Expand Up @@ -72084,8 +72091,9 @@ function run() {
yield util_1.printEnvDetailsAndSetOutput();
const registryUrl = core.getInput('registry-url');
const alwaysAuth = core.getInput('always-auth');
const username = core.getInput('username');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
auth.configAuthentication(registryUrl, alwaysAuth, username);
}
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
const cacheDependencyPath = core.getInput('cache-dependency-path');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/setup-node.git"
"url": "git+https://github.com/rapid-platform/setup-node.git"
},
"keywords": [
"actions",
Expand Down
24 changes: 19 additions & 5 deletions src/authutil.ts
Expand Up @@ -4,7 +4,11 @@ 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,
alwaysAuth: string,
username?: string
) {
const npmrc: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
'.npmrc'
Expand All @@ -13,13 +17,14 @@ export function configAuthentication(registryUrl: string, alwaysAuth: string) {
registryUrl += '/';
}

writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
writeRegistryToFile(registryUrl, npmrc, alwaysAuth, username);
}

function writeRegistryToFile(
registryUrl: string,
fileLocation: string,
alwaysAuth: string
alwaysAuth: string,
username?: string
) {
let scope: string = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
Expand All @@ -44,8 +49,17 @@ function writeRegistryToFile(
});
}
// Remove http: or https: from front of registry.
const authString: string =
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryPrefix = registryUrl.replace(/(^\w+:|^)/, '');

if (username) {
newContents += registryPrefix + `:username=${username}${os.EOL}`;
newContents += registryPrefix + `:email=dummy value` + os.EOL;
}

const authString: string = username
? registryPrefix + ':_password=${NODE_AUTH_TOKEN}'
: registryPrefix + ':_authToken=${NODE_AUTH_TOKEN}';

const registryString = `${scope}registry=${registryUrl}`;
const alwaysAuthString = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Expand Up @@ -55,8 +55,9 @@ export async function run() {

const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
const username: string | undefined = core.getInput('username');
if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth);
auth.configAuthentication(registryUrl, alwaysAuth, username);
}

if (cache && isCacheFeatureAvailable()) {
Expand Down