From b0e5cf270d5e17b8428c466710bc07c39725573a Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Thu, 28 Nov 2019 12:40:08 -0800 Subject: [PATCH] Support ids --- __tests__/auth.test.ts | 16 +++++++++++----- src/auth.ts | 9 +++++---- src/setup-java.ts | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/__tests__/auth.test.ts b/__tests__/auth.test.ts index 4a3119d..8e5efd4 100644 --- a/__tests__/auth.test.ts +++ b/__tests__/auth.test.ts @@ -29,30 +29,36 @@ describe('auth tests', () => { }, 100000); it('creates settings.xml with username and password', async () => { + const id = 'packages'; const username = 'bluebottle'; const password = 'SingleOrigin'; - await auth.configAuthentication(username, password); + await auth.configAuthentication(id, username, password); expect(fs.existsSync(m2Dir)).toBe(true); expect(fs.existsSync(settingsFile)).toBe(true); expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual( - auth.generate(username, password) + auth.generate(id, username, password) ); }, 100000); it('does not create settings.xml without username and / or password', async () => { - await auth.configAuthentication('FOO', ''); + await auth.configAuthentication('FOO', '', ''); expect(fs.existsSync(m2Dir)).toBe(false); expect(fs.existsSync(settingsFile)).toBe(false); - await auth.configAuthentication('', 'BAR'); + await auth.configAuthentication('', 'BAR', ''); expect(fs.existsSync(m2Dir)).toBe(false); expect(fs.existsSync(settingsFile)).toBe(false); - await auth.configAuthentication('', ''); // BAZ!!! + await auth.configAuthentication('', '', 'BAZ'); + + expect(fs.existsSync(m2Dir)).toBe(false); + expect(fs.existsSync(settingsFile)).toBe(false); + + await auth.configAuthentication('', '', ''); expect(fs.existsSync(m2Dir)).toBe(false); expect(fs.existsSync(settingsFile)).toBe(false); diff --git a/src/auth.ts b/src/auth.ts index 252423a..d3c13bc 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -7,13 +7,13 @@ import * as io from '@actions/io'; export const M2_DIR = '.m2'; export const SETTINGS_FILE = 'settings.xml'; -export async function configAuthentication(username: string, password: string) { - if (username && password) { +export async function configAuthentication(id: string, username: string, password: string) { + if (id && username && password) { core.debug(`configAuthentication with ${username} and a password`); const directory: string = path.join(os.homedir(), M2_DIR); await io.mkdirP(directory); core.debug(`created directory ${directory}`); - await write(directory, generate(username, password)); + await write(directory, generate(id, username, password)); } else { core.debug( `no auth without username: ${username} and password: ${password}` @@ -22,11 +22,12 @@ export async function configAuthentication(username: string, password: string) { } // only exported for testing purposes -export function generate(username: string, password: string) { +export function generate(id: string, username: string, password: string) { return ` + ${id} ${username} ${password} diff --git a/src/setup-java.ts b/src/setup-java.ts index 99026e3..2a73116 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -18,11 +18,12 @@ async function run() { const matchersPath = path.join(__dirname, '..', '.github'); console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); + const id = core.getInput('id', {required: false}); const username = core.getInput('username', {required: false}); const password = core.getInput('password', {required: false}); - if (username && password) { - await auth.configAuthentication(username, password); + if (id && username && password) { + await auth.configAuthentication(id, username, password); } } catch (error) {