setup-node/src/authutil.ts

30 lines
895 B
TypeScript
Raw Normal View History

2019-08-05 11:46:12 -04:00
import * as core from '@actions/core';
2019-08-05 11:35:39 -04:00
import * as path from 'path';
2019-08-05 11:44:04 -04:00
import * as exec from '@actions/exec';
2019-08-05 11:35:39 -04:00
2019-08-05 11:44:04 -04:00
export async function configAuth(registryUrl: string) {
2019-08-05 11:35:39 -04:00
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
2019-08-05 11:46:12 -04:00
await writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
// writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
2019-08-05 11:35:39 -04:00
}
2019-08-05 11:44:04 -04:00
async function writeRegistryToFile(
2019-08-05 11:35:39 -04:00
registryUrl: string,
2019-08-05 11:44:04 -04:00
packageManager: string,
2019-08-05 11:35:39 -04:00
authTokenName: string
) {
2019-08-05 11:46:12 -04:00
core.debug(`Setting up ${packageManager} auth`);
2019-08-05 11:44:04 -04:00
await exec.exec(`${packageManager} config set registry=${registryUrl}`);
await exec.exec(`${packageManager} config set always-auth=true`);
await exec.exec(
packageManager +
' config set ' +
registryUrl.replace(/(^\w+:|^)/, '') +
':_authToken ${' +
authTokenName +
'}'
);
2019-08-05 11:35:39 -04:00
}