mirror of
https://github.com/actions/setup-java.git
synced 2026-07-08 05:55:44 +00:00
Merge cbcf2e26ca into 623c707d77
This commit is contained in:
commit
6a1ad23bd3
@ -56,6 +56,8 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `server-password`: Environment variable name for password or token for authentication to the Apache Maven repository. Default is GITHUB_TOKEN.
|
- `server-password`: Environment variable name for password or token for authentication to the Apache Maven repository. Default is GITHUB_TOKEN.
|
||||||
|
|
||||||
|
- `mvn-server-credentials`: Optional multiline list of Maven server credentials in the format `server-id:USERNAME_ENV:PASSWORD_ENV`. When set, this input overrides `server-id`/`server-username`/`server-password` and generates multiple `<server>` entries in `settings.xml`.
|
||||||
|
|
||||||
- `settings-path`: Maven related setting to point to the directory where the settings.xml file will be written. Default is ~/.m2.
|
- `settings-path`: Maven related setting to point to the directory where the settings.xml file will be written. Default is ~/.m2.
|
||||||
|
|
||||||
- `gpg-private-key`: GPG private key to import. Default is empty string.
|
- `gpg-private-key`: GPG private key to import. Default is empty string.
|
||||||
|
|||||||
@ -43,9 +43,7 @@ describe('auth tests', () => {
|
|||||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||||
|
|
||||||
await auth.createAuthenticationSettings(
|
await auth.createAuthenticationSettings(
|
||||||
id,
|
[{id, username, password}],
|
||||||
username,
|
|
||||||
password,
|
|
||||||
altHome,
|
altHome,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -56,7 +54,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(altHome)).toBe(true);
|
expect(fs.existsSync(altHome)).toBe(true);
|
||||||
expect(fs.existsSync(altSettingsFile)).toBe(true);
|
expect(fs.existsSync(altSettingsFile)).toBe(true);
|
||||||
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
|
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
|
||||||
auth.generate(id, username, password)
|
auth.generate([{id, username, password}])
|
||||||
);
|
);
|
||||||
|
|
||||||
await io.rmRF(altHome);
|
await io.rmRF(altHome);
|
||||||
@ -68,9 +66,7 @@ describe('auth tests', () => {
|
|||||||
const password = 'TOKEN';
|
const password = 'TOKEN';
|
||||||
|
|
||||||
await auth.createAuthenticationSettings(
|
await auth.createAuthenticationSettings(
|
||||||
id,
|
[{id, username, password}],
|
||||||
username,
|
|
||||||
password,
|
|
||||||
m2Dir,
|
m2Dir,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -78,7 +74,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||||
auth.generate(id, username, password)
|
auth.generate([{id, username, password}])
|
||||||
);
|
);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
@ -89,9 +85,7 @@ describe('auth tests', () => {
|
|||||||
const gpgPassphrase = 'GPG';
|
const gpgPassphrase = 'GPG';
|
||||||
|
|
||||||
await auth.createAuthenticationSettings(
|
await auth.createAuthenticationSettings(
|
||||||
id,
|
[{id, username, password}],
|
||||||
username,
|
|
||||||
password,
|
|
||||||
m2Dir,
|
m2Dir,
|
||||||
true,
|
true,
|
||||||
gpgPassphrase
|
gpgPassphrase
|
||||||
@ -100,7 +94,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||||
auth.generate(id, username, password, gpgPassphrase)
|
auth.generate([{id, username, password}], gpgPassphrase)
|
||||||
);
|
);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
@ -115,9 +109,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||||
|
|
||||||
await auth.createAuthenticationSettings(
|
await auth.createAuthenticationSettings(
|
||||||
id,
|
[{id, username, password}],
|
||||||
username,
|
|
||||||
password,
|
|
||||||
m2Dir,
|
m2Dir,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -125,7 +117,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||||
auth.generate(id, username, password)
|
auth.generate([{id, username, password}])
|
||||||
);
|
);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
@ -140,9 +132,7 @@ describe('auth tests', () => {
|
|||||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||||
|
|
||||||
await auth.createAuthenticationSettings(
|
await auth.createAuthenticationSettings(
|
||||||
id,
|
[{id, username, password}],
|
||||||
username,
|
|
||||||
password,
|
|
||||||
m2Dir,
|
m2Dir,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -169,7 +159,7 @@ describe('auth tests', () => {
|
|||||||
</servers>
|
</servers>
|
||||||
</settings>`;
|
</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', () => {
|
it('generates valid settings.xml with additional configuration', () => {
|
||||||
@ -194,8 +184,80 @@ describe('auth tests', () => {
|
|||||||
</servers>
|
</servers>
|
||||||
</settings>`;
|
</settings>`;
|
||||||
|
|
||||||
expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
|
expect(auth.generate([{id, username, password}], gpgPassphrase)).toEqual(
|
||||||
expectedSettings
|
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.&<>"''"><&0}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>${id1}</id>
|
||||||
|
<username>\${env.${username1}}</username>
|
||||||
|
<password>\${env.&<>"''"><&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}
|
||||||
|
],
|
||||||
|
gpgPassphrase
|
||||||
|
)
|
||||||
|
).toEqual(expectedSettings);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses mvn-server-credentials multiline entries', () => {
|
||||||
|
const parsed = auth.parseMavenServerCredentials([
|
||||||
|
'releases:RELEASE_USER:RELEASE_TOKEN',
|
||||||
|
'snapshots:SNAPSHOT_USER:SNAPSHOT_TOKEN'
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(parsed).toEqual([
|
||||||
|
{id: 'releases', username: 'RELEASE_USER', password: 'RELEASE_TOKEN'},
|
||||||
|
{
|
||||||
|
id: 'snapshots',
|
||||||
|
username: 'SNAPSHOT_USER',
|
||||||
|
password: 'SNAPSHOT_TOKEN'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails on invalid mvn-server-credentials format', () => {
|
||||||
|
expect(() =>
|
||||||
|
auth.parseMavenServerCredentials(['releases:RELEASE_USER'])
|
||||||
|
).toThrow('Expected format: server-id:USERNAME_ENV:PASSWORD_ENV');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails on duplicate server ids in mvn-server-credentials', () => {
|
||||||
|
expect(() =>
|
||||||
|
auth.parseMavenServerCredentials([
|
||||||
|
'releases:RELEASE_USER:RELEASE_TOKEN',
|
||||||
|
'releases:OTHER_USER:OTHER_TOKEN'
|
||||||
|
])
|
||||||
|
).toThrow("Duplicate server-id 'releases'");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -41,6 +41,9 @@ inputs:
|
|||||||
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
|
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
|
||||||
required: false
|
required: false
|
||||||
default: 'GITHUB_TOKEN'
|
default: 'GITHUB_TOKEN'
|
||||||
|
mvn-server-credentials:
|
||||||
|
description: 'Optional multiline list of Maven server credentials in the format "server-id:USERNAME_ENV:PASSWORD_ENV". When provided, this overrides server-id/server-username/server-password and writes multiple <server> entries in settings.xml.'
|
||||||
|
required: false
|
||||||
settings-path:
|
settings-path:
|
||||||
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
|
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
3
dist/cleanup/index.js
vendored
3
dist/cleanup/index.js
vendored
@ -52241,7 +52241,7 @@ else {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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_MVN_SERVER_CREDENTIALS = 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.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||||
@ -52250,6 +52250,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
exports.INPUT_MVN_SERVER_CREDENTIALS = 'mvn-server-credentials';
|
||||||
exports.INPUT_SERVER_ID = 'server-id';
|
exports.INPUT_SERVER_ID = 'server-id';
|
||||||
exports.INPUT_SERVER_USERNAME = 'server-username';
|
exports.INPUT_SERVER_USERNAME = 'server-username';
|
||||||
exports.INPUT_SERVER_PASSWORD = 'server-password';
|
exports.INPUT_SERVER_PASSWORD = 'server-password';
|
||||||
|
|||||||
72
dist/setup/index.js
vendored
72
dist/setup/index.js
vendored
@ -77676,7 +77676,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.generate = exports.createAuthenticationSettings = exports.configureAuthentication = void 0;
|
exports.parseMavenServerCredentials = exports.generate = exports.createAuthenticationSettings = exports.configureAuthentication = void 0;
|
||||||
const path = __importStar(__nccwpck_require__(16928));
|
const path = __importStar(__nccwpck_require__(16928));
|
||||||
const core = __importStar(__nccwpck_require__(37484));
|
const core = __importStar(__nccwpck_require__(37484));
|
||||||
const io = __importStar(__nccwpck_require__(94994));
|
const io = __importStar(__nccwpck_require__(94994));
|
||||||
@ -77688,9 +77688,7 @@ const gpg = __importStar(__nccwpck_require__(88343));
|
|||||||
const util_1 = __nccwpck_require__(54527);
|
const util_1 = __nccwpck_require__(54527);
|
||||||
function configureAuthentication() {
|
function configureAuthentication() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
const mvnSettings = getMavenServerSettings();
|
||||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
|
||||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
|
||||||
const settingsDirectory = core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
const settingsDirectory = core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||||
path.join(os.homedir(), constants.M2_DIR);
|
path.join(os.homedir(), constants.M2_DIR);
|
||||||
const overwriteSettings = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, true);
|
const overwriteSettings = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, true);
|
||||||
@ -77701,7 +77699,7 @@ function configureAuthentication() {
|
|||||||
if (gpgPrivateKey) {
|
if (gpgPrivateKey) {
|
||||||
core.setSecret(gpgPrivateKey);
|
core.setSecret(gpgPrivateKey);
|
||||||
}
|
}
|
||||||
yield createAuthenticationSettings(id, username, password, settingsDirectory, overwriteSettings, gpgPassphrase);
|
yield createAuthenticationSettings(mvnSettings, settingsDirectory, overwriteSettings, gpgPassphrase);
|
||||||
if (gpgPrivateKey) {
|
if (gpgPrivateKey) {
|
||||||
core.info('Importing private gpg key');
|
core.info('Importing private gpg key');
|
||||||
const keyFingerprint = (yield gpg.importKey(gpgPrivateKey)) || '';
|
const keyFingerprint = (yield gpg.importKey(gpgPrivateKey)) || '';
|
||||||
@ -77710,34 +77708,37 @@ function configureAuthentication() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.configureAuthentication = configureAuthentication;
|
exports.configureAuthentication = configureAuthentication;
|
||||||
function createAuthenticationSettings(id, username, password, settingsDirectory, overwriteSettings, gpgPassphrase = undefined) {
|
function createAuthenticationSettings(mvnSettings, settingsDirectory, overwriteSettings, gpgPassphrase = undefined) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
core.info(`Creating ${constants.MVN_SETTINGS_FILE}`);
|
||||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||||
// otherwise use the home/.m2/ path
|
// otherwise use the home/.m2/ path
|
||||||
yield io.mkdirP(settingsDirectory);
|
yield io.mkdirP(settingsDirectory);
|
||||||
yield write(settingsDirectory, generate(id, username, password, gpgPassphrase), overwriteSettings);
|
yield write(settingsDirectory, generate(mvnSettings, gpgPassphrase), overwriteSettings);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createAuthenticationSettings = createAuthenticationSettings;
|
exports.createAuthenticationSettings = createAuthenticationSettings;
|
||||||
// only exported for testing purposes
|
// only exported for testing purposes
|
||||||
function generate(id, username, password, gpgPassphrase) {
|
function generate(mvnSettings, gpgPassphrase) {
|
||||||
const xmlObj = {
|
const xmlObj = {
|
||||||
settings: {
|
settings: {
|
||||||
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
||||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
'@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',
|
'@xsi:schemaLocation': 'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
||||||
servers: {
|
servers: {
|
||||||
server: [
|
server: []
|
||||||
{
|
|
||||||
id: id,
|
|
||||||
username: `\${env.${username}}`,
|
|
||||||
password: `\${env.${password}}`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
for (const mvnSetting of mvnSettings) {
|
||||||
|
if (mvnSetting.username && mvnSetting.password) {
|
||||||
|
xmlObj.settings.servers.server.push({
|
||||||
|
id: mvnSetting.id,
|
||||||
|
username: `\${env.${mvnSetting.username}}`,
|
||||||
|
password: `\${env.${mvnSetting.password}}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
if (gpgPassphrase) {
|
if (gpgPassphrase) {
|
||||||
const gpgServer = {
|
const gpgServer = {
|
||||||
id: 'gpg.passphrase',
|
id: 'gpg.passphrase',
|
||||||
@ -77752,6 +77753,42 @@ function generate(id, username, password, gpgPassphrase) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.generate = generate;
|
exports.generate = generate;
|
||||||
|
function getMavenServerSettings() {
|
||||||
|
const multilineEntries = core
|
||||||
|
.getMultilineInput(constants.INPUT_MVN_SERVER_CREDENTIALS)
|
||||||
|
.map(entry => entry.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
if (multilineEntries.length > 0) {
|
||||||
|
return parseMavenServerCredentials(multilineEntries);
|
||||||
|
}
|
||||||
|
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||||
|
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||||
|
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||||
|
return [{ id, username, password }];
|
||||||
|
}
|
||||||
|
// only exported for testing purposes
|
||||||
|
function parseMavenServerCredentials(entries) {
|
||||||
|
const parsed = entries.map((entry, index) => {
|
||||||
|
const parts = entry.split(':');
|
||||||
|
if (parts.length !== 3) {
|
||||||
|
throw new Error(`Invalid mvn-server-credentials entry at line ${index + 1}. Expected format: server-id:USERNAME_ENV:PASSWORD_ENV`);
|
||||||
|
}
|
||||||
|
const [id, username, password] = parts.map(part => part.trim());
|
||||||
|
if (!id || !username || !password) {
|
||||||
|
throw new Error(`Invalid mvn-server-credentials entry at line ${index + 1}. server-id, username env, and password env are required`);
|
||||||
|
}
|
||||||
|
return { id, username, password };
|
||||||
|
});
|
||||||
|
const ids = new Set();
|
||||||
|
for (const setting of parsed) {
|
||||||
|
if (ids.has(setting.id)) {
|
||||||
|
throw new Error(`Duplicate server-id '${setting.id}' in mvn-server-credentials input`);
|
||||||
|
}
|
||||||
|
ids.add(setting.id);
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
exports.parseMavenServerCredentials = parseMavenServerCredentials;
|
||||||
function write(directory, settings, overwriteSettings) {
|
function write(directory, settings, overwriteSettings) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const location = path.join(directory, constants.MVN_SETTINGS_FILE);
|
const location = path.join(directory, constants.MVN_SETTINGS_FILE);
|
||||||
@ -78000,7 +78037,7 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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_MVN_SERVER_CREDENTIALS = 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.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||||
@ -78009,6 +78046,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
exports.INPUT_MVN_SERVER_CREDENTIALS = 'mvn-server-credentials';
|
||||||
exports.INPUT_SERVER_ID = 'server-id';
|
exports.INPUT_SERVER_ID = 'server-id';
|
||||||
exports.INPUT_SERVER_USERNAME = 'server-username';
|
exports.INPUT_SERVER_USERNAME = 'server-username';
|
||||||
exports.INPUT_SERVER_PASSWORD = 'server-password';
|
exports.INPUT_SERVER_PASSWORD = 'server-password';
|
||||||
|
|||||||
@ -473,6 +473,57 @@ The two `settings.xml` files created from the above example look like the follow
|
|||||||
|
|
||||||
If you don't want to overwrite the `settings.xml` file, you can set `overwrite-settings: false`
|
If you don't want to overwrite the `settings.xml` file, you can set `overwrite-settings: false`
|
||||||
|
|
||||||
|
### Multiple repositories
|
||||||
|
|
||||||
|
When release and snapshot artifacts are deployed to different repositories, you can configure multiple Maven servers in one run.
|
||||||
|
|
||||||
|
Use `mvn-server-credentials` with one entry per line in the format:
|
||||||
|
`server-id:USERNAME_ENV:PASSWORD_ENV`
|
||||||
|
|
||||||
|
#### YAML example
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: Set up Apache Maven repositories
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '21'
|
||||||
|
mvn-server-credentials: |
|
||||||
|
releases:ARTIFACTORY_USERNAME:ARTIFACTORY_TOKEN
|
||||||
|
snapshots:SNAPSHOT_ARTIFACTORY_USERNAME:SNAPSHOT_ARTIFACTORY_TOKEN
|
||||||
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||||
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated `settings.xml`:
|
||||||
|
```xml
|
||||||
|
<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>releases</id>
|
||||||
|
<username>${env.ARTIFACTORY_USERNAME}</username>
|
||||||
|
<password>${env.ARTIFACTORY_TOKEN}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>snapshots</id>
|
||||||
|
<username>${env.SNAPSHOT_ARTIFACTORY_USERNAME}</username>
|
||||||
|
<password>${env.SNAPSHOT_ARTIFACTORY_TOKEN}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>gpg.passphrase</id>
|
||||||
|
<passphrase>${env.MAVEN_GPG_PASSPHRASE}</passphrase>
|
||||||
|
</server>
|
||||||
|
</servers>
|
||||||
|
</settings>
|
||||||
|
```
|
||||||
|
|
||||||
### Extra setup for pom.xml:
|
### Extra setup for pom.xml:
|
||||||
|
|
||||||
The Maven GPG Plugin configuration in the pom.xml file should contain the following structure to avoid possible issues like `Inappropriate ioctl for device` or `gpg: signing failed: No such file or directory`:
|
The Maven GPG Plugin configuration in the pom.xml file should contain the following structure to avoid possible issues like `Inappropriate ioctl for device` or `gpg: signing failed: No such file or directory`:
|
||||||
|
|||||||
94
src/auth.ts
94
src/auth.ts
@ -9,11 +9,10 @@ import {create as xmlCreate} from 'xmlbuilder2';
|
|||||||
import * as constants from './constants';
|
import * as constants from './constants';
|
||||||
import * as gpg from './gpg';
|
import * as gpg from './gpg';
|
||||||
import {getBooleanInput} from './util';
|
import {getBooleanInput} from './util';
|
||||||
|
import {MvnSettingDefinition} from './mvn.setting.definition';
|
||||||
|
|
||||||
export async function configureAuthentication() {
|
export async function configureAuthentication() {
|
||||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
const mvnSettings = getMavenServerSettings();
|
||||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
|
||||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
|
||||||
const settingsDirectory =
|
const settingsDirectory =
|
||||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||||
path.join(os.homedir(), constants.M2_DIR);
|
path.join(os.homedir(), constants.M2_DIR);
|
||||||
@ -33,9 +32,7 @@ export async function configureAuthentication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await createAuthenticationSettings(
|
await createAuthenticationSettings(
|
||||||
id,
|
mvnSettings,
|
||||||
username,
|
|
||||||
password,
|
|
||||||
settingsDirectory,
|
settingsDirectory,
|
||||||
overwriteSettings,
|
overwriteSettings,
|
||||||
gpgPassphrase
|
gpgPassphrase
|
||||||
@ -49,29 +46,25 @@ export async function configureAuthentication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createAuthenticationSettings(
|
export async function createAuthenticationSettings(
|
||||||
id: string,
|
mvnSettings: MvnSettingDefinition[],
|
||||||
username: string,
|
|
||||||
password: string,
|
|
||||||
settingsDirectory: string,
|
settingsDirectory: string,
|
||||||
overwriteSettings: boolean,
|
overwriteSettings: boolean,
|
||||||
gpgPassphrase: string | undefined = undefined
|
gpgPassphrase: string | undefined = undefined
|
||||||
) {
|
) {
|
||||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
core.info(`Creating ${constants.MVN_SETTINGS_FILE}`);
|
||||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||||
// otherwise use the home/.m2/ path
|
// otherwise use the home/.m2/ path
|
||||||
await io.mkdirP(settingsDirectory);
|
await io.mkdirP(settingsDirectory);
|
||||||
await write(
|
await write(
|
||||||
settingsDirectory,
|
settingsDirectory,
|
||||||
generate(id, username, password, gpgPassphrase),
|
generate(mvnSettings, gpgPassphrase),
|
||||||
overwriteSettings
|
overwriteSettings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only exported for testing purposes
|
// only exported for testing purposes
|
||||||
export function generate(
|
export function generate(
|
||||||
id: string,
|
mvnSettings: MvnSettingDefinition[],
|
||||||
username: string,
|
|
||||||
password: string,
|
|
||||||
gpgPassphrase?: string | undefined
|
gpgPassphrase?: string | undefined
|
||||||
) {
|
) {
|
||||||
const xmlObj: {[key: string]: any} = {
|
const xmlObj: {[key: string]: any} = {
|
||||||
@ -81,17 +74,21 @@ export function generate(
|
|||||||
'@xsi:schemaLocation':
|
'@xsi:schemaLocation':
|
||||||
'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
||||||
servers: {
|
servers: {
|
||||||
server: [
|
server: []
|
||||||
{
|
|
||||||
id: id,
|
|
||||||
username: `\${env.${username}}`,
|
|
||||||
password: `\${env.${password}}`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for (const mvnSetting of mvnSettings) {
|
||||||
|
if (mvnSetting.username && mvnSetting.password) {
|
||||||
|
xmlObj.settings.servers.server.push({
|
||||||
|
id: mvnSetting.id,
|
||||||
|
username: `\${env.${mvnSetting.username}}`,
|
||||||
|
password: `\${env.${mvnSetting.password}}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (gpgPassphrase) {
|
if (gpgPassphrase) {
|
||||||
const gpgServer = {
|
const gpgServer = {
|
||||||
id: 'gpg.passphrase',
|
id: 'gpg.passphrase',
|
||||||
@ -107,6 +104,61 @@ export function generate(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMavenServerSettings(): MvnSettingDefinition[] {
|
||||||
|
const multilineEntries = core
|
||||||
|
.getMultilineInput(constants.INPUT_MVN_SERVER_CREDENTIALS)
|
||||||
|
.map(entry => entry.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if (multilineEntries.length > 0) {
|
||||||
|
return parseMavenServerCredentials(multilineEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||||
|
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||||
|
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||||
|
return [{id, username, password}];
|
||||||
|
}
|
||||||
|
|
||||||
|
// only exported for testing purposes
|
||||||
|
export function parseMavenServerCredentials(
|
||||||
|
entries: string[]
|
||||||
|
): MvnSettingDefinition[] {
|
||||||
|
const parsed = entries.map((entry, index) => {
|
||||||
|
const parts = entry.split(':');
|
||||||
|
if (parts.length !== 3) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid mvn-server-credentials entry at line ${
|
||||||
|
index + 1
|
||||||
|
}. Expected format: server-id:USERNAME_ENV:PASSWORD_ENV`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [id, username, password] = parts.map(part => part.trim());
|
||||||
|
if (!id || !username || !password) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid mvn-server-credentials entry at line ${
|
||||||
|
index + 1
|
||||||
|
}. server-id, username env, and password env are required`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {id, username, password};
|
||||||
|
});
|
||||||
|
|
||||||
|
const ids = new Set<string>();
|
||||||
|
for (const setting of parsed) {
|
||||||
|
if (ids.has(setting.id)) {
|
||||||
|
throw new Error(
|
||||||
|
`Duplicate server-id '${setting.id}' in mvn-server-credentials input`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ids.add(setting.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
async function write(
|
async function write(
|
||||||
directory: string,
|
directory: string,
|
||||||
settings: string,
|
settings: string,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ export const INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
export const INPUT_DISTRIBUTION = 'distribution';
|
export const INPUT_DISTRIBUTION = 'distribution';
|
||||||
export const INPUT_JDK_FILE = 'jdkFile';
|
export const INPUT_JDK_FILE = 'jdkFile';
|
||||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
export const INPUT_MVN_SERVER_CREDENTIALS = 'mvn-server-credentials';
|
||||||
export const INPUT_SERVER_ID = 'server-id';
|
export const INPUT_SERVER_ID = 'server-id';
|
||||||
export const INPUT_SERVER_USERNAME = 'server-username';
|
export const INPUT_SERVER_USERNAME = 'server-username';
|
||||||
export const INPUT_SERVER_PASSWORD = 'server-password';
|
export const INPUT_SERVER_PASSWORD = 'server-password';
|
||||||
|
|||||||
6
src/mvn.setting.definition.ts
Normal file
6
src/mvn.setting.definition.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface MvnSettingDefinition {
|
||||||
|
id: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
gpgPassphrase?: string;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user