mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
Fix tests for always-auth
This commit is contained in:
parent
9c950f557c
commit
17f3fe1837
6 changed files with 36 additions and 32 deletions
|
@ -2,20 +2,30 @@
|
||||||
|
|
||||||
exports[`installer tests Appends trailing slash to registry 1`] = `
|
exports[`installer tests Appends trailing slash to registry 1`] = `
|
||||||
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
registry=https://registry.npmjs.org/"
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`installer tests Automatically configures GPR scope 1`] = `
|
exports[`installer tests Automatically configures GPR scope 1`] = `
|
||||||
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
|
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
@ownername:registry=npm.pkg.github.com/"
|
@ownername:registry=npm.pkg.github.com/
|
||||||
|
always-auth=false"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`installer tests Configures scoped npm registries 1`] = `
|
exports[`installer tests Configures scoped npm registries 1`] = `
|
||||||
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
@myscope:registry=https://registry.npmjs.org/"
|
@myscope:registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`installer tests Sets up npmrc for always-auth true 1`] = `
|
||||||
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=true"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`installer tests Sets up npmrc for npmjs 1`] = `
|
exports[`installer tests Sets up npmrc for npmjs 1`] = `
|
||||||
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
|
||||||
registry=https://registry.npmjs.org/"
|
registry=https://registry.npmjs.org/
|
||||||
|
always-auth=false"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -33,13 +33,13 @@ describe('installer tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Sets up npmrc for npmjs', async () => {
|
it('Sets up npmrc for npmjs', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org/');
|
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Appends trailing slash to registry', async () => {
|
it('Appends trailing slash to registry', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org');
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||||
|
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
|
@ -47,16 +47,22 @@ describe('installer tests', () => {
|
||||||
|
|
||||||
it('Configures scoped npm registries', async () => {
|
it('Configures scoped npm registries', async () => {
|
||||||
process.env['INPUT_SCOPE'] = 'myScope';
|
process.env['INPUT_SCOPE'] = 'myScope';
|
||||||
await auth.configAuthentication('https://registry.npmjs.org');
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||||
|
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Automatically configures GPR scope', async () => {
|
it('Automatically configures GPR scope', async () => {
|
||||||
await auth.configAuthentication('npm.pkg.github.com');
|
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
||||||
|
|
||||||
expect(fs.existsSync(rcFile)).toBe(true);
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Sets up npmrc for always-auth true', async () => {
|
||||||
|
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||||
|
expect(fs.existsSync(rcFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,15 +12,15 @@ 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"));
|
||||||
const github = __importStar(require("@actions/github"));
|
const github = __importStar(require("@actions/github"));
|
||||||
function configAuthentication({ registryUrl, alwaysAuth }) {
|
function configAuthentication(registryUrl, alwaysAuth) {
|
||||||
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
|
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
|
||||||
if (!registryUrl.endsWith('/')) {
|
if (!registryUrl.endsWith('/')) {
|
||||||
registryUrl += '/';
|
registryUrl += '/';
|
||||||
}
|
}
|
||||||
writeRegistryToFile({ registryUrl, fileLocation: npmrc, alwaysAuth });
|
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
|
||||||
}
|
}
|
||||||
exports.configAuthentication = configAuthentication;
|
exports.configAuthentication = configAuthentication;
|
||||||
function writeRegistryToFile({ registryUrl, fileLocation, alwaysAuth }) {
|
function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
|
||||||
let scope = core.getInput('scope');
|
let scope = 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;
|
||||||
|
|
|
@ -37,7 +37,7 @@ function run() {
|
||||||
const registryUrl = core.getInput('registry-url');
|
const registryUrl = core.getInput('registry-url');
|
||||||
const alwaysAuth = core.getInput('always-auth');
|
const alwaysAuth = core.getInput('always-auth');
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication({ registryUrl, alwaysAuth });
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
// 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');
|
||||||
|
|
|
@ -4,14 +4,7 @@ import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
interface ConfigureAuthenticationParams {
|
export function configAuthentication(registryUrl: string, alwaysAuth: string) {
|
||||||
registryUrl: string;
|
|
||||||
alwaysAuth: string;
|
|
||||||
}
|
|
||||||
export function configAuthentication({
|
|
||||||
registryUrl,
|
|
||||||
alwaysAuth
|
|
||||||
}: ConfigureAuthenticationParams) {
|
|
||||||
const npmrc: string = path.resolve(
|
const npmrc: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
'.npmrc'
|
'.npmrc'
|
||||||
|
@ -20,19 +13,14 @@ export function configAuthentication({
|
||||||
registryUrl += '/';
|
registryUrl += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
writeRegistryToFile({registryUrl, fileLocation: npmrc, alwaysAuth});
|
writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WriteRegistryToFileParams {
|
function writeRegistryToFile(
|
||||||
registryUrl: string;
|
registryUrl: string,
|
||||||
fileLocation: string;
|
fileLocation: string,
|
||||||
alwaysAuth: string;
|
alwaysAuth: string
|
||||||
}
|
) {
|
||||||
function writeRegistryToFile({
|
|
||||||
registryUrl,
|
|
||||||
fileLocation,
|
|
||||||
alwaysAuth
|
|
||||||
}: WriteRegistryToFileParams) {
|
|
||||||
let scope: string = 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;
|
||||||
|
|
|
@ -21,7 +21,7 @@ async function run() {
|
||||||
const registryUrl: string = core.getInput('registry-url');
|
const registryUrl: string = core.getInput('registry-url');
|
||||||
const alwaysAuth: string = core.getInput('always-auth');
|
const alwaysAuth: string = core.getInput('always-auth');
|
||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication({registryUrl, alwaysAuth});
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
|
|
Loading…
Add table
Reference in a new issue