Update
parent
dd1cda5071
commit
287437bd45
@ -1,29 +1,41 @@
|
|||||||
import * as core from '@actions/core';
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as exec from '@actions/exec';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
export async function configAuth(registryUrl: string) {
|
export function configAuth(registryUrl: string) {
|
||||||
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
||||||
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
|
||||||
|
|
||||||
await writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
|
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
|
||||||
// writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
|
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeRegistryToFile(
|
function writeRegistryToFile(
|
||||||
registryUrl: string,
|
registryUrl: string,
|
||||||
packageManager: string,
|
fileLocation: string,
|
||||||
authTokenName: string
|
authTokenName: string
|
||||||
) {
|
) {
|
||||||
core.debug(`Setting up ${packageManager} auth`);
|
core.debug(`Setting auth in ${fileLocation}`);
|
||||||
await exec.exec(`${packageManager} config set registry=${registryUrl}`);
|
let newContents = '';
|
||||||
await exec.exec(`${packageManager} config set always-auth=true`);
|
if (fs.existsSync(fileLocation)) {
|
||||||
await exec.exec(
|
const curContents = fs.readFileSync(fileLocation, 'utf8');
|
||||||
packageManager +
|
curContents.split(os.EOL).forEach((line: string) => {
|
||||||
' config set ' +
|
// Add current contents unless they are setting the registry
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') +
|
if (!line.startsWith('registry')) {
|
||||||
':_authToken ${' +
|
newContents += line + os.EOL;
|
||||||
authTokenName +
|
}
|
||||||
'}'
|
});
|
||||||
);
|
}
|
||||||
|
newContents +=
|
||||||
|
'registry=' +
|
||||||
|
registryUrl +
|
||||||
|
os.EOL +
|
||||||
|
'always-auth=true' +
|
||||||
|
os.EOL +
|
||||||
|
registryUrl.replace(/(^\w+:|^)/, '') +
|
||||||
|
':_authToken=${' +
|
||||||
|
authTokenName +
|
||||||
|
'}';
|
||||||
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue