diff --git a/README.md b/README.md index 7ba1456..45b1337 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ steps: with: version: '10.x' registry-url: -- run: npm install +- run: npm install -g yarn +- run: yarn install - run: yarn publish env: NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} diff --git a/lib/authutil.js b/lib/authutil.js index bae941b..f1a978d 100644 --- a/lib/authutil.js +++ b/lib/authutil.js @@ -11,13 +11,11 @@ const fs = __importStar(require("fs")); const os = __importStar(require("os")); const path = __importStar(require("path")); const core = __importStar(require("@actions/core")); -function configAuth(registryUrl) { - let npmrc = path.resolve(process.cwd(), '.npmrc'); - let yarnrc = path.resolve(process.cwd(), '.yarnrc'); +function configAuthentication(registryUrl) { + const npmrc = path.resolve(process.cwd(), '.npmrc'); writeRegistryToFile(registryUrl, npmrc); - writeRegistryToFile(registryUrl, yarnrc); } -exports.configAuth = configAuth; +exports.configAuthentication = configAuthentication; function writeRegistryToFile(registryUrl, fileLocation) { core.debug(`Setting auth in ${fileLocation}`); let newContents = ''; @@ -25,7 +23,7 @@ function writeRegistryToFile(registryUrl, fileLocation) { const curContents = fs.readFileSync(fileLocation, 'utf8'); curContents.split(os.EOL).forEach((line) => { // Add current contents unless they are setting the registry - if (!line.startsWith('registry')) { + if (!line.toLowerCase().startsWith('registry')) { newContents += line + os.EOL; } }); @@ -36,7 +34,7 @@ function writeRegistryToFile(registryUrl, fileLocation) { os.EOL + 'always-auth=true' + os.EOL + - registryUrl.replace(/(^\w+:|^)/, '') + + registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry. ':_authToken=${NODE_AUTH_TOKEN}'; fs.writeFileSync(fileLocation, newContents); } diff --git a/lib/setup-node.js b/lib/setup-node.js index 26d716a..974936f 100644 --- a/lib/setup-node.js +++ b/lib/setup-node.js @@ -33,7 +33,7 @@ function run() { } const registryUrl = core.getInput('registry-url'); if (registryUrl) { - auth.configAuth(registryUrl); + auth.configAuthentication(registryUrl); } // TODO: setup proxy from runner proxy config const matchersPath = path.join(__dirname, '..', '.github'); diff --git a/src/authutil.ts b/src/authutil.ts index bcd1f87..99cb33b 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -3,22 +3,20 @@ import * as os from 'os'; import * as path from 'path'; import * as core from '@actions/core'; -export function configAuth(registryUrl: string) { - let npmrc: string = path.resolve(process.cwd(), '.npmrc'); - let yarnrc: string = path.resolve(process.cwd(), '.yarnrc'); +export function configAuthentication(registryUrl: string) { + const npmrc: string = path.resolve(process.cwd(), '.npmrc'); writeRegistryToFile(registryUrl, npmrc); - writeRegistryToFile(registryUrl, yarnrc); } function writeRegistryToFile(registryUrl: string, fileLocation: string) { core.debug(`Setting auth in ${fileLocation}`); let newContents = ''; if (fs.existsSync(fileLocation)) { - const curContents = fs.readFileSync(fileLocation, 'utf8'); + const curContents: string = fs.readFileSync(fileLocation, 'utf8'); curContents.split(os.EOL).forEach((line: string) => { // Add current contents unless they are setting the registry - if (!line.startsWith('registry')) { + if (!line.toLowerCase().startsWith('registry')) { newContents += line + os.EOL; } }); @@ -29,7 +27,7 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) { os.EOL + 'always-auth=true' + os.EOL + - registryUrl.replace(/(^\w+:|^)/, '') + + registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry. ':_authToken=${NODE_AUTH_TOKEN}'; fs.writeFileSync(fileLocation, newContents); } diff --git a/src/setup-node.ts b/src/setup-node.ts index c038786..ba64e24 100644 --- a/src/setup-node.ts +++ b/src/setup-node.ts @@ -15,9 +15,9 @@ async function run() { await installer.getNode(version); } - const registryUrl = core.getInput('registry-url'); + const registryUrl: string = core.getInput('registry-url'); if (registryUrl) { - auth.configAuth(registryUrl); + auth.configAuthentication(registryUrl); } // TODO: setup proxy from runner proxy config