19 Commits
v2 ... v2.1.0

Author SHA1 Message Date
63ea49dafa Merge remote-tracking branch 'origin/master' into releases/v2 2020-04-06 22:43:15 +02:00
64c06afaca mirrors example in readme 2020-04-06 22:40:39 +02:00
b818438be1 fix mirrors example 2020-04-06 22:37:48 +02:00
10967cd2f2 test for mirrors 2020-04-06 22:28:38 +02:00
d0b8b534b3 Merge pull request #12 from p1nkun1c0rns/master_up
Add mirror support
2020-04-06 22:17:33 +02:00
1b34539e65 feat: add mirror support 2020-04-06 20:00:32 +02:00
79bc1c28ad Merge pull request #11 from s4u/dependabot/npm_and_yarn/jest-25.2.7 2020-04-03 15:14:32 +00:00
f2d19d8a3c Bump jest from 25.2.4 to 25.2.7
Bumps [jest](https://github.com/facebook/jest) from 25.2.4 to 25.2.7.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/compare/v25.2.4...v25.2.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-03 09:14:56 +00:00
d38ae3dd0c Merge pull request #9 from s4u/dependabot/npm_and_yarn/jest-25.2.4 2020-03-30 19:00:33 +00:00
1a566d6b1a Bump jest from 25.2.3 to 25.2.4
Bumps [jest](https://github.com/facebook/jest) from 25.2.3 to 25.2.4.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/compare/v25.2.3...v25.2.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-30 10:07:28 +00:00
68c0f5968a Merge pull request #8 from s4u/dependabot/npm_and_yarn/jest-25.2.3
Bump jest from 25.1.0 to 25.2.3
2020-03-29 16:54:56 +02:00
fa170c9efb Bump jest from 25.1.0 to 25.2.3
Bumps [jest](https://github.com/facebook/jest) from 25.1.0 to 25.2.3.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/compare/v25.1.0...v25.2.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-27 09:14:30 +00:00
b8e6d4c5c1 Merge remote-tracking branch 'origin/master' into releases/v2 2020-03-19 21:06:31 +01:00
c79b8c8bae info about versioning 2020-03-19 20:56:13 +01:00
19aa5326f7 fix audit issues 2020-03-19 19:48:19 +01:00
e754a0a431 new badge for test and audit 2020-03-18 18:38:52 +01:00
79b590b1fa separate action for test and audit 2020-03-18 18:14:14 +01:00
6e3efd3238 Merge pull request #6 from viniciussousazup/patch-1
Update README.md
2020-03-18 17:59:11 +01:00
c920943d3e Update README.md 2020-03-17 18:55:30 -03:00
10 changed files with 987 additions and 1088 deletions

27
.github/workflows/audit.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: "Audit"
on:
pull_request:
push:
branches-ignore:
- 'dependabot/*'
schedule:
- cron: '09 22 * * *'
jobs:
test:
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

View File

@ -1,7 +1,9 @@
name: "Test Action" name: "Test"
on: on:
pull_request: pull_request:
push: push:
branches-ignore:
- 'dependabot/*'
schedule: schedule:
- cron: '22 22 * * 5' - cron: '22 22 * * 5'
@ -26,13 +28,13 @@ jobs:
- run: npm version - 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"}]'
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]' properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
sonatypeSnapshots: true sonatypeSnapshots: true
- run: cat ~/.m2/settings.xml - run: cat ~/.m2/settings.xml

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
# Editors # Editors
.vscode .vscode
.idea
# Logs # Logs
logs logs

View File

@ -1,5 +1,7 @@
# maven-settings-action # 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) [![Test](https://github.com/s4u/maven-settings-action/workflows/Test/badge.svg)](https://github.com/s4u/maven-settings-action/actions?query=workflow%3ATest)
[![Audit](https://github.com/s4u/maven-settings-action/workflows/Audit/badge.svg)](https://github.com/s4u/maven-settings-action/actions?query=workflow%3AAudit)
This action setup maven environment for use in action by: This action setup maven environment for use in action by:
- create maven settings.xml - create maven settings.xml
@ -8,10 +10,17 @@ This action setup maven environment for use in action by:
- add server to servers with id=github, username=$GITHUB_ACTOR and password=$GITHUB_TOKEN - add server to servers with id=github, username=$GITHUB_ACTOR and password=$GITHUB_TOKEN
# Contributions # Contributions
- Contributions are welcome! - Contributions are welcome!
- Give a star - if you want to encourage me to work on a project - Give :star: - if you want to encourage me to work on a project
- Don't hesitate create issue - Don't hesitate create issue for new feature you dream of or if you suspect some bug
# Project versioning
Project use [Semantic Versioning](https://semver.org/).
We recommended to use the latest and specific release version.
In order to keep your project dependencies up to date you can watch this repository *(Releases only)*
or use automatic tools like [Dependabot](https://dependabot.com/).
# Usage # Usage
See [action.yml](action.yml) See [action.yml](action.yml)
@ -19,21 +28,29 @@ See [action.yml](action.yml)
Create default ```settings.xml```: Create default ```settings.xml```:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
``` ```
Create ```settings.xml``` with server section: Create ```settings.xml``` with servers section:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
with: with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]' servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
``` ```
Create ```settings.xml``` with mirrors section:
```yml
steps:
- uses: s4u/maven-settings-action@v2
with:
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
```
Create ```settings.xml``` with maven properties: Create ```settings.xml``` with maven properties:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
with: with:
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]' properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
``` ```
@ -41,7 +58,7 @@ steps:
Create ```settings.xml``` with https://oss.sonatype.org/content/repositories/snapshots in repository list Create ```settings.xml``` with https://oss.sonatype.org/content/repositories/snapshots in repository list
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
with: with:
sonatypeSnapshots: true sonatypeSnapshots: true
``` ```
@ -49,7 +66,7 @@ steps:
Do not override existing ```settings.xml```, from version 2.0 file is override by default : Do not override existing ```settings.xml```, from version 2.0 file is override by default :
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
with: with:
override: false override: false
``` ```
@ -57,7 +74,7 @@ steps:
Do not add github to server in ```settings.xml```, by default is added: Do not add github to server in ```settings.xml```, by default is added:
```yml ```yml
steps: steps:
- uses: s4u/maven-settings-action@v2.0 - uses: s4u/maven-settings-action@v2
with: with:
githubServer: false githubServer: false
``` ```

View File

@ -9,6 +9,9 @@ inputs:
servers: servers:
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]' description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]'
required: false required: false
mirrors:
description: 'mirrors definition in json array, eg: [{"id": "id", "name": "name", "mirrorOf": "mirrorOf", "url": "url"}]'
required: false
properties: properties:
description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]' description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
required: false required: false

1806
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,6 @@
}, },
"devDependencies": { "devDependencies": {
"eslint": "^6.8.0", "eslint": "^6.8.0",
"jest": "^25.1.0" "jest": "^25.2.7"
} }
} }

