Merge remote-tracking branch 'origin/master' into releases/v1

This commit is contained in:
Slawomir Jaranowski
2019-10-04 11:44:56 +02:00
7 changed files with 91 additions and 15 deletions

View File

@ -5,11 +5,22 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm version
- run: npm ci
- run: npm audit
- run: npm test
- uses: ./
with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
@ -17,3 +28,4 @@ jobs:
sonatypeSnapshots: true
- run: cat ~/.m2/settings.xml
shell: bash

View File

@ -1,4 +1,5 @@
# maven-settings-action
[![Test Action](https://github.com/s4u/maven-settings-action/workflows/Test%20Action/badge.svg)](https://github.com/s4u/maven-settings-action/actions)
This action setup maven environment for use in action by:
- create maven setings.xml

View File

@ -1,6 +1,7 @@
const core = require('@actions/core');
const path = require('path');
const fs = require('fs');
const os = require('os');
const settings = require('./settings');
@ -8,10 +9,11 @@ const settings = require('./settings');
async function run() {
try {
const settingsPath = path.join(process.env.HOME, '.m2', 'settings.xml');
core.info('Prepare maven setings: ' + settingsPath);
const settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
if ( fs.existsSync(settingsPath) ) {
core.info('Prepare maven setings: ' + settingsPath);
if (fs.existsSync(settingsPath)) {
core.warning('maven settings.xml already exists - skip');
return;
}

View File

@ -3,7 +3,7 @@ const cp = require('child_process');
const path = require('path');
const fs = require('fs');
const testHomePath = path.join(__dirname, 'temp');
const testHomePath = fs.mkdtempSync(".m2");
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
const indexPath = path.join(__dirname, 'index.js');
@ -13,22 +13,21 @@ beforeAll(() => {
}
process.env['HOME'] = testHomePath;
process.env['USERPROFILE'] = testHomePath;
});
afterEach(() => {
try {
fs.unlinkSync(settingsPath);
} catch (error) {
console.error(error.message);
}
});
afterAll(() => {
try {
fs.rmdirSync(path.join(testHomePath, ".m2"));
fs.rmdirSync(path.dirname(settingsPath));
fs.rmdirSync(testHomePath);
} catch (error) {
console.error(error.message);
}
});

6
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.2.tgz",
"integrity": "sha512-l8Ol2wEzFeuhV1v7LbGB2x8ghXSnmUiSVKVSjsNwgqAU4i5LvGRXpM+kli9gNMkGVudwZYHET4qZ5DTep5Sssw=="
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.3.tgz",
"integrity": "sha512-2BIib53Jh4Cfm+1XNuZYYGTeRo8yiWEAUMoliMh1qQGMaqTF4VUlhhcsBylTu4qWmUx45DrY0y0XskimAHSqhw=="
},
"@babel/code-frame": {
"version": "7.5.5",

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"lint": "eslint index.js settings.js",
"test": "eslint index.js settings.js && jest"
"test": "eslint index.js settings.js && jest --coverage"
},
"repository": {
"type": "git",
@ -24,7 +24,7 @@
},
"homepage": "https://github.com/s4u/maven-settings-action#readme",
"dependencies": {
"@actions/core": "^1.1.2",
"@actions/core": "^1.1.3",
"xmldom": "^0.1.27",
"xpath": "0.0.27"
},

View File

@ -1,11 +1,16 @@
const DOMParser = require('xmldom').DOMParser;
const XMLSerializer = require('xmldom').XMLSerializer;
const fs = require('fs');
const path = require('path');
const settings = require('./settings');
var xmlTestProfile = undefined;
const testHomePath = fs.mkdtempSync(".m2");
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
beforeEach(() => {
xmlTestProfile = new DOMParser().parseFromString(`<settings>
<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', () => {
const template = settings.getSettingsTemplate();
@ -34,6 +61,19 @@ test('template should be read', () => {
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', () => {
const xml = new DOMParser().parseFromString("<servers/>");
@ -43,7 +83,6 @@ test('fillServers do nothing if no params', () => {
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe("<servers/>");
});
test('fillServers one server', () => {
@ -60,7 +99,6 @@ test('fillServers one server', () => {
expect(xmlStr).toBe("<servers>" +
"<server><id>id1</id><username>username1</username><password>password1</password></server>" +
"</servers>");
});
test('fillServers two servers', () => {
@ -131,3 +169,27 @@ test('fillProperties', () => {
</profiles>
</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>`);
})