mirror of
https://github.com/actions/setup-node
synced 2025-04-09 02:15:52 +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'
|
||||
scope:
|
||||
description: 'Optional scope for authenticating against scoped registries'
|
||||
include-both-registries:
|
||||
description: 'Include both registry url and scoped'
|
||||
default: 'false'
|
||||
token:
|
||||
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 }}
|
||||
|
|
|
@ -43,6 +43,7 @@ async function getAuthToken(
|
|||
const startIndex = body.indexOf('_auth') + 8;
|
||||
const endIndex = body.indexOf('\n');
|
||||
const authToken = body.substring(startIndex, endIndex);
|
||||
console.log(authToken);
|
||||
return authToken;
|
||||
}
|
||||
|
||||
|
@ -91,11 +92,20 @@ async function writeRegistryToFile(
|
|||
/(^\w+:|^)/,
|
||||
''
|
||||
)}:_authToken=${nodeAuthToken}`;
|
||||
|
||||
const includeBothRegistries: string = core.getInput('include-both-registries');
|
||||
const registryString: string = scope
|
||||
? `${scope}:registry=${registryUrl}`
|
||||
: `registry=${registryUrl}`;
|
||||
? `${scope}:registry=${registryUrl}`
|
||||
: `registry=${registryUrl}`;
|
||||
|
||||
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
|
||||
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
|
||||
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}`;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue