diff --git a/src/auth.ts b/src/auth.ts index 9681049b2..5729b6cfe 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -10,13 +10,13 @@ export const M2_DIR = '.m2'; export const SETTINGS_FILE = 'settings.xml'; export async function configAuthentication( - id: string, + idArray: string[], username: string, password: string, gpgPassphrase: string | undefined = undefined ) { console.log( - `creating ${SETTINGS_FILE} with server-id: ${id};`, + `creating ${SETTINGS_FILE} with server-id: ${idArray.join(',')};`, 'environment variables:', `username=\$${username},`, `password=\$${password},`, @@ -32,13 +32,13 @@ export async function configAuthentication( core.debug(`created directory ${settingsDirectory}`); await write( settingsDirectory, - generate(id, username, password, gpgPassphrase) + generate(idArray, username, password, gpgPassphrase) ); } // only exported for testing purposes export function generate( - id: string, + idArray: string[], username: string, password: string, gpgPassphrase: string | undefined = undefined @@ -50,13 +50,13 @@ export function generate( '@xsi:schemaLocation': 'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd', servers: { - server: [ - { + server: idArray.map((id, index, idArray) => { + return { id: id, username: `\${env.${username}}`, password: `\${env.${password}}` } - ] + }) } } }; diff --git a/src/constants.ts b/src/constants.ts index 2e885cff0..d403e1ed0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,7 @@ export const INPUT_ARCHITECTURE = 'architecture'; export const INPUT_JAVA_PACKAGE = 'java-package'; export const INPUT_JDK_FILE = 'jdkFile'; export const INPUT_SERVER_ID = 'server-id'; +export const INPUT_SERVER_ID_LIST = 'server-id-list'; export const INPUT_SERVER_USERNAME = 'server-username'; export const INPUT_SERVER_PASSWORD = 'server-password'; export const INPUT_SETTINGS_PATH = 'settings-path'; diff --git a/src/setup-java.ts b/src/setup-java.ts index db169f296..6d9b7d4ec 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -22,7 +22,8 @@ async function run() { const matchersPath = path.join(__dirname, '..', '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); - const id = core.getInput(constants.INPUT_SERVER_ID, {required: false}); + const id = core.getInput(constants.INPUT_SERVER_ID, {required: false}) || [] + const idList = core.getInput(constants.INPUT_SERVER_ID_LIST, {required: false}).split(',') || [] const username = core.getInput(constants.INPUT_SERVER_USERNAME, { required: false }); @@ -40,7 +41,7 @@ async function run() { core.setSecret(gpgPrivateKey); } - await auth.configAuthentication(id, username, password, gpgPassphrase); + await auth.configAuthentication(idList.concat(id), username, password, gpgPassphrase); if (gpgPrivateKey) { core.info('importing private key');