mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-18 00:00:26 +08:00
Add proxy support (#250)
This commit is contained in:
@ -101,6 +101,14 @@ steps:
|
|||||||
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## ```settings.xml``` with proxies section
|
||||||
|
```yml
|
||||||
|
step:
|
||||||
|
- uses: s4u/maven-settings-action@v2.7.0
|
||||||
|
with:
|
||||||
|
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]'
|
||||||
|
```
|
||||||
|
|
||||||
## ```settings.xml``` with properties
|
## ```settings.xml``` with properties
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@ -15,6 +15,8 @@ inputs:
|
|||||||
mirrors:
|
mirrors:
|
||||||
description: 'mirrors definition in json array, eg: [{"id": "id", "name": "name", "mirrorOf": "mirrorOf", "url": "url"}]'
|
description: 'mirrors definition in json array, eg: [{"id": "id", "name": "name", "mirrorOf": "mirrorOf", "url": "url"}]'
|
||||||
required: false
|
required: false
|
||||||
|
proxies:
|
||||||
|
description: 'proxies definition in json array, eg: [{"id": "id", "active": "active", "protocol": "protocol", "host": "hostl", "port": "port", "nonProxyHosts", "nonProxyHosts"}]'
|
||||||
properties:
|
properties:
|
||||||
description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@ -68,6 +68,7 @@ test('run with all feature', () => {
|
|||||||
process.env['INPUT_GITHUBSERVER'] = true;
|
process.env['INPUT_GITHUBSERVER'] = true;
|
||||||
|
|
||||||
process.env['INPUT_MIRRORS'] = '[{"id": "mirrorId", "name": "mirror Name", "mirrorOf": "mirror Off *", "url": "mirror url"}]';
|
process.env['INPUT_MIRRORS'] = '[{"id": "mirrorId", "name": "mirror Name", "mirrorOf": "mirror Off *", "url": "mirror url"}]';
|
||||||
|
process.env['INPUT_PROXIES'] = '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]';
|
||||||
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||||
|
|
||||||
process.env['INPUT_APACHESNAPSHOTS'] = true;
|
process.env['INPUT_APACHESNAPSHOTS'] = true;
|
||||||
@ -75,7 +76,6 @@ test('run with all feature', () => {
|
|||||||
process.env['INPUT_ORACLEREPO'] = true;
|
process.env['INPUT_ORACLEREPO'] = true;
|
||||||
|
|
||||||
cp.spawnSync('node', [ `${indexPath}` ], { env: process.env, stdio: 'inherit' });
|
cp.spawnSync('node', [ `${indexPath}` ], { env: process.env, stdio: 'inherit' });
|
||||||
|
|
||||||
const settingsStatus = fs.lstatSync(settingsPath);
|
const settingsStatus = fs.lstatSync(settingsPath);
|
||||||
expect(settingsStatus.isFile()).toBeTruthy();
|
expect(settingsStatus.isFile()).toBeTruthy();
|
||||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||||
@ -242,5 +242,13 @@ test('run with all feature', () => {
|
|||||||
<mirrorOf>mirror Off *</mirrorOf>
|
<mirrorOf>mirror Off *</mirrorOf>
|
||||||
<url>mirror url</url>
|
<url>mirror url</url>
|
||||||
</mirror></mirrors>
|
</mirror></mirrors>
|
||||||
|
<proxies><proxy>
|
||||||
|
<id>proxyId</id>
|
||||||
|
<active>isActive</active>
|
||||||
|
<protocol>proxyProtocol</protocol>
|
||||||
|
<host>proxyHost</host>
|
||||||
|
<port>proxyPort</port>
|
||||||
|
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
||||||
|
</proxy></proxies>
|
||||||
</settings>`);
|
</settings>`);
|
||||||
})
|
})
|
||||||
|
|||||||
31
settings.js
31
settings.js
@ -152,6 +152,35 @@ function fillMirrors(template) {
|
|||||||
JSON.parse(mirrors).forEach((mirror) => fillMirror(template, mirror.id, mirror.name, mirror.mirrorOf, mirror.url));
|
JSON.parse(mirrors).forEach((mirror) => fillMirror(template, mirror.id, mirror.name, mirror.mirrorOf, mirror.url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fillProxies(template) {
|
||||||
|
|
||||||
|
const proxies = core.getInput('proxies');
|
||||||
|
|
||||||
|
if (!proxies) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts));
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
|
||||||
|
if(!id || !active || !protocol || !host || !port || !nonProxyHosts) {
|
||||||
|
core.setFailed('proxies must contain id, active, protocol, host, port and nonProxyHosts');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxyXml = getTemplate('proxy.xml');
|
||||||
|
proxyXml.getElementsByTagName("id")[0].textContent = id;
|
||||||
|
proxyXml.getElementsByTagName("active")[0].textContent = active;
|
||||||
|
proxyXml.getElementsByTagName("protocol")[0].textContent = protocol;
|
||||||
|
proxyXml.getElementsByTagName("host")[0].textContent = host;
|
||||||
|
proxyXml.getElementsByTagName("port")[0].textContent = port;
|
||||||
|
proxyXml.getElementsByTagName("nonProxyHosts")[0].textContent = nonProxyHosts;
|
||||||
|
|
||||||
|
const proxiesXml = template.getElementsByTagName('proxies')[0];
|
||||||
|
proxiesXml.appendChild(proxyXml);
|
||||||
|
}
|
||||||
|
|
||||||
function isInputTrue(inputName) {
|
function isInputTrue(inputName) {
|
||||||
const val = core.getInput(inputName);
|
const val = core.getInput(inputName);
|
||||||
return val && val.toLocaleLowerCase() == 'true';
|
return val && val.toLocaleLowerCase() == 'true';
|
||||||
@ -230,6 +259,7 @@ function generate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const settingsXml = getTemplate('settings.xml');
|
const settingsXml = getTemplate('settings.xml');
|
||||||
|
fillProxies(settingsXml);
|
||||||
fillMirrors(settingsXml);
|
fillMirrors(settingsXml);
|
||||||
fillServers(settingsXml, 'servers');
|
fillServers(settingsXml, 'servers');
|
||||||
fillServers(settingsXml, 'oracleServers');
|
fillServers(settingsXml, 'oracleServers');
|
||||||
@ -263,6 +293,7 @@ module.exports = {
|
|||||||
writeSettings,
|
writeSettings,
|
||||||
fillMirrors,
|
fillMirrors,
|
||||||
fillServers,
|
fillServers,
|
||||||
|
fillProxies,
|
||||||
fillServerForGithub,
|
fillServerForGithub,
|
||||||
fillProperties,
|
fillProperties,
|
||||||
addApacheSnapshots,
|
addApacheSnapshots,
|
||||||
|
|||||||
@ -436,6 +436,83 @@ test('fillMirrors incorrect fields', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("fillProxies do noting if no params", () => {
|
||||||
|
const xml = stringAsXml("<proxies/>");
|
||||||
|
|
||||||
|
settings.fillProxies(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
expect(xmlStr).toBe("<proxies/>");
|
||||||
|
expect(consoleOutput).toEqual([]);
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fillProxies one proxy", () => {
|
||||||
|
const xml = stringAsXml("<proxies/>");
|
||||||
|
|
||||||
|
process.env['INPUT_PROXIES'] = `[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol",
|
||||||
|
"host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]`;
|
||||||
|
|
||||||
|
settings.fillProxies(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
expect(xmlStr).toBe(`<proxies><proxy>
|
||||||
|
<id>proxyId</id>
|
||||||
|
<active>isActive</active>
|
||||||
|
<protocol>proxyProtocol</protocol>
|
||||||
|
<host>proxyHost</host>
|
||||||
|
<port>proxyPort</port>
|
||||||
|
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
||||||
|
</proxy></proxies>`)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
test("fillProxies two proxies", () => {
|
||||||
|
const xml = stringAsXml("<proxies/>");
|
||||||
|
|
||||||
|
process.env['INPUT_PROXIES'] = `[{"id": "proxyId1", "active": "isActive1", "protocol": "proxyProtocol1",
|
||||||
|
"host": "proxyHost1", "port": "proxyPort1", "nonProxyHosts": "nonProxyHost1"},
|
||||||
|
{"id": "proxyId2", "active": "isActive2", "protocol": "proxyProtocol2",
|
||||||
|
"host": "proxyHost2", "port": "proxyPort2", "nonProxyHosts": "nonProxyHost2"}]`;
|
||||||
|
|
||||||
|
settings.fillProxies(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
expect(xmlStr).toBe(`<proxies><proxy>
|
||||||
|
<id>proxyId1</id>
|
||||||
|
<active>isActive1</active>
|
||||||
|
<protocol>proxyProtocol1</protocol>
|
||||||
|
<host>proxyHost1</host>
|
||||||
|
<port>proxyPort1</port>
|
||||||
|
<nonProxyHosts>nonProxyHost1</nonProxyHosts>
|
||||||
|
</proxy><proxy>
|
||||||
|
<id>proxyId2</id>
|
||||||
|
<active>isActive2</active>
|
||||||
|
<protocol>proxyProtocol2</protocol>
|
||||||
|
<host>proxyHost2</host>
|
||||||
|
<port>proxyPort2</port>
|
||||||
|
<nonProxyHosts>nonProxyHost2</nonProxyHosts>
|
||||||
|
</proxy></proxies>`)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
test('fillProxies incorrect fields', () => {
|
||||||
|
|
||||||
|
const xml = stringAsXml("<proxies/>");
|
||||||
|
|
||||||
|
process.env['INPUT_PROXIES'] = '[{"idx": "id1"}]';
|
||||||
|
|
||||||
|
settings.fillProxies(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe('<proxies/>');
|
||||||
|
expect(consoleOutput).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.stringMatching(/::error::proxies must contain id, active, protocol, host, port and nonProxyHosts/)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
})
|
||||||
|
|
||||||
test('addApacheSnapshots', () => {
|
test('addApacheSnapshots', () => {
|
||||||
|
|
||||||
process.env['INPUT_APACHESNAPSHOTS'] = "true";
|
process.env['INPUT_APACHESNAPSHOTS'] = "true";
|
||||||
|
|||||||
8
templates/proxy.xml
Normal file
8
templates/proxy.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<proxy>
|
||||||
|
<id />
|
||||||
|
<active />
|
||||||
|
<protocol />
|
||||||
|
<host />
|
||||||
|
<port />
|
||||||
|
<nonProxyHosts />
|
||||||
|
</proxy>
|
||||||
@ -3,4 +3,5 @@
|
|||||||
<profiles/>
|
<profiles/>
|
||||||
<servers />
|
<servers />
|
||||||
<mirrors />
|
<mirrors />
|
||||||
|
<proxies />
|
||||||
</settings>
|
</settings>
|
||||||
|
|||||||
Reference in New Issue
Block a user