Compare commits
6 Commits
ff5ec869e5
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5273d0df9c | ||
|
|
fc9ff49b90 | ||
|
|
552489ce4b | ||
|
|
401832ee64 | ||
|
|
b0d4a002ac | ||
|
|
ea546c14bf |
18
README.md
18
README.md
@@ -39,21 +39,27 @@ jobs:
|
|||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
Set up auth with npm:
|
Publish to npmjs and GPR with npm:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
version: '10.x'
|
version: '10.x'
|
||||||
registry-url: <registry url>
|
registry-url: 'https://registry.npmjs.org'
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
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 }}
|
||||||
```
|
```
|
||||||
|
|
||||||
Set up auth with yarn:
|
Publish to npmjs and GPR with yarn:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
@@ -66,6 +72,12 @@ steps:
|
|||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
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
|
# License
|
||||||
|
|||||||
21
__tests__/__snapshots__/authutil.test.ts.snap
Normal file
21
__tests__/__snapshots__/authutil.test.ts.snap
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// 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/"
|
||||||
|
`;
|
||||||
62
__tests__/authutil.test.ts
Normal file
62
__tests__/authutil.test.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,7 +4,7 @@ import os = require('os');
|
|||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
const toolDir = path.join(
|
const toolDir = path.join(
|
||||||
process.cwd(),
|
__dirname,
|
||||||
'runner',
|
'runner',
|
||||||
path.join(
|
path.join(
|
||||||
Math.random()
|
Math.random()
|
||||||
@@ -14,7 +14,7 @@ const toolDir = path.join(
|
|||||||
'tools'
|
'tools'
|
||||||
);
|
);
|
||||||
const tempDir = path.join(
|
const tempDir = path.join(
|
||||||
process.cwd(),
|
__dirname,
|
||||||
'runner',
|
'runner',
|
||||||
path.join(
|
path.join(
|
||||||
Math.random()
|
Math.random()
|
||||||
@@ -36,15 +36,6 @@ describe('installer tests', () => {
|
|||||||
await io.rmRF(tempDir);
|
await io.rmRF(tempDir);
|
||||||
}, 100000);
|
}, 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 () => {
|
it('Acquires version of node if no matching version is installed', async () => {
|
||||||
await installer.getNode('10.16.0');
|
await installer.getNode('10.16.0');
|
||||||
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());
|
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ const path = __importStar(require("path"));
|
|||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const github = __importStar(require("@actions/github"));
|
const github = __importStar(require("@actions/github"));
|
||||||
function configAuthentication(registryUrl) {
|
function configAuthentication(registryUrl) {
|
||||||
// const npmrc: string = path.resolve(
|
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
|
||||||
// process.env['RUNNER_TEMP'] || process.cwd(),
|
if (!registryUrl.endsWith('/')) {
|
||||||
// '.npmrc'
|
registryUrl += '/';
|
||||||
// );
|
}
|
||||||
const npmrc = path.resolve(process.cwd(), '.npmrc');
|
|
||||||
writeRegistryToFile(registryUrl, npmrc);
|
writeRegistryToFile(registryUrl, npmrc);
|
||||||
}
|
}
|
||||||
exports.configAuthentication = configAuthentication;
|
exports.configAuthentication = configAuthentication;
|
||||||
@@ -45,9 +44,9 @@ function writeRegistryToFile(registryUrl, fileLocation) {
|
|||||||
const registryString = scope
|
const registryString = scope
|
||||||
? `${scope}:registry=${registryUrl}`
|
? `${scope}:registry=${registryUrl}`
|
||||||
: `registry=${registryUrl}`;
|
: `registry=${registryUrl}`;
|
||||||
newContents += `${registryString}${os.EOL}${authString}`;
|
newContents += `${authString}${os.EOL}${registryString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
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
|
// 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');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ import * as core from '@actions/core';
|
|||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
export function configAuthentication(registryUrl: string) {
|
export function configAuthentication(registryUrl: string) {
|
||||||
// const npmrc: string = path.resolve(
|
const npmrc: string = path.resolve(
|
||||||
// process.env['RUNNER_TEMP'] || process.cwd(),
|
process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
// '.npmrc'
|
'.npmrc'
|
||||||
// );
|
);
|
||||||
const npmrc: string = path.resolve(process.cwd(), '.npmrc');
|
if (!registryUrl.endsWith('/')) {
|
||||||
|
registryUrl += '/';
|
||||||
|
}
|
||||||
|
|
||||||
writeRegistryToFile(registryUrl, npmrc);
|
writeRegistryToFile(registryUrl, npmrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||||
let scope = core.getInput('scope');
|
let scope: string = core.getInput('scope');
|
||||||
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
||||||
scope = github.context.repo.owner;
|
scope = github.context.repo.owner;
|
||||||
}
|
}
|
||||||
@@ -35,14 +37,14 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove http: or https: from front of registry.
|
// Remove http: or https: from front of registry.
|
||||||
const authString =
|
const authString: string =
|
||||||
registryUrl.replace(/(^\w+:|^)/, '') + `:_authToken=${NODE_AUTH_TOKEN}`;
|
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
|
||||||
const registryString = scope
|
const registryString: string = scope
|
||||||
? `${scope}:registry=${registryUrl}`
|
? `${scope}:registry=${registryUrl}`
|
||||||
: `registry=${registryUrl}`;
|
: `registry=${registryUrl}`;
|
||||||
newContents += `${registryString}${os.EOL}${authString}`;
|
newContents += `${authString}${os.EOL}${registryString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
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
|
// 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');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user