mirror of
https://github.com/actions/setup-node.git
synced 2025-04-24 12:22:12 +00:00
add ability to include both types of registries on complex repos
This commit is contained in:
parent
39ccff2929
commit
eff932eb37
2 changed files with 16 additions and 3 deletions
|
@ -11,6 +11,9 @@ inputs:
|
||||||
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'
|
||||||
|
include-both-registries:
|
||||||
|
description: 'Include both registry url and scoped'
|
||||||
|
default: 'false'
|
||||||
token:
|
token:
|
||||||
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
|
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user.
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
|
|
@ -43,6 +43,7 @@ async function getAuthToken(
|
||||||
const startIndex = body.indexOf('_auth') + 8;
|
const startIndex = body.indexOf('_auth') + 8;
|
||||||
const endIndex = body.indexOf('\n');
|
const endIndex = body.indexOf('\n');
|
||||||
const authToken = body.substring(startIndex, endIndex);
|
const authToken = body.substring(startIndex, endIndex);
|
||||||
|
console.log(authToken);
|
||||||
return authToken;
|
return authToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +92,20 @@ async function writeRegistryToFile(
|
||||||
/(^\w+:|^)/,
|
/(^\w+:|^)/,
|
||||||
''
|
''
|
||||||
)}:_authToken=${nodeAuthToken}`;
|
)}:_authToken=${nodeAuthToken}`;
|
||||||
|
|
||||||
|
const includeBothRegistries: string = core.getInput('include-both-registries');
|
||||||
const registryString: string = scope
|
const registryString: string = scope
|
||||||
? `${scope}:registry=${registryUrl}`
|
? `${scope}:registry=${registryUrl}`
|
||||||
: `registry=${registryUrl}`;
|
: `registry=${registryUrl}`;
|
||||||
|
|
||||||
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
|
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
|
||||||
|
if(scope && includeBothRegistries) {
|
||||||
|
const registryStringNoScope = `registry=${registryUrl}`;
|
||||||
|
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${registryStringNoScope}${os.EOL}${alwaysAuthString}`;
|
||||||
|
} else {
|
||||||
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue