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/v1
This commit is contained in:
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@ -5,11 +5,22 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: '12.x'
|
||||||
|
- run: npm version
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
- run: npm audit
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||||
@ -17,3 +28,4 @@ jobs:
|
|||||||
sonatypeSnapshots: true
|
sonatypeSnapshots: true
|
||||||
|
|
||||||
- run: cat ~/.m2/settings.xml
|
- run: cat ~/.m2/settings.xml
|
||||||
|
shell: bash
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
# maven-settings-action
|
# maven-settings-action
|
||||||
|
[](https://github.com/s4u/maven-settings-action/actions)
|
||||||
|
|
||||||
This action setup maven environment for use in action by:
|
This action setup maven environment for use in action by:
|
||||||
- create maven setings.xml
|
- create maven setings.xml
|
||||||
|
|||||||
8
index.js
8
index.js
@ -1,6 +1,7 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const settings = require('./settings');
|
const settings = require('./settings');
|
||||||
|
|
||||||
|
|
||||||
@ -8,10 +9,11 @@ const settings = require('./settings');
|
|||||||
async function run() {
|
async function run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const settingsPath = path.join(process.env.HOME, '.m2', 'settings.xml');
|
const settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
|
||||||
core.info('Prepare maven setings: ' + settingsPath);
|
|
||||||
|
|
||||||
if ( fs.existsSync(settingsPath) ) {
|
core.info('Prepare maven setings: ' + settingsPath);
|
||||||
|
|
||||||
|
if (fs.existsSync(settingsPath)) {
|
||||||
core.warning('maven settings.xml already exists - skip');
|
core.warning('maven settings.xml already exists - skip');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const cp = require('child_process');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const testHomePath = path.join(__dirname, 'temp');
|
const testHomePath = fs.mkdtempSync(".m2");
|
||||||
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
|
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
|
||||||
const indexPath = path.join(__dirname, 'index.js');
|
const indexPath = path.join(__dirname, 'index.js');
|
||||||
|
|
||||||
@ -13,22 +13,21 @@ beforeAll(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.env['HOME'] = testHomePath;
|
process.env['HOME'] = testHomePath;
|
||||||
|
process.env['USERPROFILE'] = testHomePath;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(settingsPath);
|
fs.unlinkSync(settingsPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
try {
|
try {
|
||||||
fs.rmdirSync(path.join(testHomePath, ".m2"));
|
fs.rmdirSync(path.dirname(settingsPath));
|
||||||
fs.rmdirSync(testHomePath);
|
fs.rmdirSync(testHomePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
6
package-lock.json
generated
6
package-lock.json
generated
@ -5,9 +5,9 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.3.tgz",
|
||||||
"integrity": "sha512-l8Ol2wEzFeuhV1v7LbGB2x8ghXSnmUiSVKVSjsNwgqAU4i5LvGRXpM+kli9gNMkGVudwZYHET4qZ5DTep5Sssw=="
|
"integrity": "sha512-2BIib53Jh4Cfm+1XNuZYYGTeRo8yiWEAUMoliMh1qQGMaqTF4VUlhhcsBylTu4qWmUx45DrY0y0XskimAHSqhw=="
|
||||||
},
|
},
|
||||||
"@babel/code-frame": {
|
"@babel/code-frame": {
|
||||||
"version": "7.5.5",
|
"version": "7.5.5",
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint index.js settings.js",
|
"lint": "eslint index.js settings.js",
|
||||||
"test": "eslint index.js settings.js && jest"
|
"test": "eslint index.js settings.js && jest --coverage"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.1.2",
|
"@actions/core": "^1.1.3",
|
||||||
"xmldom": "^0.1.27",
|
"xmldom": "^0.1.27",
|
||||||
"xpath": "0.0.27"
|
"xpath": "0.0.27"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,11 +1,16 @@
|
|||||||
|
|
||||||
const DOMParser = require('xmldom').DOMParser;
|
const DOMParser = require('xmldom').DOMParser;
|
||||||
const XMLSerializer = require('xmldom').XMLSerializer;
|
const XMLSerializer = require('xmldom').XMLSerializer;
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const settings = require('./settings');
|
const settings = require('./settings');
|
||||||
|
|
||||||
var xmlTestProfile = undefined;
|
var xmlTestProfile = undefined;
|
||||||
|
|
||||||
|
const testHomePath = fs.mkdtempSync(".m2");
|
||||||
|
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
xmlTestProfile = new DOMParser().parseFromString(`<settings>
|
xmlTestProfile = new DOMParser().parseFromString(`<settings>
|
||||||
<profiles>
|
<profiles>
|
||||||
@ -27,6 +32,28 @@ beforeEach(() => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
|
||||||
|
for (key in process.env) {
|
||||||
|
if (key.match(/^INPUT_/)) {
|
||||||
|
delete process.env[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(settingsPath);
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
try {
|
||||||
|
fs.rmdirSync(path.dirname(settingsPath));
|
||||||
|
fs.rmdirSync(testHomePath);
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('template should be read', () => {
|
test('template should be read', () => {
|
||||||
|
|
||||||
const template = settings.getSettingsTemplate();
|
const template = settings.getSettingsTemplate();
|
||||||
@ -34,6 +61,19 @@ test('template should be read', () => {
|
|||||||
expect(template).toBeDefined();
|
expect(template).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('xml should be write', () => {
|
||||||
|
|
||||||
|
if (!fs.existsSync(testHomePath)) {
|
||||||
|
fs.mkdirSync(testHomePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.writeSettings(settingsPath, xmlTestProfile);
|
||||||
|
|
||||||
|
const settingsStatus = fs.lstatSync(settingsPath);
|
||||||
|
expect(settingsStatus.isFile()).toBeTruthy();
|
||||||
|
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('fillServers do nothing if no params', () => {
|
test('fillServers do nothing if no params', () => {
|
||||||
|
|
||||||
const xml = new DOMParser().parseFromString("<servers/>");
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
@ -43,7 +83,6 @@ test('fillServers do nothing if no params', () => {
|
|||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<servers/>");
|
expect(xmlStr).toBe("<servers/>");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillServers one server', () => {
|
test('fillServers one server', () => {
|
||||||
@ -60,7 +99,6 @@ test('fillServers one server', () => {
|
|||||||
expect(xmlStr).toBe("<servers>" +
|
expect(xmlStr).toBe("<servers>" +
|
||||||
"<server><id>id1</id><username>username1</username><password>password1</password></server>" +
|
"<server><id>id1</id><username>username1</username><password>password1</password></server>" +
|
||||||
"</servers>");
|
"</servers>");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillServers two servers', () => {
|
test('fillServers two servers', () => {
|
||||||
@ -131,3 +169,27 @@ test('fillProperties', () => {
|
|||||||
</profiles>
|
</profiles>
|
||||||
</settings>`);
|
</settings>`);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('fillProperties do nothing if no params', () => {
|
||||||
|
|
||||||
|
settings.fillProperties(xmlTestProfile);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xmlTestProfile);
|
||||||
|
expect(xmlStr).toBe(`<settings>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>_properties_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>false</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties/>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>_sonatype-snapshots_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>false</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</settings>`);
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user