Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Merge pull request #73 from whelk-io/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zteater authored Nov 12, 2020
2 parents a43ecf2 + 100a268 commit f2ce02a
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].3
- uses: actions/[email protected].4
- run: |
npm ci
npm test
test_job:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].3
- uses: actions/[email protected].4
- name: Create maven settings.xml
uses: ./
with:
Expand All @@ -27,6 +27,7 @@ jobs:
repositories: '[{"id": "foo", "url": "https://fu.bar"}]'
plugin_repositories: '[{"id": "foo-plugin", "url": "https://fu.bar.plugin"}]'
profiles: '[{ "id": "foo.profile", "name": "foo.profile", "url": "http://foo.bar.profile", "properties": { "foo": "property-1", "bar": "property-2"} }]'
plugin_groups: '[ "some.plugin.group.id", "some.other.plugin.group.id" ]'
- run: |
cat ~/.m2/settings.xml
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Reference: [Maven Settings > Plugin Repositories](http://maven.apache.org/settin

Reference: [Maven Settings > Repositories](http://maven.apache.org/settings.html#Plugin_Repositories)

### `plugin_groups`
**Optional** json array of plugin groups to add to settings.xml

Reference: [Maven Settings > Plugin Groups](http://maven.apache.org/settings.html#Plugin_Groups)

### `profiles`
**Optional** json array of profiles to add to settings.xml

Expand Down Expand Up @@ -125,6 +130,7 @@ Reference: [Maven Settings > Profiles](http://maven.apache.org/settings.html#pro
servers: '[{ "id": "some-server", "username": "some.user", "password": "some.password" }]'
mirrors: '[{ "id": "nexus", "mirrorOf": "!my-org-snapshots,*", "url": "http://redacted/nexus/content/groups/public" }]'
profiles: '[{ "id": "foo.profile", "name": "foo.profile", "url": "http://foo.bar.profile", "properties": { "foo": "property-1", "bar": "property-2"} }]'
plugin_groups: '[ "some.plugin.group.id", "some.other.plugin.group.id" ]'

````

Expand Down Expand Up @@ -207,5 +213,10 @@ Reference: [Maven Settings > Profiles](http://maven.apache.org/settings.html#pro
</mirror>
</mirrors>

<pluginGroups>
<pluginGroup>some.plugin.group.id</pluginGroup>
<pluginGroup>some.other.plugin.group.id</pluginGroup>
</pluginGroups>

</settings>
````
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ inputs:
profiles:
description: 'json array of profiles to add to settings.xml'
required: false
plugin_groups:
description: 'json array of plugin groups to add to settings.xml'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
124 changes: 104 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,75 @@ module.exports =
/************************************************************************/
/******/ ({

/***/ 82:
/***/ (function(__unusedmodule, exports) {

"use strict";

// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
//# sourceMappingURL=utils.js.map

/***/ }),

/***/ 87:
/***/ (function(module) {

module.exports = require("os");

/***/ }),

/***/ 102:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

// For internal use, subject to change.
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Missing file at path: ${filePath}`);
}
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
encoding: 'utf8'
});
}
exports.issueCommand = issueCommand;
//# sourceMappingURL=file-command.js.map

/***/ }),

/***/ 431:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

Expand All @@ -64,6 +126,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(__webpack_require__(87));
const utils_1 = __webpack_require__(82);
/**
* Commands
*
Expand Down Expand Up @@ -117,28 +180,14 @@ class Command {
return cmdStr;
}
}
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
*/
function toCommandValue(input) {
if (input === null || input === undefined) {
return '';
}
else if (typeof input === 'string' || input instanceof String) {
return input;
}
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
function escapeData(s) {
return toCommandValue(s)
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
}
function escapeProperty(s) {
return toCommandValue(s)
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
Expand Down Expand Up @@ -1435,6 +1484,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __webpack_require__(431);
const file_command_1 = __webpack_require__(102);
const utils_1 = __webpack_require__(82);
const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622));
/**
Expand All @@ -1461,9 +1512,17 @@ var ExitCode;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function exportVariable(name, val) {
const convertedVal = command_1.toCommandValue(val);
const convertedVal = utils_1.toCommandValue(val);
process.env[name] = convertedVal;
command_1.issueCommand('set-env', { name }, convertedVal);
const filePath = process.env['GITHUB_ENV'] || '';
if (filePath) {
const delimiter = '_GitHubActionsFileCommandDelimeter_';
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand('ENV', commandValue);
}
else {
command_1.issueCommand('set-env', { name }, convertedVal);
}
}
exports.exportVariable = exportVariable;
/**
Expand All @@ -1479,7 +1538,13 @@ exports.setSecret = setSecret;
* @param inputPath
*/
function addPath(inputPath) {
command_1.issueCommand('add-path', {}, inputPath);
const filePath = process.env['GITHUB_PATH'] || '';
if (filePath) {
file_command_1.issueCommand('PATH', inputPath);
}
else {
command_1.issueCommand('add-path', {}, inputPath);
}
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
}
exports.addPath = addPath;
Expand Down Expand Up @@ -2290,6 +2355,7 @@ function run() {
settings.updateRepositories(templateXml);
settings.updatePluginRepositories(templateXml);
settings.updateProfiles(templateXml)
settings.updatePluginGroups(templateXml)

// write template to filepath
var settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
Expand Down Expand Up @@ -3000,14 +3066,32 @@ function updateProfiles(templateXml) {
});
}

function updatePluginGroups(templateXml) {
var pluginGroupsInput = core.getInput('plugin_groups');

if (!pluginGroupsInput) {
return;
}

var pluginGroupsXml = templateXml.getElementsByTagName('pluginGroups')[0];

JSON.parse(pluginGroupsInput).forEach((pluginGroupInput) => {
var pluginGroupXml = templateXml.createElement('pluginGroup');
pluginGroupXml.textContent = pluginGroupInput;
pluginGroupsXml.appendChild(pluginGroupXml);
});

}

module.exports = {
getSettingsTemplate,
writeSettings,
updateServers,
updateMirrors,
updateRepositories,
updatePluginRepositories,
updateProfiles
updateProfiles,
updatePluginGroups
}

/***/ })
Expand Down
2 changes: 2 additions & 0 deletions dist/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@

<mirrors/>

<pluginGroups/>

</settings>
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function run() {
settings.updateRepositories(templateXml);
settings.updatePluginRepositories(templateXml);
settings.updateProfiles(templateXml)
settings.updatePluginGroups(templateXml)

// write template to filepath
var settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
Expand Down
20 changes: 19 additions & 1 deletion src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,30 @@ function updateProfiles(templateXml) {
});
}

function updatePluginGroups(templateXml) {
var pluginGroupsInput = core.getInput('plugin_groups');

if (!pluginGroupsInput) {
return;
}

var pluginGroupsXml = templateXml.getElementsByTagName('pluginGroups')[0];

JSON.parse(pluginGroupsInput).forEach((pluginGroupInput) => {
var pluginGroupXml = templateXml.createElement('pluginGroup');
pluginGroupXml.textContent = pluginGroupInput;
pluginGroupsXml.appendChild(pluginGroupXml);
});

}

module.exports = {
getSettingsTemplate,
writeSettings,
updateServers,
updateMirrors,
updateRepositories,
updatePluginRepositories,
updateProfiles
updateProfiles,
updatePluginGroups
}
2 changes: 2 additions & 0 deletions template/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@

<mirrors/>

<pluginGroups/>

</settings>
19 changes: 19 additions & 0 deletions test/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,24 @@ describe('run settings.js', function () {
});
});

describe('#updatePluginGroups', function () {
it('<pluginGroups/> should be appended with <pluginGroup> when input.pluginGroups is present', function () {
// given input
process.env['INPUT_PLUGIN_GROUPS'] = '[ "some.plugin.group.id" ]';

// and default settings
var xml = new DOMParser().parseFromString("<settings><pluginGroups/></settings>");

// when
settings.updatePluginGroups(xml);

// then
var expectedXml = '<settings><pluginGroups><pluginGroup>some.plugin.group.id</pluginGroup></pluginGroups></settings>';
assert.equal(new XMLSerializer().serializeToString(xml), expectedXml);

process.env['INPUT_PLUGIN_GROUPS'] = '';
});
});

});

0 comments on commit f2ce02a

Please sign in to comment.