1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-12-23 13:42:42 +00:00
This commit is contained in:
Danny McCormick 2019-08-05 13:12:37 -04:00
parent 8e12aec29e
commit 920661f1be
5 changed files with 15 additions and 18 deletions

View file

@ -61,7 +61,8 @@ steps:
with: with:
version: '10.x' version: '10.x'
registry-url: <registry url> registry-url: <registry url>
- run: npm install - run: npm install -g yarn
- run: yarn install
- run: yarn publish - run: yarn publish
env: env:
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}

View file

@ -11,13 +11,11 @@ const fs = __importStar(require("fs"));
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
function configAuth(registryUrl) { function configAuthentication(registryUrl) {
let npmrc = path.resolve(process.cwd(), '.npmrc'); const npmrc = path.resolve(process.cwd(), '.npmrc');
let yarnrc = path.resolve(process.cwd(), '.yarnrc');
writeRegistryToFile(registryUrl, npmrc); writeRegistryToFile(registryUrl, npmrc);
writeRegistryToFile(registryUrl, yarnrc);
} }
exports.configAuth = configAuth; exports.configAuthentication = configAuthentication;
function writeRegistryToFile(registryUrl, fileLocation) { function writeRegistryToFile(registryUrl, fileLocation) {
core.debug(`Setting auth in ${fileLocation}`); core.debug(`Setting auth in ${fileLocation}`);
let newContents = ''; let newContents = '';
@ -25,7 +23,7 @@ function writeRegistryToFile(registryUrl, fileLocation) {
const curContents = fs.readFileSync(fileLocation, 'utf8'); const curContents = fs.readFileSync(fileLocation, 'utf8');
curContents.split(os.EOL).forEach((line) => { curContents.split(os.EOL).forEach((line) => {
// Add current contents unless they are setting the registry // Add current contents unless they are setting the registry
if (!line.startsWith('registry')) { if (!line.toLowerCase().startsWith('registry')) {
newContents += line + os.EOL; newContents += line + os.EOL;
} }
}); });
@ -36,7 +34,7 @@ function writeRegistryToFile(registryUrl, fileLocation) {
os.EOL + os.EOL +
'always-auth=true' + 'always-auth=true' +
os.EOL + os.EOL +
registryUrl.replace(/(^\w+:|^)/, '') + registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry.
':_authToken=${NODE_AUTH_TOKEN}'; ':_authToken=${NODE_AUTH_TOKEN}';
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);
} }

View file

@ -33,7 +33,7 @@ function run() {
} }
const registryUrl = core.getInput('registry-url'); const registryUrl = core.getInput('registry-url');
if (registryUrl) { if (registryUrl) {
auth.configAuth(registryUrl); auth.configAuthentication(registryUrl);
} }
// TODO: setup proxy from runner proxy config // TODO: setup proxy from runner proxy config
const matchersPath = path.join(__dirname, '..', '.github'); const matchersPath = path.join(__dirname, '..', '.github');

View file

@ -3,22 +3,20 @@ import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
export function configAuth(registryUrl: string) { export function configAuthentication(registryUrl: string) {
let npmrc: string = path.resolve(process.cwd(), '.npmrc'); const npmrc: string = path.resolve(process.cwd(), '.npmrc');
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
writeRegistryToFile(registryUrl, npmrc); writeRegistryToFile(registryUrl, npmrc);
writeRegistryToFile(registryUrl, yarnrc);
} }
function writeRegistryToFile(registryUrl: string, fileLocation: string) { function writeRegistryToFile(registryUrl: string, fileLocation: string) {
core.debug(`Setting auth in ${fileLocation}`); core.debug(`Setting auth in ${fileLocation}`);
let newContents = ''; let newContents = '';
if (fs.existsSync(fileLocation)) { if (fs.existsSync(fileLocation)) {
const curContents = fs.readFileSync(fileLocation, 'utf8'); const curContents: string = fs.readFileSync(fileLocation, 'utf8');
curContents.split(os.EOL).forEach((line: string) => { curContents.split(os.EOL).forEach((line: string) => {
// Add current contents unless they are setting the registry // Add current contents unless they are setting the registry
if (!line.startsWith('registry')) { if (!line.toLowerCase().startsWith('registry')) {
newContents += line + os.EOL; newContents += line + os.EOL;
} }
}); });
@ -29,7 +27,7 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
os.EOL + os.EOL +
'always-auth=true' + 'always-auth=true' +
os.EOL + os.EOL +
registryUrl.replace(/(^\w+:|^)/, '') + registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry.
':_authToken=${NODE_AUTH_TOKEN}'; ':_authToken=${NODE_AUTH_TOKEN}';
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);
} }

View file

@ -15,9 +15,9 @@ async function run() {
await installer.getNode(version); await installer.getNode(version);
} }
const registryUrl = core.getInput('registry-url'); const registryUrl: string = core.getInput('registry-url');
if (registryUrl) { if (registryUrl) {
auth.configAuth(registryUrl); auth.configAuthentication(registryUrl);
} }
// TODO: setup proxy from runner proxy config // TODO: setup proxy from runner proxy config