From 38c86467c6b882339ae5466d3e07686daa34055b Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Wed, 26 Apr 2023 22:09:30 +1000 Subject: [PATCH 1/5] feature: support Azure DevOps Artifacts --- src/authutil.ts | 24 +++++++++++++++++++----- src/main.ts | 3 ++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/authutil.ts b/src/authutil.ts index 2ce949393..04349be0f 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -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' @@ -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) { @@ -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`; + } + + 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}`; diff --git a/src/main.ts b/src/main.ts index 90cd1d9d9..73027197d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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()) { From 3352bc631c5bbc0b8a984135607386878aeb8be9 Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Wed, 26 Apr 2023 22:12:16 +1000 Subject: [PATCH 2/5] meta: add username input parameter --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index b22de1ef6..35dbc7dc5 100644 --- a/action.yml +++ b/action.yml @@ -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: + 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: From 2b65979b36b0b38a6cc541ede1025e3671754f47 Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Wed, 26 Apr 2023 22:18:16 +1000 Subject: [PATCH 3/5] add build --- dist/setup/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 9b813965b..2ae48da9e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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; @@ -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`; + } + 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}`; @@ -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'); From 952f7f9d8a67c272a81b18d365a462df99ece629 Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Wed, 26 Apr 2023 22:28:38 +1000 Subject: [PATCH 4/5] fix: EOL character on _email in username/password mode --- dist/setup/index.js | 2 +- package.json | 2 +- src/authutil.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2ae48da9e..b84366cad 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71083,7 +71083,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth, username) { const registryPrefix = registryUrl.replace(/(^\w+:|^)/, ''); if (username) { newContents += registryPrefix + `:_username=${username}${os.EOL}`; - newContents += registryPrefix + `:_email=dummy value`; + newContents += registryPrefix + `:_email=dummy value` + os.EOL; } const authString = username ? registryPrefix + ':_password=${NODE_AUTH_TOKEN}' diff --git a/package.json b/package.json index 89d2eaf88..e37003c5e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/authutil.ts b/src/authutil.ts index 04349be0f..ffac7d44f 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -53,7 +53,7 @@ function writeRegistryToFile( if (username) { newContents += registryPrefix + `:_username=${username}${os.EOL}`; - newContents += registryPrefix + `:_email=dummy value`; + newContents += registryPrefix + `:_email=dummy value` + os.EOL; } const authString: string = username From e6b1dcc8efa8646b11be8fec63691d369ff8bb8c Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Wed, 26 Apr 2023 22:57:11 +1000 Subject: [PATCH 5/5] fix: devOps identifier incorrect --- dist/setup/index.js | 4 ++-- src/authutil.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b84366cad..085872d8d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71082,8 +71082,8 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth, username) { // Remove http: or https: from front of registry. const registryPrefix = registryUrl.replace(/(^\w+:|^)/, ''); if (username) { - newContents += registryPrefix + `:_username=${username}${os.EOL}`; - newContents += registryPrefix + `:_email=dummy value` + os.EOL; + newContents += registryPrefix + `:username=${username}${os.EOL}`; + newContents += registryPrefix + `:email=dummy value` + os.EOL; } const authString = username ? registryPrefix + ':_password=${NODE_AUTH_TOKEN}' diff --git a/src/authutil.ts b/src/authutil.ts index ffac7d44f..cde3a8af5 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -52,8 +52,8 @@ function writeRegistryToFile( const registryPrefix = registryUrl.replace(/(^\w+:|^)/, ''); if (username) { - newContents += registryPrefix + `:_username=${username}${os.EOL}`; - newContents += registryPrefix + `:_email=dummy value` + os.EOL; + newContents += registryPrefix + `:username=${username}${os.EOL}`; + newContents += registryPrefix + `:email=dummy value` + os.EOL; } const authString: string = username