19 Commits

Author SHA1 Message Date
e967605742 update dependency after merge from master 2021-02-28 20:25:07 +01:00
e65dc96bde Merge remote-tracking branch 'origin/master' into releases/v2 2021-02-28 20:22:43 +01:00
b742fc533f prepare release 2.4.0 2021-02-28 20:20:35 +01:00
d1f8f65870 Merge pull request #97 from s4u/dependabot/github_actions/actions/setup-node-v2.1.5
Bump actions/setup-node from v2.1.4 to v2.1.5
2021-02-28 11:42:22 +01:00
de53ea431e Bump actions/setup-node from v2.1.4 to v2.1.5
Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.4 to v2.1.5.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2.1.4...46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-23 09:00:30 +00:00
cd16d8406c Completed the attribute support for servers. (#95)
* Completed the attribute support for servers, and password is optional. Resolves #92.

* Updated oracleServers.xml template to match new servers.xml template.

* Revised tests to match code and template changes.

* Added documentation for server attributes.

* Added additional use cases to exercise server attribute handling.
2021-02-16 22:46:27 +01:00
abf1253b29 Merge pull request #94 from awhitford/typos
Corrected typos. Resolves #93.
2021-02-16 08:29:57 +01:00
7a5cb7ba33 Merge pull request #91 from s4u/dependabot/npm_and_yarn/eslint-7.20.0
Bump eslint from 7.19.0 to 7.20.0
2021-02-16 08:27:27 +01:00
7799be5210 Bump eslint from 7.19.0 to 7.20.0
Bumps [eslint](https://github.com/eslint/eslint) from 7.19.0 to 7.20.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.19.0...v7.20.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-16 07:19:24 +00:00
82e778d8d7 File sync from s4u/.github 2021-02-16 07:05:18 +00:00
175b85e48d Corrected typos. Resolves #93. 2021-02-15 14:23:05 -08:00
40cb7c6ba4 Merge pull request #89 from s4u/dependabot/npm_and_yarn/eslint-7.19.0
Bump eslint from 7.18.0 to 7.19.0
2021-02-07 14:43:44 +01:00
a154ae5bb3 Bump eslint from 7.18.0 to 7.19.0
Bumps [eslint](https://github.com/eslint/eslint) from 7.18.0 to 7.19.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.18.0...v7.19.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-01 09:06:12 +00:00
26b06607c7 Merge pull request #88 from s4u/dependabot/npm_and_yarn/eslint-7.18.0
Bump eslint from 7.17.0 to 7.18.0
2021-01-18 20:00:27 +01:00
5391894326 Bump eslint from 7.17.0 to 7.18.0
Bumps [eslint](https://github.com/eslint/eslint) from 7.17.0 to 7.18.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.17.0...v7.18.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-01-18 09:01:10 +00:00
a9c25dcc48 Merge pull request #87 from s4u/dependabot/npm_and_yarn/eslint-7.17.0
Bump eslint from 7.16.0 to 7.17.0
2021-01-04 11:22:39 +01:00
6240d8dec2 Bump eslint from 7.16.0 to 7.17.0
Bumps [eslint](https://github.com/eslint/eslint) from 7.16.0 to 7.17.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.16.0...v7.17.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-01-04 09:01:04 +00:00
0ae2055ed1 File sync from s4u/.github 2020-12-29 18:32:24 +00:00
eb98cf558d File sync from s4u/.github 2020-12-28 00:31:56 +00:00
14 changed files with 848 additions and 502 deletions

View File

@ -9,12 +9,12 @@ categories:
- 'bug' - 'bug'
- title: 'Maintenance' - title: 'Maintenance'
label: labels:
- 'code quality' - 'code quality'
- 'documentation' - 'documentation'
- title: 'Dependency updates' - title: 'Dependency updates'
label: labels:
- 'dependencies' - 'dependencies'
change-template: '- $TITLE #$NUMBER' change-template: '- $TITLE #$NUMBER'

View File

@ -19,7 +19,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
- uses: actions/setup-node@v2.1.4 - uses: actions/setup-node@v2.1.5
with: with:
node-version: '12.x' node-version: '12.x'

View File

@ -2,15 +2,18 @@ name: Release Drafter
on: on:
push: push:
# branches to consider in the event; optional, defaults to all
branches: branches:
- master - 'master'
jobs: jobs:
update_release_draft: update_release_draft:
name: Update Release Draft name: Update Release Draft
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: >
github.repository_owner == 's4u'
&& !startsWith(github.event.head_commit.message , '[maven-release-plugin]')
steps: steps:
- uses: release-drafter/release-drafter@v5.12.1 - uses: release-drafter/release-drafter@v5.14.0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -19,7 +19,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
- uses: actions/setup-node@v2.1.4 - uses: actions/setup-node@v2.1.5
with: with:
node-version: '12.x' node-version: '12.x'

View File

@ -28,23 +28,35 @@ See [action.yml](action.yml)
## default ```settings.xml``` ## default ```settings.xml```
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
``` ```
## ```settings.xml``` with servers section ## ```settings.xml``` with servers section
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]' servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
``` ```
All `server` attributes may be specified:
* `id` _(required)_
* `username`
* `password`
* `privateKey`
* `passphrase`
* `filePermissions`
* `directoryPermissions`
* `configuration`
Please refer to the [servers](http://maven.apache.org/settings.html#Servers) documentation for more information.
## ```settings.xml``` with servers section and additional configuration ## ```settings.xml``` with servers section and additional configuration
``` yml ``` yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
servers: | servers: |
[{ [{
@ -78,7 +90,7 @@ result will be:
## ```settings.xml``` with mirrors section ## ```settings.xml``` with mirrors section
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]' mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
``` ```
@ -86,7 +98,7 @@ steps:
## ```settings.xml``` with properties ## ```settings.xml``` with properties
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]' properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
``` ```
@ -95,7 +107,7 @@ steps:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
sonatypeSnapshots: true sonatypeSnapshots: true
``` ```
@ -104,7 +116,7 @@ steps:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
apacheSnapshots: true apacheSnapshots: true
``` ```
@ -112,7 +124,7 @@ steps:
## Do not override existing ```settings.xml```, from version **2.0** file is override by default : ## Do not override existing ```settings.xml```, from version **2.0** file is override by default :
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
override: false override: false
``` ```
@ -120,7 +132,7 @@ steps:
## Do not add github to server in ```settings.xml```, by default is added: ## Do not add github to server in ```settings.xml```, by default is added:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
githubServer: false githubServer: false
``` ```
@ -129,7 +141,7 @@ steps:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]' oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
``` ```
@ -137,7 +149,7 @@ steps:
## ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017) ## ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017)
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
oracleRepo: true oracleRepo: true
``` ```
@ -148,7 +160,7 @@ It is also possible pass in Github Secrets e.g.
``` yml ``` yml
steps: steps:
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
with: with:
servers: | servers: |
[{ [{
@ -178,7 +190,7 @@ steps:
with: with:
java-version: 8 java-version: 8
- uses: s4u/maven-settings-action@v2.3.0 - uses: s4u/maven-settings-action@v2.4.0
- run: mvn verify - run: mvn verify
``` ```

View File

@ -1,4 +1,4 @@
name: 'maven-setings-action' name: 'maven-settings-action'
description: 'Prepare maven settings.xml' description: 'Prepare maven settings.xml'
branding: branding:
@ -7,7 +7,7 @@ branding:
inputs: inputs:
servers: servers:
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]' description: 'servers definition in json array, eg: [{"id": "serverId", "username": "username", "password": "password"}]'
required: false required: false
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"}]'
@ -32,7 +32,7 @@ inputs:
default: "true" default: "true"
required: false required: false
oracleServers: oracleServers:
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}] for Oracle repository' description: 'servers definition in json array, eg: [{"id": "serverId", "username": "username", "password": "password"}] for Oracle repository'
required: false required: false
oracleRepo: oracleRepo:
description: 'add Oracle Maven Repository' description: 'add Oracle Maven Repository'

View File

@ -63,11 +63,11 @@ afterAll(() => {
test('run with all feature', () => { test('run with all feature', () => {
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "sUsername", "password": "sPassword", "configuration": {"props1": "value1"}}]'; process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "sUsername", "password": "sPassword", "configuration": {"props1": "value1"}}]';
process.env['INPUT_ORACLESERVERS'] = '[{"id": "oServerId", "username": "oUsername", "password": "oPassword"}]'; process.env['INPUT_ORACLESERVERS'] = '[{"id": "oServerId", "username": "oUsername", "password": "oPassword"}]';
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_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]' process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
process.env['INPUT_APACHESNAPSHOTS'] = true; process.env['INPUT_APACHESNAPSHOTS'] = true;
@ -80,7 +80,7 @@ test('run with all feature', () => {
expect(settingsStatus.isFile()).toBeTruthy(); expect(settingsStatus.isFile()).toBeTruthy();
expect(settingsStatus.size).toBeGreaterThan(0); expect(settingsStatus.size).toBeGreaterThan(0);
const settingsBody = fs.readFileSync(settingsPath).toString().replace(/^ $/mg, ''); const settingsBody = fs.readFileSync(settingsPath).toString().replace(/^\s*$(?:\r\n?|\n)/gm, '');
expect(settingsBody).toBe(`<settings> expect(settingsBody).toBe(`<settings>
<interactiveMode>false</interactiveMode> <interactiveMode>false</interactiveMode>
<profiles> <profiles>
@ -214,7 +214,6 @@ test('run with all feature', () => {
<id>github</id> <id>github</id>
<username>\${env.GITHUB_ACTOR}</username> <username>\${env.GITHUB_ACTOR}</username>
<password>\${env.GITHUB_TOKEN}</password> <password>\${env.GITHUB_TOKEN}</password>
</server></servers> </server></servers>
<mirrors> <mirrors>
<mirror> <mirror>

2
node_modules/.package-lock.json generated vendored
View File

@ -1,6 +1,6 @@
{ {
"name": "maven-settings-action", "name": "maven-settings-action",
"version": "2.3.0", "version": "2.4.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

1080
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "maven-settings-action", "name": "maven-settings-action",
"version": "2.3.0", "version": "2.4.0",
"description": "Prepare maven settings", "description": "Prepare maven settings",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -28,7 +28,7 @@
"xmldom": "^0.4.0" "xmldom": "^0.4.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.16.0", "eslint": "^7.20.0",
"jest": "^26.6.3" "jest": "^26.6.3"
} }
} }

View File

@ -54,7 +54,7 @@ function jsonToXml(templateXml, xmlTag, json) {
for (const key in json) { for (const key in json) {
const keyXml = templateXml.createElement(key); const keyXml = templateXml.createElement(key);
const value = json[key]; const value = json[key];
if ( value instanceof Object) { if (value instanceof Object) {
jsonToXml(templateXml, keyXml, value); jsonToXml(templateXml, keyXml, value);
} else { } else {
keyXml.textContent = value; keyXml.textContent = value;
@ -63,28 +63,32 @@ function jsonToXml(templateXml, xmlTag, json) {
} }
} }
function fillServer(templateXml, templateName, id, username, password, configurations) { function fillServer(templateXml, templateName, id, username, password, privateKey, passphrase, filePermissions, directoryPermissions, configurations) {
if (!id || ((!username || !password) && !configurations) ) { if (!id || (!username && !configurations)) {
core.setFailed(templateName + ' must contain id, (username and password) or configuration'); core.setFailed(templateName + ' must contain id, and username or configuration');
return; return;
} }
const serverXml = getTemplate(templateName + '.xml') const serverXml = getTemplate(templateName + '.xml')
serverXml.getElementsByTagName('id')[0].textContent = id; serverXml.getElementsByTagName('id')[0].textContent = id;
const usernameTag = serverXml.getElementsByTagName('username')[0]; const serverTags = {
if (username) { 'username': username,
usernameTag.textContent = username; 'password': password,
} else { 'privateKey': privateKey,
serverXml.documentElement.removeChild(usernameTag); 'passphrase': passphrase,
} 'filePermissions': filePermissions,
'directoryPermissions': directoryPermissions
const passwordTag = serverXml.getElementsByTagName('password')[0]; };
if (password) { for (const tag in serverTags) {
passwordTag.textContent = password; const serverTag = serverXml.getElementsByTagName(tag)[0];
} else { const tagValue = serverTags[tag];
serverXml.documentElement.removeChild(passwordTag); if (tagValue) {
serverTag.textContent = tagValue;
} else {
serverXml.documentElement.removeChild(serverTag);
}
} }
const configurationTag = serverXml.getElementsByTagName('configuration')[0]; const configurationTag = serverXml.getElementsByTagName('configuration')[0];
@ -109,7 +113,10 @@ function fillServers(template, templateName) {
} }
JSON.parse(servers).forEach((server) => JSON.parse(servers).forEach((server) =>
fillServer(template, templateName, server.id, server.username, server.password, server.configuration)); fillServer(template, templateName, server.id, server.username,
server.password, server.privateKey, server.passphrase,
server.filePermissions, server.directoryPermissions,
server.configuration));
} }
function fillMirror(template, id, name, mirrorOf, url) { function fillMirror(template, id, name, mirrorOf, url) {

View File

@ -38,6 +38,14 @@ const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
var consoleOutput = []; var consoleOutput = [];
function stringAsXml(str) {
return new DOMParser().parseFromString(str, 'text/xml');
}
function xmlAsString(xml) {
return new XMLSerializer().serializeToString(xml).replace(/^\s*$(?:\r\n?|\n)/gm, '');
}
beforeAll(() => { beforeAll(() => {
if (!fs.existsSync(testHomePath)) { if (!fs.existsSync(testHomePath)) {
fs.mkdirSync(testHomePath); fs.mkdirSync(testHomePath);
@ -51,7 +59,7 @@ beforeAll(() => {
}); });
beforeEach(() => { beforeEach(() => {
xmlTestProfile = new DOMParser().parseFromString(`<settings> xmlTestProfile = stringAsXml(`<settings>
<profiles> <profiles>
<profile> <profile>
<id>_properties_</id> <id>_properties_</id>
@ -119,7 +127,7 @@ test('xml should be write', () => {
test('fillServers do nothing if no params', () => { test('fillServers do nothing if no params', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
@ -130,54 +138,46 @@ test('fillServers do nothing if no params', () => {
test('fillServers one server', () => { test('fillServers one server', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, ''); expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<username>username1</username> <username>username1</username>
<password>password1</password> <password>password1</password>
</server></servers>`); </server></servers>`);
}); });
test('fillServers with username and configuration', () => { test('fillServers with username and configuration', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, '') expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<username>username</username> <username>username</username>
<configuration><prop1>prop1Value</prop1><prop2>prop2Value</prop2></configuration> <configuration><prop1>prop1Value</prop1><prop2>prop2Value</prop2></configuration>
</server></servers>`); </server></servers>`);
}); });
test('fillServers with username, password and configuration', () => { test('fillServers with username, password and configuration', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "password": "password", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "password": "password", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, '') expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<username>username</username> <username>username</username>
@ -186,73 +186,115 @@ test('fillServers with username, password and configuration', () => {
</server></servers>`); </server></servers>`);
}); });
test('fillServers with username, privateKey', () => {
const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "privateKey": "${user.home}/.ssh/id_rsa"}]';
settings.fillServers(xml, 'servers');
expect(xmlAsString(xml)).toBe(`<servers>
<server>
<id>id1</id>
<username>username</username>
<privateKey>\${user.home}/.ssh/id_rsa</privateKey>
</server></servers>`);
});
test('fillServers with username, privateKey, and passphrase', () => {
const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username", "privateKey": "${user.home}/.ssh/id_rsa", "passphrase": "secret"}]';
settings.fillServers(xml, 'servers');
expect(xmlAsString(xml)).toBe(`<servers>
<server>
<id>id1</id>
<username>username</username>
<privateKey>\${user.home}/.ssh/id_rsa</privateKey>
<passphrase>secret</passphrase>
</server></servers>`);
});
test('fillServers with all attributes', () => {
const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "server001", "username": "my_login", "password": "my_password", "privateKey": "${user.home}/.ssh/id_dsa", "passphrase": "some_passphrase", "filePermissions": "664", "directoryPermissions": "775", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"} }]';
settings.fillServers(xml, 'servers');
expect(xmlAsString(xml)).toBe(`<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>\${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration><prop1>prop1Value</prop1><prop2>prop2Value</prop2></configuration>
</server></servers>`);
});
test('fillServers with configuration', () => { test('fillServers with configuration', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "configuration": {"prop1": "prop1Value", "prop2": "prop2Value"}}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, '') expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<configuration><prop1>prop1Value</prop1><prop2>prop2Value</prop2></configuration> <configuration><prop1>prop1Value</prop1><prop2>prop2Value</prop2></configuration>
</server></servers>`); </server></servers>`);
}); });
test('fillServers with configuration subLevel', () => { test('fillServers with configuration subLevel', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "configuration": {"prop1": {"prop11": "value11", "prop12": "value12"}, "prop2": "value2"}}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "configuration": {"prop1": {"prop11": "value11", "prop12": "value12"}, "prop2": "value2"}}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, '') expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<configuration><prop1><prop11>value11</prop11><prop12>value12</prop12></prop1><prop2>value2</prop2></configuration> <configuration><prop1><prop11>value11</prop11><prop12>value12</prop12></prop1><prop2>value2</prop2></configuration>
</server></servers>`); </server></servers>`);
}); });
test('fillServers two servers', () => { test('fillServers two servers', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"},\ process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"},\
{"id": "id2", "username": "username2", "password":"password2"}]'; {"id": "id2", "username": "username2", "password":"password2"}]';
settings.fillServers(xml, 'servers'); settings.fillServers(xml, 'servers');
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, ''); expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<username>username1</username> <username>username1</username>
<password>password1</password> <password>password1</password>
</server> </server>
<server> <server>
<id>id2</id> <id>id2</id>
<username>username2</username> <username>username2</username>
<password>password2</password> <password>password2</password>
</server></servers>`); </server></servers>`);
}); });
test('fill servers incorrect fields', () => { test('fill servers incorrect fields', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_SERVERS'] = '[{"idx": "id1"}]'; process.env['INPUT_SERVERS'] = '[{"idx": "id1"}]';
@ -263,22 +305,20 @@ test('fill servers incorrect fields', () => {
expect(xmlStr).toBe('<servers/>'); expect(xmlStr).toBe('<servers/>');
expect(consoleOutput).toEqual( expect(consoleOutput).toEqual(
expect.arrayContaining([ expect.arrayContaining([
expect.stringMatching(/::error::servers must contain id, \(username and password\) or configuration/) expect.stringMatching(/::error::servers must contain id, and username or configuration/)
]) ])
); );
}); });
test('fill oracleServers', () => { test('fill oracleServers', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_ORACLESERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]'; process.env['INPUT_ORACLESERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
settings.fillServers(xml, 'oracleServers'); settings.fillServers(xml, 'oracleServers');
const xmlStr = new XMLSerializer().serializeToString(xml); expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>id1</id> <id>id1</id>
<username>username1</username> <username>username1</username>
@ -305,27 +345,24 @@ test('fill oracleServers', () => {
test('fillServers github', () => { test('fillServers github', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = stringAsXml("<servers/>");
process.env['INPUT_GITHUBSERVER'] = 'true'; process.env['INPUT_GITHUBSERVER'] = 'true';
settings.fillServerForGithub(xml); settings.fillServerForGithub(xml);
const xmlStr = new XMLSerializer().serializeToString(xml).replace(/^ $/mg, ''); expect(xmlAsString(xml)).toBe(`<servers>
expect(xmlStr).toBe(`<servers>
<server> <server>
<id>github</id> <id>github</id>
<username>\${env.GITHUB_ACTOR}</username> <username>\${env.GITHUB_ACTOR}</username>
<password>\${env.GITHUB_TOKEN}</password> <password>\${env.GITHUB_TOKEN}</password>
</server></servers>`); </server></servers>`);
expect(consoleOutput).toEqual([]); expect(consoleOutput).toEqual([]);
}); });
test('fillMirrors do nothing if no params', () => { test('fillMirrors do nothing if no params', () => {
const xml = new DOMParser().parseFromString("<mirrors/>"); const xml = stringAsXml("<mirrors/>");
settings.fillMirrors(xml); settings.fillMirrors(xml);
@ -337,7 +374,7 @@ test('fillMirrors do nothing if no params', () => {
test('fillMirrors one mirror', () => { test('fillMirrors one mirror', () => {
const xml = new DOMParser().parseFromString("<mirrors/>"); const xml = stringAsXml("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name", "mirrorOf":"mirrorOf", "url":"url"}]'; process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name", "mirrorOf":"mirrorOf", "url":"url"}]';
@ -357,7 +394,7 @@ test('fillMirrors one mirror', () => {
test('fillMirrors two mirrors', () => { test('fillMirrors two mirrors', () => {
const xml = new DOMParser().parseFromString("<mirrors/>"); const xml = stringAsXml("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name1", "mirrorOf":"mirrorOf1", "url":"url1"},{"id": "id2", "name": "name2", "mirrorOf":"mirrorOf2", "url":"url2"}]'; process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name1", "mirrorOf":"mirrorOf1", "url":"url1"},{"id": "id2", "name": "name2", "mirrorOf":"mirrorOf2", "url":"url2"}]';
@ -383,7 +420,7 @@ test('fillMirrors two mirrors', () => {
test('fillMirrors incorrect fields', () => { test('fillMirrors incorrect fields', () => {
const xml = new DOMParser().parseFromString("<mirrors/>"); const xml = stringAsXml("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"idx": "id1"}]'; process.env['INPUT_MIRRORS'] = '[{"idx": "id1"}]';
@ -403,7 +440,7 @@ test('addApacheSnapshots', () => {
process.env['INPUT_APACHESNAPSHOTS'] = "true"; process.env['INPUT_APACHESNAPSHOTS'] = "true";
const xml = new DOMParser().parseFromString('<profiles/>'); const xml = stringAsXml('<profiles/>');
settings.addApacheSnapshots(xml); settings.addApacheSnapshots(xml);
@ -445,7 +482,7 @@ test('addSonatypeSnapshots', () => {
process.env['INPUT_SONATYPESNAPSHOTS'] = "true"; process.env['INPUT_SONATYPESNAPSHOTS'] = "true";
const xml = new DOMParser().parseFromString('<profiles/>'); const xml = stringAsXml('<profiles/>');
settings.addSonatypeSnapshots(xml); settings.addSonatypeSnapshots(xml);
@ -487,7 +524,7 @@ test('addOracleRepo', () => {
process.env['INPUT_ORACLEREPO'] = "true"; process.env['INPUT_ORACLEREPO'] = "true";
const xml = new DOMParser().parseFromString('<profiles/>'); const xml = stringAsXml('<profiles/>');
settings.addOracleRepo(xml); settings.addOracleRepo(xml);
@ -529,7 +566,7 @@ test('fillProperties', () => {
process.env['INPUT_PROPERTIES'] = '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'; process.env['INPUT_PROPERTIES'] = '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]';
const xml = new DOMParser().parseFromString('<profiles/>'); const xml = stringAsXml('<profiles/>');
settings.fillProperties(xml); settings.fillProperties(xml);

View File

@ -3,6 +3,10 @@
<id /> <id />
<username /> <username />
<password /> <password />
<privateKey />
<passphrase />
<filePermissions />
<directoryPermissions />
<configuration> <configuration>
<basicAuthScope> <basicAuthScope>
<host>ANY</host> <host>ANY</host>

View File

@ -3,5 +3,9 @@
<id /> <id />
<username /> <username />
<password /> <password />
<privateKey />
<passphrase />
<filePermissions />
<directoryPermissions />
<configuration /> <configuration />
</server> </server>