Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds registry-url and always-auth parameters #64

Merged
merged 2 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,26 @@ jobs:
- run: tests/check-version.sh 'node' 'v12.0.0'
- run: tests/check-version.sh 'npm' '7.5.2'
- run: tests/check-version.sh 'yarn' '1.22.0'

test-specified-registry-url:
runs-on: "${{ matrix.os }}-latest"

strategy:
fail-fast: false
matrix:
os: [ubuntu, macOS, windows]

steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm run build
- uses: ./
with:
registry-url: "https://some.path.here.com/lol/"

- run: tests/log-info.sh
- run: tests/check-version.sh 'volta' 'current'
- run: volta install [email protected] [email protected]
- run: tests/check-version.sh 'node' 'v10.17.0'
- run: tests/check-version.sh 'yarn' '1.19.0'
- run: tests/check-registry.sh 'https://some.path.here.com/lol/'
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ inputs:
yarn-version:
description: 'Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0'
default: ''
registry-url:
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc file, and set up auth to read in from env.NODE_AUTH_TOKEN'
always-auth:
description: 'Set always-auth in npmrc'
default: 'false'
branding:
icon: 'zap'
color: 'yellow'
Expand Down
151 changes: 128 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"lint:types": "tsc --noEmit",
"test": "jest"
},
"dependencies": {},
"dependencies": {
"@actions/github": "^5.0.0"
},
"devDependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import findUp from 'find-up';
import * as installer from './installer';
import * as registry from './registry';
import addMatchers from './matchers';

async function run(): Promise<void> {
Expand Down Expand Up @@ -42,6 +43,13 @@ async function run(): Promise<void> {
}
}

const registryUrl = core.getInput('registry-url', { required: false });
const alwaysAuth = core.getInput('always-auth', { required: false });
if (registryUrl !== '') {
core.info(`setting up registry url: ${registryUrl}`);
await registry.configAuthentication(registryUrl, alwaysAuth);
}

await addMatchers();
} catch (error) {
core.setFailed(error.message);
Expand Down
44 changes: 44 additions & 0 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as path from 'path';
import { writeRegistryToFile } from './registry';
import { createTempDir } from 'broccoli-test-helper';

const ORIGNAL_CONSOLE = Object.assign({}, console);

describe('registry', () => {
afterEach(() => {
Object.assign(console, ORIGNAL_CONSOLE);
});

test('creates an .npmrc with the proper registry url', async () => {
const tmpdir = await createTempDir();

await writeRegistryToFile(path.join(tmpdir.path(), '.npmrc'), 'some.registry.url', 'false');

expect(tmpdir.read()).toMatchInlineSnapshot(`
Object {
".npmrc": "some.registry.url:_authToken=\${NODE_AUTH_TOKEN}
registry=some.registry.url
always-auth=false",
}
`);
});

test('includes existing npmrc', async () => {
const tmpdir = await createTempDir();

tmpdir.write({
'.npmrc': 'some-scope:registry=https://npm.pkg.github.com',
});

await writeRegistryToFile(path.join(tmpdir.path(), '.npmrc'), 'some.registry.url', 'false');

expect(tmpdir.read()).toMatchInlineSnapshot(`
Object {
".npmrc": "some-scope:registry=https://npm.pkg.github.com
some.registry.url:_authToken=\${NODE_AUTH_TOKEN}
registry=some.registry.url
always-auth=false",
}
`);
});
});
Loading