View File

@ -91,6 +91,42 @@ function fillServers(template) {
JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password)); JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password));
} }
function fillMirror(template, id, name, mirrorOf, url) {
const mirrorXml = template.createElement('mirror');
if (!id || !name || !mirrorOf || !url) {
core.setFailed('mirrors must contain id, name, mirrorOf and url');
return;
}
const idXml = createElementWithText(template, 'id', id);
mirrorXml.appendChild(idXml);
const nameXml = createElementWithText(template, 'name', name);
mirrorXml.appendChild(nameXml);
const mirrorOfXml = createElementWithText(template, 'mirrorOf', mirrorOf);
mirrorXml.appendChild(mirrorOfXml);
const urlXml = createElementWithText(template, 'url', url);
mirrorXml.appendChild(urlXml);
const mirrorsXml = template.getElementsByTagName('mirrors')[0];
mirrorsXml.appendChild(mirrorXml);
}
function fillMirrors(template) {
const mirrors = core.getInput('mirrors');
if (!mirrors) {
return;
}
JSON.parse(mirrors).forEach((mirror) => fillMirror(template, mirror.id, mirror.name, mirror.mirrorOf, mirror.url));
}
function isInputTrue(inputName) { function isInputTrue(inputName) {
const val = core.getInput(inputName); const val = core.getInput(inputName);
return val && val.toLocaleLowerCase() == 'true'; return val && val.toLocaleLowerCase() == 'true';
@ -157,6 +193,7 @@ function generate() {
} }
const templateXml = getSettingsTemplate(); const templateXml = getSettingsTemplate();
fillMirrors(templateXml);
fillServers(templateXml); fillServers(templateXml);
fillServerForGithub(templateXml); fillServerForGithub(templateXml);
fillProperties(templateXml); fillProperties(templateXml);
@ -184,6 +221,7 @@ function cleanup() {
module.exports = { module.exports = {
getSettingsTemplate, getSettingsTemplate,
writeSettings, writeSettings,
fillMirrors,
fillServers, fillServers,
fillServerForGithub, fillServerForGithub,
fillProperties, fillProperties,

View File

@ -99,7 +99,6 @@ afterEach(() => {
}); });
test('template should be read', () => { test('template should be read', () => {
const template = settings.getSettingsTemplate(); const template = settings.getSettingsTemplate();
expect(template).toBeDefined(); expect(template).toBeDefined();
@ -133,7 +132,6 @@ test('fillServers one server', () => {
const xml = new DOMParser().parseFromString("<servers/>"); const xml = new DOMParser().parseFromString("<servers/>");
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]'; process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
settings.fillServers(xml); settings.fillServers(xml);
@ -194,6 +192,65 @@ test('fillServers github', () => {
expect(consoleOutput).toEqual([]); expect(consoleOutput).toEqual([]);
}); });
test('fillMirrors do nothing if no params', () => {
const xml = new DOMParser().parseFromString("<mirrors/>");
settings.fillMirrors(xml);
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe("<mirrors/>");
});
test('fillMirrors one mirror', () => {
const xml = new DOMParser().parseFromString("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name", "mirrorOf":"mirrorOf", "url":"url"}]';
settings.fillMirrors(xml);
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe("<mirrors>" +
"<mirror><id>id1</id><name>name</name><mirrorOf>mirrorOf</mirrorOf><url>url</url></mirror>" +
"</mirrors>");
});
test('fillMirrors two mirrors', () => {
const xml = new DOMParser().parseFromString("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"id": "id1", "name": "name1", "mirrorOf":"mirrorOf1", "url":"url1"},{"id": "id2", "name": "name2", "mirrorOf":"mirrorOf2", "url":"url2"}]';
settings.fillMirrors(xml);
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe("<mirrors>" +
"<mirror><id>id1</id><name>name1</name><mirrorOf>mirrorOf1</mirrorOf><url>url1</url></mirror><mirror><id>id2</id><name>name2</name><mirrorOf>mirrorOf2</mirrorOf><url>url2</url></mirror>" +
"</mirrors>");
});
test('fillMirrors incorrect fields', () => {
const xml = new DOMParser().parseFromString("<mirrors/>");
process.env['INPUT_MIRRORS'] = '[{"idx": "id1"}]';
settings.fillMirrors(xml);
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe('<mirrors/>');
expect(consoleOutput).toEqual(
expect.arrayContaining([
expect.stringMatching(/::error::mirrors must contain id, name, mirrorOf and url/)
])
);
});
test('addSonatypeSnapshots activate', () => { test('addSonatypeSnapshots activate', () => {
process.env['INPUT_SONATYPESNAPSHOTS'] = "true"; process.env['INPUT_SONATYPESNAPSHOTS'] = "true";

View File

@ -1,48 +1,46 @@
<settings> <settings>
<interactiveMode>false</interactiveMode>
<interactiveMode>false</interactiveMode> <profiles>
<!-- generic ############################################################# -->
<profiles> <profile>
<profile> <id>_properties_</id>
<id>_properties_</id> <activation>
<activation> <activeByDefault>false</activeByDefault>
<activeByDefault>false</activeByDefault> </activation>
</activation> <properties />
<properties /> </profile>
</profile> <!-- sonatype ############################################################# -->
<profile>
<profile> <id>_sonatype-snapshots_</id>
<id>_sonatype-snapshots_</id> <activation>
<activation> <activeByDefault>false</activeByDefault>
<activeByDefault>false</activeByDefault> </activation>
</activation> <repositories>
<repositories> <repository>
<repository> <id>sonatype-snapshots</id>
<id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases>
<releases> <enabled>false</enabled>
<enabled>false</enabled> </releases>
</releases> <snapshots>
<snapshots> <enabled>true</enabled>
<enabled>true</enabled> </snapshots>
</snapshots> </repository>
</repository> </repositories>
</repositories> <pluginRepositories>
<pluginRepositories> <pluginRepository>
<pluginRepository> <id>sonatype-snapshots</id>
<id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases>
<releases> <enabled>false</enabled>
<enabled>false</enabled> </releases>
</releases> <snapshots>
<snapshots> <enabled>true</enabled>
<enabled>true</enabled> </snapshots>
</snapshots> </pluginRepository>
</pluginRepository> </pluginRepositories>
</pluginRepositories> </profile>
</profile> </profiles>
<servers />
</profiles> <mirrors />
<servers />
</settings> </settings>