This commit is contained in:
Danny McCormick 2019-08-05 11:35:39 -04:00
parent 9bb7038a07
commit 2b9c956517
6 changed files with 113 additions and 0 deletions

39
src/authutil.ts Normal file
View file

@ -0,0 +1,39 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
export function configAuth(registryUrl: string) {
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
}
function writeRegistryToFile(
registryUrl: string,
fileLocation: string,
authTokenName: string
) {
let newContents = '';
if (fs.existsSync(fileLocation)) {
const curContents = fs.readFileSync(fileLocation, 'utf8');
curContents.split(os.EOL).forEach((line: string) => {
// Add current contents unless they are setting the registry
if (!line.startsWith('registry')) {
newContents += line + os.EOL;
}
});
}
newContents +=
'registry=' +
registryUrl +
os.EOL +
'always-auth=true' +
os.EOL +
registryUrl.replace(/(^\w+:|^)/, '') +
':_authToken=${' +
authTokenName +
'}';
fs.writeFileSync(fileLocation, newContents);
}

View file

@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as installer from './installer';
import * as auth from './authutil';
import * as path from 'path';
async function run() {
@ -14,6 +15,11 @@ async function run() {
await installer.getNode(version);
}
const registryUrl = core.getInput('registry-url');
if (registryUrl) {
auth.configAuth(registryUrl);
}
// TODO: setup proxy from runner proxy config
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);