Skip to content

Commit b0e5cf2

Browse files
author
Bryan Clark
committed
Support ids
1 parent 1b04170 commit b0e5cf2

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

__tests__/auth.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,36 @@ describe('auth tests', () => {
2929
}, 100000);
3030

3131
it('creates settings.xml with username and password', async () => {
32+
const id = 'packages';
3233
const username = 'bluebottle';
3334
const password = 'SingleOrigin';
3435

35-
await auth.configAuthentication(username, password);
36+
await auth.configAuthentication(id, username, password);
3637

3738
expect(fs.existsSync(m2Dir)).toBe(true);
3839
expect(fs.existsSync(settingsFile)).toBe(true);
3940
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
40-
auth.generate(username, password)
41+
auth.generate(id, username, password)
4142
);
4243
}, 100000);
4344

4445
it('does not create settings.xml without username and / or password', async () => {
45-
await auth.configAuthentication('FOO', '');
46+
await auth.configAuthentication('FOO', '', '');
4647

4748
expect(fs.existsSync(m2Dir)).toBe(false);
4849
expect(fs.existsSync(settingsFile)).toBe(false);
4950

50-
await auth.configAuthentication('', 'BAR');
51+
await auth.configAuthentication('', 'BAR', '');
5152

5253
expect(fs.existsSync(m2Dir)).toBe(false);
5354
expect(fs.existsSync(settingsFile)).toBe(false);
5455

55-
await auth.configAuthentication('', ''); // BAZ!!!
56+
await auth.configAuthentication('', '', 'BAZ');
57+
58+
expect(fs.existsSync(m2Dir)).toBe(false);
59+
expect(fs.existsSync(settingsFile)).toBe(false);
60+
61+
await auth.configAuthentication('', '', '');
5662

5763
expect(fs.existsSync(m2Dir)).toBe(false);
5864
expect(fs.existsSync(settingsFile)).toBe(false);

src/auth.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import * as io from '@actions/io';
77
export const M2_DIR = '.m2';
88
export const SETTINGS_FILE = 'settings.xml';
99

10-
export async function configAuthentication(username: string, password: string) {
11-
if (username && password) {
10+
export async function configAuthentication(id: string, username: string, password: string) {
11+
if (id && username && password) {
1212
core.debug(`configAuthentication with ${username} and a password`);
1313
const directory: string = path.join(os.homedir(), M2_DIR);
1414
await io.mkdirP(directory);
1515
core.debug(`created directory ${directory}`);
16-
await write(directory, generate(username, password));
16+
await write(directory, generate(id, username, password));
1717
} else {
1818
core.debug(
1919
`no auth without username: ${username} and password: ${password}`
@@ -22,11 +22,12 @@ export async function configAuthentication(username: string, password: string) {
2222
}
2323

2424
// only exported for testing purposes
25-
export function generate(username: string, password: string) {
25+
export function generate(id: string, username: string, password: string) {
2626
return `
2727
<settings>
2828
<servers>
2929
<server>
30+
<id>${id}</id>
3031
<username>${username}</username>
3132
<password>${password}</password>
3233
</server>

src/setup-java.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ async function run() {
1818
const matchersPath = path.join(__dirname, '..', '.github');
1919
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
2020

21+
const id = core.getInput('id', {required: false});
2122
const username = core.getInput('username', {required: false});
2223
const password = core.getInput('password', {required: false});
2324

24-
if (username && password) {
25-
await auth.configAuthentication(username, password);
25+
if (id && username && password) {
26+
await auth.configAuthentication(id, username, password);
2627
}
2728

2829
} catch (error) {

0 commit comments

Comments
 (0)