1
0

Compare commits

..

21 Commits

Author SHA1 Message Date
Danny McCormick
ff5ec869e5 Don't export both userconfigs 2019-08-06 11:52:15 -04:00
Iheanyi Ekechukwu
f20c85e5e5 Fix string interpolation for auth token. 2019-08-06 11:19:12 -04:00
Danny McCormick
da3e59948e Get auth working for now pending runner changes 2019-08-06 10:58:30 -04:00
Danny McCormick
3c9d73515f Try exporting blank token 2019-08-06 09:47:51 -04:00
Danny McCormick
c09ef151f8 Dont always auth 2019-08-06 09:40:13 -04:00
Danny McCormick
985b557393 npmrc in RUNNER_TEMP 2019-08-06 09:26:34 -04:00
Danny McCormick
1be350f27e Merge branch 'master' of https://github.com/actions/setup-node into auth 2019-08-05 22:24:44 -04:00
Danny McCormick
0675b87d74 Update installer.js (#24)
* Update installer.js

* Update installer.ts

* Update installer.js
2019-08-05 22:23:46 -04:00
Danny McCormick
6b65ca8e49 Merge branch 'master' into auth 2019-08-05 21:33:24 -04:00
Danny McCormick
213c968cb9 Update io (#22) 2019-08-05 16:46:12 -04:00
Danny McCormick
feb12fe291 new toolkit and scoped registries 2019-08-05 15:18:52 -04:00
Danny McCormick
a9f1343a9a Add type 2019-08-05 13:15:47 -04:00
Danny McCormick
920661f1be Feedback 2019-08-05 13:12:37 -04:00
Danny McCormick
8e12aec29e Update readme 2019-08-05 12:02:15 -04:00
Danny McCormick
f338d8591f Description 2019-08-05 11:58:24 -04:00
Danny McCormick
9776256210 Yarn sometimes prefers npmrc, so use same token 2019-08-05 11:57:53 -04:00
Danny McCormick
287437bd45 Update 2019-08-05 11:51:04 -04:00
Danny McCormick
dd1cda5071 Update 2019-08-05 11:47:09 -04:00
Danny McCormick
0930c1111e Update 2019-08-05 11:46:12 -04:00
Danny McCormick
409b7dfb5b Update 2019-08-05 11:44:04 -04:00
Danny McCormick
2b9c956517 Updates 2019-08-05 11:35:39 -04:00
6 changed files with 33 additions and 120 deletions

View File

@@ -39,27 +39,21 @@ jobs:
- run: npm test
```
Publish to npmjs and GPR with npm:
Set up auth with npm:
```yaml
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
version: '10.x'
registry-url: 'https://registry.npmjs.org'
registry-url: <registry url>
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v1
with:
registry-url: 'https://npm.pkg.github.com'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Publish to npmjs and GPR with yarn:
Set up auth with yarn:
```yaml
steps:
- uses: actions/checkout@master
@@ -72,12 +66,6 @@ steps:
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
- uses: actions/setup-node@v1
with:
registry-url: 'https://npm.pkg.github.com'
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
# License

View File

@@ -1,21 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`installer tests Appends trailing slash to registry 1`] = `
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
registry=https://registry.npmjs.org/"
`;
exports[`installer tests Automatically configures GPR scope 1`] = `
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
@owner:registry=npm.pkg.github.com/"
`;
exports[`installer tests Configures scoped npm registries 1`] = `
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
@myScope:registry=https://registry.npmjs.org/"
`;
exports[`installer tests Sets up npmrc for npmjs 1`] = `
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
registry=https://registry.npmjs.org/"
`;

View File

@@ -1,62 +0,0 @@
import io = require('@actions/io');
import fs = require('fs');
import path = require('path');
const tempDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);
const rcFile = path.join(tempDir, '.npmrc');
process.env['GITHUB_REPOSITORY'] = 'owner/repo';
process.env['RUNNER_TEMP'] = tempDir;
import * as auth from '../src/authutil';
describe('installer tests', () => {
beforeAll(async () => {
await io.rmRF(tempDir);
await io.mkdirP(tempDir);
}, 100000);
beforeEach(() => {
if (fs.existsSync(rcFile)) {
fs.unlinkSync(rcFile);
}
process.env['INPUT_SCOPE'] = '';
});
it('Sets up npmrc for npmjs', async () => {
await auth.configAuthentication('https://registry.npmjs.org/');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Appends trailing slash to registry', async () => {
await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Configures scoped npm registries', async () => {
process.env['INPUT_SCOPE'] = 'myScope';
await auth.configAuthentication('https://registry.npmjs.org');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
it('Automatically configures GPR scope', async () => {
await auth.configAuthentication('npm.pkg.github.com');
expect(fs.existsSync(rcFile)).toBe(true);
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
});
});

View File

@@ -4,7 +4,7 @@ import os = require('os');
import path = require('path');
const toolDir = path.join(
__dirname,
process.cwd(),
'runner',
path.join(
Math.random()
@@ -14,7 +14,7 @@ const toolDir = path.join(
'tools'
);
const tempDir = path.join(
__dirname,
process.cwd(),
'runner',
path.join(
Math.random()
@@ -36,6 +36,15 @@ describe('installer tests', () => {
await io.rmRF(tempDir);
}, 100000);
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
}, 100000);
it('Acquires version of node if no matching version is installed', async () => {
await installer.getNode('10.16.0');
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());

View File

@@ -13,10 +13,11 @@ const path = __importStar(require("path"));
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
function configAuthentication(registryUrl) {
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
if (!registryUrl.endsWith('/')) {
registryUrl += '/';
}
// const npmrc: string = path.resolve(
// process.env['RUNNER_TEMP'] || process.cwd(),
// '.npmrc'
// );
const npmrc = path.resolve(process.cwd(), '.npmrc');
writeRegistryToFile(registryUrl, npmrc);
}
exports.configAuthentication = configAuthentication;
@@ -44,9 +45,9 @@ function writeRegistryToFile(registryUrl, fileLocation) {
const registryString = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
newContents += `${authString}${os.EOL}${registryString}`;
newContents += `${registryString}${os.EOL}${authString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
}

View File

@@ -5,19 +5,17 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
export function configAuthentication(registryUrl: string) {
const npmrc: string = path.resolve(
process.env['RUNNER_TEMP'] || process.cwd(),
'.npmrc'
);
if (!registryUrl.endsWith('/')) {
registryUrl += '/';
}
// const npmrc: string = path.resolve(
// process.env['RUNNER_TEMP'] || process.cwd(),
// '.npmrc'
// );
const npmrc: string = path.resolve(process.cwd(), '.npmrc');
writeRegistryToFile(registryUrl, npmrc);
}
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
let scope: string = core.getInput('scope');
let scope = core.getInput('scope');
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
scope = github.context.repo.owner;
}
@@ -37,14 +35,14 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
});
}
// Remove http: or https: from front of registry.
const authString: string =
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString: string = scope
const authString =
registryUrl.replace(/(^\w+:|^)/, '') + `:_authToken=${NODE_AUTH_TOKEN}`;
const registryString = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
newContents += `${authString}${os.EOL}${registryString}`;
newContents += `${registryString}${os.EOL}${authString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
}