Added support for configuring multiple maven repositories with separate usernames and passwords by sudiptosarkar · Pull Request #827 · actions/setup-java · GitHub
Skip to content
Closed
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
42 changes: 42 additions & 0 deletions .github/workflows/e2e-publishing.yml
81 changes: 56 additions & 25 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ describe('auth tests', () => {
await io.rmRF(altHome); // ensure it doesn't already exist

await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password}],
altHome,
true
);
Expand All @@ -56,7 +54,7 @@ describe('auth tests', () => {
expect(fs.existsSync(altHome)).toBe(true);
expect(fs.existsSync(altSettingsFile)).toBe(true);
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([{id, username, password}])
);

await io.rmRF(altHome);
Expand All @@ -68,17 +66,15 @@ describe('auth tests', () => {
const password = 'TOKEN';

await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password}],
m2Dir,
true
);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([{id, username, password}])
);
}, 100000);

Expand All @@ -89,18 +85,15 @@ describe('auth tests', () => {
const gpgPassphrase = 'GPG';

await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password, gpgPassphrase}],
m2Dir,
true,
gpgPassphrase
true
);
Comment on lines 87 to 91

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password, gpgPassphrase)
auth.generate([{id, username, password, gpgPassphrase}])
);
}, 100000);

Expand All @@ -115,17 +108,15 @@ describe('auth tests', () => {
expect(fs.existsSync(settingsFile)).toBe(true);

await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password}],
m2Dir,
true
);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([{id, username, password}])
);
}, 100000);

Expand All @@ -140,9 +131,7 @@ describe('auth tests', () => {
expect(fs.existsSync(settingsFile)).toBe(true);

await auth.createAuthenticationSettings(
id,
username,
password,
[{id, username, password}],
m2Dir,
false
);
Expand All @@ -169,7 +158,7 @@ describe('auth tests', () => {
</servers>
</settings>`;

expect(auth.generate(id, username, password)).toEqual(expectedSettings);
expect(auth.generate([{id, username, password}])).toEqual(expectedSettings);
});

it('generates valid settings.xml with additional configuration', () => {
Expand All @@ -194,8 +183,50 @@ describe('auth tests', () => {
</servers>
</settings>`;

expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
expectedSettings
);
expect(
auth.generate([
{id, username, password},
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
])
).toEqual(expectedSettings);
});

it('generates valid settings.xml for multiple repositories', () => {
const id0 = 'packages0';
const username0 = 'USER0';
const password0 = '&<>"\'\'"><&0';
const id1 = 'packages1';
const username1 = 'USER1';
const password1 = '&<>"\'\'"><&1';
const gpgPassphrase = 'PASSPHRASE';

const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>${id0}</id>
<username>\${env.${username0}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;0}</password>
</server>
<server>
<id>${id1}</id>
<username>\${env.${username1}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;1}</password>
</server>
<server>
<id>gpg.passphrase</id>
<passphrase>\${env.${gpgPassphrase}}</passphrase>
</server>
</servers>
</settings>`;

expect(
auth.generate([
{id: id0, username: username0, password: password0},
{id: id1, username: username1, password: password1},
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
])
).toEqual(expectedSettings);
});
});
27 changes: 27 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ inputs:
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
required: false
default: 'GITHUB_TOKEN'
mvn-repositories-len:
description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured'
required: false
Comment on lines +44 to +46
server-id-0:
description: 'ID of the first distributionManagement repository in the pom.xml
file - Only applicable if more than one Maven repository is being configured'
required: false
server-username-0:
description: 'Environment variable name for the username for authentication
to the first Maven repository - Only applicable if more than one Maven repository is being configured'
required: false
server-password-0:
description: 'Environment variable name for password or token for
authentication to the first Maven repository - Only applicable if more than one Maven repository is being configured'
required: false
server-id-1:
description: 'ID of the second distributionManagement repository in the pom.xml
file - Only applicable if more than one Maven repository is being configured'
required: false
server-username-1:
description: 'Environment variable name for the username for authentication
to the second Maven repository - Only applicable if more than one Maven repository is being configured'
required: false
server-password-1:
description: 'Environment variable name for password or token for
authentication to the second Maven repository - Only applicable if more than one Maven repository is being configured'
required: false
settings-path:
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
required: false
Expand Down
3 changes: 2 additions & 1 deletion dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52046,7 +52046,7 @@ else {
"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_NUM_MVN_REPOS = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
Expand All @@ -52055,6 +52055,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_DISTRIBUTION = 'distribution';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_CHECK_LATEST = 'check-latest';
exports.INPUT_NUM_MVN_REPOS = 'mvn-repositories-len';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
Expand Down
86 changes: 57 additions & 29 deletions dist/setup/index.js
Loading