Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed the attribute support for servers. #95

Merged
merged 5 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ steps:
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

``` yml
Expand Down
11 changes: 5 additions & 6 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ afterAll(() => {

test('run with all feature', () => {

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_GITHUBSERVER'] = true;
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "sUsername", "password": "sPassword", "configuration": {"props1": "value1"}}]';
awhitford marked this conversation as resolved.
Show resolved Hide resolved
process.env['INPUT_ORACLESERVERS'] = '[{"id": "oServerId", "username": "oUsername", "password": "oPassword"}]';
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_APACHESNAPSHOTS'] = true;
Expand All @@ -80,7 +80,7 @@ test('run with all feature', () => {
expect(settingsStatus.isFile()).toBeTruthy();
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>
<interactiveMode>false</interactiveMode>
<profiles>
Expand Down Expand Up @@ -214,7 +214,6 @@ test('run with all feature', () => {
<id>github</id>
<username>\${env.GITHUB_ACTOR}</username>
<password>\${env.GITHUB_TOKEN}</password>

</server></servers>
<mirrors>
<mirror>
Expand Down
41 changes: 24 additions & 17 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function jsonToXml(templateXml, xmlTag, json) {
for (const key in json) {
const keyXml = templateXml.createElement(key);
const value = json[key];
if ( value instanceof Object) {
if (value instanceof Object) {
jsonToXml(templateXml, keyXml, value);
} else {
keyXml.textContent = value;
Expand All @@ -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) ) {
core.setFailed(templateName + ' must contain id, (username and password) or configuration');
if (!id || (!username && !configurations)) {
core.setFailed(templateName + ' must contain id, and username or configuration');
return;
}

const serverXml = getTemplate(templateName + '.xml')
serverXml.getElementsByTagName('id')[0].textContent = id;

const usernameTag = serverXml.getElementsByTagName('username')[0];
if (username) {
usernameTag.textContent = username;
} else {
serverXml.documentElement.removeChild(usernameTag);
}

const passwordTag = serverXml.getElementsByTagName('password')[0];
if (password) {
passwordTag.textContent = password;
} else {
serverXml.documentElement.removeChild(passwordTag);
const serverTags = {
'username': username,
'password': password,
'privateKey': privateKey,
'passphrase': passphrase,
'filePermissions': filePermissions,
'directoryPermissions': directoryPermissions
};
for (const tag in serverTags) {
const serverTag = serverXml.getElementsByTagName(tag)[0];
const tagValue = serverTags[tag];
if (tagValue) {
serverTag.textContent = tagValue;
} else {
serverXml.documentElement.removeChild(serverTag);
}
}

const configurationTag = serverXml.getElementsByTagName('configuration')[0];
Expand All @@ -109,7 +113,10 @@ function fillServers(template, templateName) {
}

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) {
Expand Down
Loading