mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-18 00:00:26 +08:00
Merge remote-tracking branch 'origin/master' into releases/v2
This commit is contained in:
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -32,8 +32,9 @@ jobs:
|
|||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||||
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||||
|
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||||
sonatypeSnapshots: true
|
sonatypeSnapshots: true
|
||||||
|
|
||||||
- run: cat ~/.m2/settings.xml
|
- run: cat ~/.m2/settings.xml
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
.vscode
|
.vscode
|
||||||
|
.idea
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|||||||
10
README.md
10
README.md
@ -31,7 +31,7 @@ steps:
|
|||||||
- uses: s4u/maven-settings-action@v2
|
- uses: s4u/maven-settings-action@v2
|
||||||
```
|
```
|
||||||
|
|
||||||
Create ```settings.xml``` with server section:
|
Create ```settings.xml``` with servers section:
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: s4u/maven-settings-action@v2
|
- uses: s4u/maven-settings-action@v2
|
||||||
@ -39,6 +39,14 @@ steps:
|
|||||||
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Create ```settings.xml``` with mirrors section:
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: s4u/maven-settings-action@v2
|
||||||
|
with:
|
||||||
|
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||||
|
```
|
||||||
|
|
||||||
Create ```settings.xml``` with maven properties:
|
Create ```settings.xml``` with maven properties:
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@ -9,6 +9,9 @@ inputs:
|
|||||||
servers:
|
servers:
|
||||||
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]'
|
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]'
|
||||||
required: false
|
required: false
|
||||||
|
mirrors:
|
||||||
|
description: 'mirrors definition in json array, eg: [{"id": "id", "name": "name", "mirrorOf": "mirrorOf", "url": "url"}]'
|
||||||
|
required: false
|
||||||
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
|
||||||
|
|||||||
1002
package-lock.json
generated
1002
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"jest": "^25.1.0"
|
"jest": "^25.2.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
settings.js
38
settings.js
@ -91,6 +91,42 @@ function fillServers(template) {
|
|||||||
JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password));
|
JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fillMirror(template, id, name, mirrorOf, url) {
|
||||||
|
|
||||||
|
const mirrorXml = template.createElement('mirror');
|
||||||
|
|
||||||
|
if (!id || !name || !mirrorOf || !url) {
|
||||||
|
core.setFailed('mirrors must contain id, name, mirrorOf and url');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const idXml = createElementWithText(template, 'id', id);
|
||||||
|
mirrorXml.appendChild(idXml);
|
||||||
|
|
||||||
|
const nameXml = createElementWithText(template, 'name', name);
|
||||||
|
mirrorXml.appendChild(nameXml);
|
||||||
|
|
||||||
|
const mirrorOfXml = createElementWithText(template, 'mirrorOf', mirrorOf);
|
||||||
|
mirrorXml.appendChild(mirrorOfXml);
|
||||||
|
|
||||||
|
const urlXml = createElementWithText(template, 'url', url);
|
||||||
|
mirrorXml.appendChild(urlXml);
|
||||||
|
|
||||||
|
const mirrorsXml = template.getElementsByTagName('mirrors')[0];
|
||||||
|
mirrorsXml.appendChild(mirrorXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillMirrors(template) {
|
||||||
|
|
||||||
|
const mirrors = core.getInput('mirrors');
|
||||||
|
|
||||||
|
if (!mirrors) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON.parse(mirrors).forEach((mirror) => fillMirror(template, mirror.id, mirror.name, mirror.mirrorOf, mirror.url));
|
||||||
|
}
|
||||||
|
|
||||||
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';
|
||||||
@ -157,6 +193,7 @@ function generate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const templateXml = getSettingsTemplate();
|
const templateXml = getSettingsTemplate();
|
||||||
|
fillMirrors(templateXml);
|
||||||
fillServers(templateXml);
|
fillServers(templateXml);
|
||||||
fillServerForGithub(templateXml);
|
fillServerForGithub(templateXml);
|
||||||
fillProperties(templateXml);
|
fillProperties(templateXml);
|
||||||
@ -184,6 +221,7 @@ function cleanup() {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getSettingsTemplate,
|
getSettingsTemplate,
|
||||||
writeSettings,
|
writeSettings,
|
||||||
|
fillMirrors,
|
||||||
fillServers,
|
fillServers,
|
||||||
fillServerForGithub,
|
fillServerForGithub,
|
||||||
fillProperties,
|
fillProperties,
|
||||||
|
|||||||
@ -99,7 +99,6 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('template should be read', () => {
|
test('template should be read', () => {
|
||||||
|
|
||||||
const template = settings.getSettingsTemplate();
|
const template = settings.getSettingsTemplate();
|
||||||
|
|
||||||
expect(template).toBeDefined();
|
expect(template).toBeDefined();
|
||||||
@ -133,7 +132,6 @@ test('fillServers one server', () => {
|
|||||||
|
|
||||||
const xml = new DOMParser().parseFromString("<servers/>");
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
|
|
||||||
|
|
||||||
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
|
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
|
||||||
|
|
||||||
settings.fillServers(xml);
|
settings.fillServers(xml);
|
||||||
@ -194,6 +192,65 @@ test('fillServers github', () => {
|
|||||||
expect(consoleOutput).toEqual([]);
|
expect(consoleOutput).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('fillMirrors do nothing if no params', () => {
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString("<mirrors/>");
|
||||||
|
|
||||||
|
settings.fillMirrors(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe("<mirrors/>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fillMirrors one mirror', () => {
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString("<mirrors/>");
|
||||||
|
|
||||||
|
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name", "mirrorOf":"mirrorOf", "url":"url"}]';
|
||||||
|
|
||||||
|
settings.fillMirrors(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe("<mirrors>" +
|
||||||
|
"<mirror><id>id1</id><name>name</name><mirrorOf>mirrorOf</mirrorOf><url>url</url></mirror>" +
|
||||||
|
"</mirrors>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fillMirrors two mirrors', () => {
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString("<mirrors/>");
|
||||||
|
|
||||||
|
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name1", "mirrorOf":"mirrorOf1", "url":"url1"},{"id": "id2", "name": "name2", "mirrorOf":"mirrorOf2", "url":"url2"}]';
|
||||||
|
|
||||||
|
settings.fillMirrors(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe("<mirrors>" +
|
||||||
|
"<mirror><id>id1</id><name>name1</name><mirrorOf>mirrorOf1</mirrorOf><url>url1</url></mirror><mirror><id>id2</id><name>name2</name><mirrorOf>mirrorOf2</mirrorOf><url>url2</url></mirror>" +
|
||||||
|
"</mirrors>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fillMirrors incorrect fields', () => {
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString("<mirrors/>");
|
||||||
|
|
||||||
|
process.env['INPUT_MIRRORS'] = '[{"idx": "id1"}]';
|
||||||
|
|
||||||
|
settings.fillMirrors(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe('<mirrors/>');
|
||||||
|
expect(consoleOutput).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.stringMatching(/::error::mirrors must contain id, name, mirrorOf and url/)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('addSonatypeSnapshots activate', () => {
|
test('addSonatypeSnapshots activate', () => {
|
||||||
|
|
||||||
process.env['INPUT_SONATYPESNAPSHOTS'] = "true";
|
process.env['INPUT_SONATYPESNAPSHOTS'] = "true";
|
||||||
|
|||||||
@ -1,48 +1,46 @@
|
|||||||
<settings>
|
<settings>
|
||||||
|
<interactiveMode>false</interactiveMode>
|
||||||
<interactiveMode>false</interactiveMode>
|
<profiles>
|
||||||
|
<!-- generic ############################################################# -->
|
||||||
<profiles>
|
<profile>
|
||||||
<profile>
|
<id>_properties_</id>
|
||||||
<id>_properties_</id>
|
<activation>
|
||||||
<activation>
|
<activeByDefault>false</activeByDefault>
|
||||||
<activeByDefault>false</activeByDefault>
|
</activation>
|
||||||
</activation>
|
<properties />
|
||||||
<properties />
|
</profile>
|
||||||
</profile>
|
<!-- sonatype ############################################################# -->
|
||||||
|
<profile>
|
||||||
<profile>
|
<id>_sonatype-snapshots_</id>
|
||||||
<id>_sonatype-snapshots_</id>
|
<activation>
|
||||||
<activation>
|
<activeByDefault>false</activeByDefault>
|
||||||
<activeByDefault>false</activeByDefault>
|
</activation>
|
||||||
</activation>
|
<repositories>
|
||||||
<repositories>
|
<repository>
|
||||||
<repository>
|
<id>sonatype-snapshots</id>
|
||||||
<id>sonatype-snapshots</id>
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
<releases>
|
||||||
<releases>
|
<enabled>false</enabled>
|
||||||
<enabled>false</enabled>
|
</releases>
|
||||||
</releases>
|
<snapshots>
|
||||||
<snapshots>
|
<enabled>true</enabled>
|
||||||
<enabled>true</enabled>
|
</snapshots>
|
||||||
</snapshots>
|
</repository>
|
||||||
</repository>
|
</repositories>
|
||||||
</repositories>
|
<pluginRepositories>
|
||||||
<pluginRepositories>
|
<pluginRepository>
|
||||||
<pluginRepository>
|
<id>sonatype-snapshots</id>
|
||||||
<id>sonatype-snapshots</id>
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
<releases>
|
||||||
<releases>
|
<enabled>false</enabled>
|
||||||
<enabled>false</enabled>
|
</releases>
|
||||||
</releases>
|
<snapshots>
|
||||||
<snapshots>
|
<enabled>true</enabled>
|
||||||
<enabled>true</enabled>
|
</snapshots>
|
||||||
</snapshots>
|
</pluginRepository>
|
||||||
</pluginRepository>
|
</pluginRepositories>
|
||||||
</pluginRepositories>
|
</profile>
|
||||||
</profile>
|
</profiles>
|
||||||
|
<servers />
|
||||||
</profiles>
|
<mirrors />
|
||||||
|
|
||||||
<servers />
|
|
||||||
</settings>
|
</settings>
|
||||||
|
|||||||
Reference in New Issue
Block a user