mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-18 00:00:26 +08:00
update dependency, code cleanup
This commit is contained in:
@ -21,3 +21,4 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
|
post: 'cleanup.js'
|
||||||
|
|||||||
36
cleanup.js
Normal file
36
cleanup.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2020 Slawomir Jaranowski and contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const settings = require('./settings');
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
settings.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
||||||
|
module.exports = { run };
|
||||||
61
cleanup.test.js
Normal file
61
cleanup.test.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2020 Slawomir Jaranowski and contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const cp = require('child_process');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const process = require('process');
|
||||||
|
|
||||||
|
const cleanupPath = path.join(__dirname, 'cleanup.js');
|
||||||
|
|
||||||
|
const testHomePath = fs.mkdtempSync(".m2");
|
||||||
|
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
if (!fs.existsSync(testHomePath)) {
|
||||||
|
fs.mkdirSync(testHomePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.env['HOME'] = testHomePath;
|
||||||
|
process.env['USERPROFILE'] = testHomePath;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.rmdirSync(path.dirname(settingsPath));
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.rmdirSync(testHomePath);
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('run with default values', () => {
|
||||||
|
const out = cp.execSync(`node ${cleanupPath}`, { env: process.env }).toString();
|
||||||
|
console.log(out);
|
||||||
|
})
|
||||||
23
index.js
23
index.js
@ -1,29 +1,10 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const os = require('os');
|
|
||||||
const settings = require('./settings');
|
const settings = require('./settings');
|
||||||
|
|
||||||
|
|
||||||
// most @actions toolkit packages have async methods
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
|
settings.generate();
|
||||||
|
|
||||||
core.info('Prepare maven setings: ' + settingsPath);
|
|
||||||
|
|
||||||
if (fs.existsSync(settingsPath)) {
|
|
||||||
core.warning('maven settings.xml already exists - skip');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const templateXml = settings.getSettingsTemplate();
|
|
||||||
settings.fillServers(templateXml);
|
|
||||||
settings.fillProperties(templateXml);
|
|
||||||
settings.addSonatypeSnapshots(templateXml);
|
|
||||||
settings.writeSettings(settingsPath, templateXml);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -31,5 +12,3 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
module.exports = { run };
|
|
||||||
|
|||||||
@ -1,3 +1,26 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2020 Slawomir Jaranowski and contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -24,30 +47,48 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.rmdirSync(path.dirname(settingsPath));
|
fs.rmdirSync(path.dirname(settingsPath));
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
fs.rmdirSync(testHomePath);
|
fs.rmdirSync(testHomePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('run with default values', () => {
|
function assertSetingsFile() {
|
||||||
|
|
||||||
console.log(cp.execSync(`node ${indexPath}`, { env: process.env }).toString());
|
|
||||||
const settingsStatus = fs.lstatSync(settingsPath);
|
const settingsStatus = fs.lstatSync(settingsPath);
|
||||||
expect(settingsStatus.isFile()).toBeTruthy();
|
expect(settingsStatus.isFile()).toBeTruthy();
|
||||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const settingsBody = fs.readFileSync(settingsPath).toString();
|
||||||
|
expect(settingsBody).toMatch('<settings>');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('run with default values', () => {
|
||||||
|
|
||||||
|
const out = cp.execSync(`node ${indexPath}`, { env: process.env }).toString();
|
||||||
|
console.log(out);
|
||||||
|
|
||||||
|
assertSetingsFile();
|
||||||
})
|
})
|
||||||
|
|
||||||
test('run with all feature', () => {
|
test('run with all feature', () => {
|
||||||
|
|
||||||
process.env['INPUT_SERVERES'] = '[{"id": "serverId", "username": "username", "password": "password"}]';
|
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "username", "password": "password"}]';
|
||||||
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||||
process.env['INPUT_SONATYPESNAPSHOT'] = true;
|
process.env['INPUT_SONATYPESNAPSHOT'] = true;
|
||||||
|
|
||||||
console.log(cp.execSync(`node ${indexPath}`, { env: process.env }).toString());
|
const out = cp.execSync(`node ${indexPath}`, { env: process.env }).toString();
|
||||||
const settingsStatus = fs.lstatSync(settingsPath);
|
console.log(out);
|
||||||
expect(settingsStatus.isFile()).toBeTruthy();
|
|
||||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
assertSetingsFile();
|
||||||
|
|
||||||
|
const settingsBody = fs.readFileSync(settingsPath).toString();
|
||||||
|
expect(settingsBody).toMatch('<servers><server><id>serverId</id><username>username</username><password>password</password></server></servers>');
|
||||||
|
expect(settingsBody).toMatch('prop1');
|
||||||
})
|
})
|
||||||
|
|||||||
4469
package-lock.json
generated
4469
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,11 +25,11 @@
|
|||||||
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.0",
|
"@actions/core": "^1.2.0",
|
||||||
"xmldom": "^0.1.27",
|
"xmldom": "^0.2.1",
|
||||||
"xpath": "0.0.27"
|
"xpath": "0.0.27"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^6.7.1",
|
"eslint": "^6.8.0",
|
||||||
"jest": "^24.9.0"
|
"jest": "^25.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
settings.js
29
settings.js
@ -1,10 +1,14 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const DOMParser = require('xmldom').DOMParser;
|
const DOMParser = require('xmldom').DOMParser;
|
||||||
const XMLSerializer = require('xmldom').XMLSerializer;
|
const XMLSerializer = require('xmldom').XMLSerializer;
|
||||||
const xpath = require('xpath');
|
const xpath = require('xpath');
|
||||||
|
|
||||||
|
|
||||||
|
const settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
|
||||||
|
|
||||||
function getSettingsTemplate() {
|
function getSettingsTemplate() {
|
||||||
const templatePath = path.join(__dirname, 'templates', 'settings.xml');
|
const templatePath = path.join(__dirname, 'templates', 'settings.xml');
|
||||||
const templateStr = fs.readFileSync(templatePath).toString();
|
const templateStr = fs.readFileSync(templatePath).toString();
|
||||||
@ -82,10 +86,33 @@ function addSonatypeSnapshots(template) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generate() {
|
||||||
|
core.info('Prepare maven setings: ' + settingsPath);
|
||||||
|
|
||||||
|
if (fs.existsSync(settingsPath)) {
|
||||||
|
core.warning('maven settings.xml already exists - skip');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const templateXml = getSettingsTemplate();
|
||||||
|
fillServers(templateXml);
|
||||||
|
fillProperties(templateXml);
|
||||||
|
addSonatypeSnapshots(templateXml);
|
||||||
|
writeSettings(settingsPath, templateXml);
|
||||||
|
core.saveState('maven-settings', 'ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
const mavenSettingsState = core.getState('maven-settings');
|
||||||
|
core.info('Cleanup maven setings: ' + settingsPath + " state: " + mavenSettingsState);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSettingsTemplate,
|
getSettingsTemplate,
|
||||||
writeSettings,
|
writeSettings,
|
||||||
fillServers,
|
fillServers,
|
||||||
fillProperties,
|
fillProperties,
|
||||||
addSonatypeSnapshots
|
addSonatypeSnapshots,
|
||||||
|
generate,
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user