mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-16 00:00:27 +08:00
Merge remote-tracking branch 'origin/master' into releases/v2
This commit is contained in:
2
.github/workflows/release-drafter.yml
vendored
2
.github/workflows/release-drafter.yml
vendored
@ -17,6 +17,6 @@ jobs:
|
||||
&& !startsWith(github.event.head_commit.message , '[maven-release-plugin]')
|
||||
|
||||
steps:
|
||||
- uses: release-drafter/release-drafter@v5.21.0
|
||||
- uses: release-drafter/release-drafter@v5.21.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
34
README.md
34
README.md
@ -31,14 +31,14 @@ See [action.yml](action.yml)
|
||||
## default ```settings.xml```
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
```
|
||||
|
||||
## ```settings.xml``` with servers section
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||
```
|
||||
@ -62,7 +62,7 @@ Please refer to the [servers](http://maven.apache.org/settings.html#Servers) doc
|
||||
|
||||
``` yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
servers: |
|
||||
[{
|
||||
@ -96,15 +96,23 @@ result will be:
|
||||
## ```settings.xml``` with mirrors section
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||
```
|
||||
|
||||
## ```settings.xml``` with proxies section
|
||||
```yml
|
||||
step:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]'
|
||||
```
|
||||
|
||||
## ```settings.xml``` with properties
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
||||
```
|
||||
@ -113,7 +121,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
sonatypeSnapshots: true
|
||||
```
|
||||
@ -122,7 +130,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
apacheSnapshots: true
|
||||
```
|
||||
@ -130,7 +138,7 @@ steps:
|
||||
## Do not override existing ```settings.xml```, from version **2.0** file is override by default :
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
override: false
|
||||
```
|
||||
@ -138,7 +146,7 @@ steps:
|
||||
## Do not add github to server in ```settings.xml```, by default is added:
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
githubServer: false
|
||||
```
|
||||
@ -147,7 +155,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||
```
|
||||
@ -155,7 +163,7 @@ steps:
|
||||
## ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017)
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
oracleRepo: true
|
||||
```
|
||||
@ -166,7 +174,7 @@ It is also possible pass in Github Secrets e.g.
|
||||
|
||||
``` yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
with:
|
||||
servers: |
|
||||
[{
|
||||
@ -196,7 +204,7 @@ steps:
|
||||
with:
|
||||
java-version: 8
|
||||
|
||||
- uses: s4u/maven-settings-action@v2.7.0
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
|
||||
- run: mvn verify
|
||||
```
|
||||
|
||||
@ -15,6 +15,8 @@ inputs:
|
||||
mirrors:
|
||||
description: 'mirrors definition in json array, eg: [{"id": "id", "name": "name", "mirrorOf": "mirrorOf", "url": "url"}]'
|
||||
required: false
|
||||
proxies:
|
||||
description: 'proxies definition in json array, eg: [{"id": "id", "active": "active", "protocol": "protocol", "host": "hostl", "port": "port", "nonProxyHosts", "nonProxyHosts"}]'
|
||||
properties:
|
||||
description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
||||
required: false
|
||||
|
||||
@ -68,6 +68,7 @@ test('run with all feature', () => {
|
||||
process.env['INPUT_GITHUBSERVER'] = true;
|
||||
|
||||
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_APACHESNAPSHOTS'] = true;
|
||||
@ -75,7 +76,6 @@ test('run with all feature', () => {
|
||||
process.env['INPUT_ORACLEREPO'] = true;
|
||||
|
||||
cp.spawnSync('node', [ `${indexPath}` ], { env: process.env, stdio: 'inherit' });
|
||||
|
||||
const settingsStatus = fs.lstatSync(settingsPath);
|
||||
expect(settingsStatus.isFile()).toBeTruthy();
|
||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||
@ -242,5 +242,13 @@ test('run with all feature', () => {
|
||||
<mirrorOf>mirror Off *</mirrorOf>
|
||||
<url>mirror url</url>
|
||||
</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>`);
|
||||
})
|
||||
|
||||
589
package-lock.json
generated
589
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "maven-settings-action",
|
||||
"version": "2.7.0",
|
||||
"version": "2.8.0",
|
||||
"description": "Prepare maven settings",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -27,10 +27,10 @@
|
||||
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@xmldom/xmldom": "^0.8.3"
|
||||
"@xmldom/xmldom": "^0.8.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.25.0",
|
||||
"eslint": "^8.27.0",
|
||||
"jest": "^28.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
const val = core.getInput(inputName);
|
||||
return val && val.toLocaleLowerCase() == 'true';
|
||||
@ -230,6 +259,7 @@ function generate() {
|
||||
}
|
||||
|
||||
const settingsXml = getTemplate('settings.xml');
|
||||
fillProxies(settingsXml);
|
||||
fillMirrors(settingsXml);
|
||||
fillServers(settingsXml, 'servers');
|
||||
fillServers(settingsXml, 'oracleServers');
|
||||
@ -263,6 +293,7 @@ module.exports = {
|
||||
writeSettings,
|
||||
fillMirrors,
|
||||
fillServers,
|
||||
fillProxies,
|
||||
fillServerForGithub,
|
||||
fillProperties,
|
||||
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', () => {
|
||||
|
||||
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/>
|
||||
<servers />
|
||||
<mirrors />
|
||||
<proxies />
|
||||
</settings>
|
||||
|
||||
Reference in New Issue
Block a user