mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-12 00:05:49 +08:00
Compare commits
106 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d06ffc01c1 | |||
| 85a676bfd7 | |||
| 7c3a8b283a | |||
| db48270276 | |||
| 0120fc220b | |||
| 86e28b1256 | |||
| f7c867403d | |||
| 65009cbda6 | |||
| 4304bcedb3 | |||
| a1400c985d | |||
| 625171aa24 | |||
| 04f57f5f0e | |||
| dd913c92b1 | |||
| 8063cbe254 | |||
| ed58d20239 | |||
| c99cacf8e5 | |||
| 1bd3a222e0 | |||
| 2c724b5972 | |||
| a8a76a7b1e | |||
| 41cc972a6e | |||
| c253de7654 | |||
| e2a43d69f6 | |||
| d20dda0d1e | |||
| 9c3f6ce289 | |||
| fe82f409d0 | |||
| eb293947b5 | |||
| b703e0a7d7 | |||
| 1cf39ceb1b | |||
| 134cffbe71 | |||
| 38474872a0 | |||
| 49cd6b8c78 | |||
| 2e21981438 | |||
| afc0d7896a | |||
| 2e58029a96 | |||
| 80a4416636 | |||
| 3ef9aea393 | |||
| bf2f085f63 | |||
| f7a604dc6b | |||
| c1153c4b91 | |||
| 64d0152d7a | |||
| 5ac0323dc5 | |||
| ee25a92a84 | |||
| fb4ef3151e | |||
| f972cb7ea0 | |||
| eff73b239d | |||
| 8a5150d3c2 | |||
| 13bd1e5d92 | |||
| ceff4e7641 | |||
| ec0855f7cb | |||
| 074e0bfd5e | |||
| 06520eb502 | |||
| 45ea8e67c7 | |||
| adfd5fdbd9 | |||
| 5a796027b8 | |||
| 162ea4b86f | |||
| ed4f3a253e | |||
| f1d20e06f1 | |||
| a72cf9566e | |||
| eaf7fdc666 | |||
| 2300ba896e | |||
| d7a1cbd9a6 | |||
| ac4057b57d | |||
| 89310fb576 | |||
| d8e9709ef0 | |||
| 879f94d6bf | |||
| 25432ff633 | |||
| fa974055b8 | |||
| b09cecc467 | |||
| 90774c5e4a | |||
| 39de721118 | |||
| d2caa874cf | |||
| 51dd9e6a27 | |||
| 656f00e6c3 | |||
| de1640533d | |||
| 1d9b75d383 | |||
| 97fed6ec95 | |||
| 684cea1eed | |||
| 09d4653a85 | |||
| a343407dc0 | |||
| fdd7389b05 | |||
| dfb2ccea7f | |||
| 06eb0c4e33 | |||
| a4747963fd | |||
| b550d25288 | |||
| 57c6d5534f | |||
| ad6e19bf22 | |||
| 4e994b0af9 | |||
| 29b5c3e071 | |||
| 60261ed05e | |||
| be65e70753 | |||
| 30dcff9bf2 | |||
| 4ddcfe5843 | |||
| dc70c1232b | |||
| 712fea742c | |||
| 6da4e99f6e | |||
| 2ba0ae16c3 | |||
| dd92e98a57 | |||
| ffb873a39b | |||
| 499a91c156 | |||
| be814177e9 | |||
| ab664173c6 | |||
| 7669be9e26 | |||
| de15375a60 | |||
| 40b0fc9e3c | |||
| 81b7b67684 | |||
| e6d8814f92 |
@ -1,17 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"globals": {
|
||||
"Atomics": "readonly",
|
||||
"SharedArrayBuffer": "readonly"
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
6
.github/workflows/audit.yml
vendored
6
.github/workflows/audit.yml
vendored
@ -17,11 +17,11 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '12.x'
|
||||
node-version: '24.x'
|
||||
|
||||
- run: npm version
|
||||
- run: npm ci
|
||||
|
||||
13
.github/workflows/release-drafter.yml
vendored
13
.github/workflows/release-drafter.yml
vendored
@ -5,18 +5,9 @@ on:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'main'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update_release_draft:
|
||||
name: Update Release Draft
|
||||
runs-on: ubuntu-latest
|
||||
concurrency: release-drafter
|
||||
|
||||
if: >
|
||||
github.repository_owner == 's4u'
|
||||
&& !startsWith(github.event.head_commit.message , '[maven-release-plugin]')
|
||||
|
||||
steps:
|
||||
- uses: release-drafter/release-drafter@v5.21.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
uses: s4u/.github/.github/workflows/release-drafter.yml@master
|
||||
|
||||
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@ -17,16 +17,16 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '12.x'
|
||||
node-version: '24.x'
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '8'
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
|
||||
- run: npm version
|
||||
|
||||
25
MAINTENANCE.md
Normal file
25
MAINTENANCE.md
Normal file
@ -0,0 +1,25 @@
|
||||
# update dependencies
|
||||
|
||||
npm update
|
||||
npm outdated
|
||||
|
||||
If new version exist put '*' in `package.json` and run again `npm update`
|
||||
|
||||
- new commit with dependency updates
|
||||
|
||||
# new release
|
||||
|
||||
- run - npm version patch -m "prepare release %s"
|
||||
or
|
||||
- run - npm version minor -m "prepare release %s"
|
||||
|
||||
- push commit
|
||||
|
||||
- checkout release/vX
|
||||
- merge master and push
|
||||
- run
|
||||
npm update
|
||||
npm install
|
||||
npm prune --production
|
||||
- commit and push "update dependency after merge from master"
|
||||
- git tag and git push --tags
|
||||
52
README.md
52
README.md
@ -31,14 +31,14 @@ See [action.yml](action.yml)
|
||||
## default ```settings.xml```
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
```
|
||||
|
||||
## ```settings.xml``` with servers section
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||
```
|
||||
@ -62,7 +62,7 @@ Please refer to the [servers](http://maven.apache.org/settings.html#Servers) doc
|
||||
|
||||
``` yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
servers: |
|
||||
[{
|
||||
@ -80,7 +80,7 @@ steps:
|
||||
result will be:
|
||||
|
||||
```xml
|
||||
<server>
|
||||
<servers><server>
|
||||
<id>serverId</id>
|
||||
<configuration>
|
||||
<item1>value1</item1>
|
||||
@ -96,7 +96,7 @@ result will be:
|
||||
## ```settings.xml``` with mirrors section
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||
```
|
||||
@ -104,24 +104,25 @@ steps:
|
||||
## ```settings.xml``` with proxies section
|
||||
```yml
|
||||
step:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]'
|
||||
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxUser", "password": "proxPassword"}]'
|
||||
```
|
||||
Note: Authentication details are optional.
|
||||
|
||||
## ```settings.xml``` with properties
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
||||
```
|
||||
|
||||
## ```settings.xml``` with https://oss.sonatype.org/content/repositories/snapshots in repository list
|
||||
## ```settings.xml``` with https://central.sonatype.com/repository/maven-snapshots in repository list
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
sonatypeSnapshots: true
|
||||
```
|
||||
@ -130,7 +131,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
apacheSnapshots: true
|
||||
```
|
||||
@ -138,7 +139,7 @@ steps:
|
||||
## Do not override existing ```settings.xml```, from version **2.0** file is override by default :
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
override: false
|
||||
```
|
||||
@ -146,7 +147,7 @@ steps:
|
||||
## Do not add github to server in ```settings.xml```, by default is added:
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
githubServer: false
|
||||
```
|
||||
@ -155,7 +156,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||
```
|
||||
@ -163,18 +164,35 @@ steps:
|
||||
## ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017)
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
oracleRepo: true
|
||||
```
|
||||
|
||||
## ```settings.xml``` with custom repositories
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
repositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
```
|
||||
|
||||
## ```settings.xml``` with custom plugin repositories
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
pluginRepositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
```
|
||||
|
||||
|
||||
## GitHub actions secrets
|
||||
|
||||
It is also possible pass in Github Secrets e.g.
|
||||
|
||||
``` yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
with:
|
||||
servers: |
|
||||
[{
|
||||
@ -204,7 +222,7 @@ steps:
|
||||
with:
|
||||
java-version: 8
|
||||
|
||||
- uses: s4u/maven-settings-action@v2.8.0
|
||||
- uses: s4u/maven-settings-action@v4.0.0
|
||||
|
||||
- run: mvn verify
|
||||
```
|
||||
|
||||
@ -43,8 +43,14 @@ inputs:
|
||||
description: 'add Oracle Maven Repository'
|
||||
default: "false"
|
||||
required: false
|
||||
repositories:
|
||||
description: 'list of custom repositories as json array, e.g: [{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
required: false
|
||||
pluginRepositories:
|
||||
description: 'list of custom plugin repositories as json array, e.g: [{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node24'
|
||||
main: 'index.js'
|
||||
post: 'cleanup.js'
|
||||
|
||||
@ -49,7 +49,7 @@ afterAll(() => {
|
||||
}
|
||||
|
||||
try {
|
||||
fs.rmdirSync(testHomePath);
|
||||
fs.rmSync(testHomePath, { recursive: true });
|
||||
} catch (error) {
|
||||
}
|
||||
});
|
||||
|
||||
29
eslint.config.mjs
Normal file
29
eslint.config.mjs
Normal file
@ -0,0 +1,29 @@
|
||||
import globals from "globals";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import js from "@eslint/js";
|
||||
import { FlatCompat } from "@eslint/eslintrc";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
recommendedConfig: js.configs.recommended,
|
||||
allConfig: js.configs.all
|
||||
});
|
||||
|
||||
export default [...compat.extends("eslint:recommended"), {
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.commonjs,
|
||||
...globals.node,
|
||||
Atomics: "readonly",
|
||||
SharedArrayBuffer: "readonly",
|
||||
},
|
||||
|
||||
ecmaVersion: 2018,
|
||||
sourceType: "commonjs",
|
||||
},
|
||||
|
||||
rules: {},
|
||||
}];
|
||||
@ -55,7 +55,7 @@ afterAll(() => {
|
||||
}
|
||||
|
||||
try {
|
||||
fs.rmdirSync(testHomePath);
|
||||
fs.rmSync(testHomePath, { recursive: true });
|
||||
} catch (error) {
|
||||
}
|
||||
});
|
||||
@ -74,6 +74,8 @@ test('run with all feature', () => {
|
||||
process.env['INPUT_APACHESNAPSHOTS'] = true;
|
||||
process.env['INPUT_SONATYPESNAPSHOTS'] = true;
|
||||
process.env['INPUT_ORACLEREPO'] = true;
|
||||
process.env['INPUT_REPOSITORIES'] = '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
process.env['INPUT_PLUGINREPOSITORIES'] = '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
|
||||
cp.spawnSync('node', [ `${indexPath}` ], { env: process.env, stdio: 'inherit' });
|
||||
const settingsStatus = fs.lstatSync(settingsPath);
|
||||
@ -128,18 +130,8 @@ test('run with all feature', () => {
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
@ -150,18 +142,8 @@ test('run with all feature', () => {
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
@ -200,6 +182,24 @@ test('run with all feature', () => {
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>_custom_repositories_</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories> <repository>
|
||||
<id>repoId</id>
|
||||
<name>repoName</name>
|
||||
<url>url</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</repository></repositories>
|
||||
<pluginRepositories> <pluginRepository>
|
||||
<id>repoId</id>
|
||||
<name>repoName</name>
|
||||
<url>url</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</pluginRepository></pluginRepositories>
|
||||
</profile></profiles>
|
||||
<servers>
|
||||
<server>
|
||||
|
||||
7379
package-lock.json
generated
7379
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "maven-settings-action",
|
||||
"version": "2.8.0",
|
||||
"version": "4.0.0",
|
||||
"description": "Prepare maven settings",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -26,11 +26,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@xmldom/xmldom": "^0.8.6"
|
||||
"@actions/core": "^2.0.3",
|
||||
"@xmldom/xmldom": "^0.8.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.27.0",
|
||||
"jest": "^28.1.3"
|
||||
"eslint": "^9.39.1",
|
||||
"jest": "^30.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
89
settings.js
89
settings.js
@ -124,6 +124,74 @@ function fillServers(template, templateName) {
|
||||
server.configuration));
|
||||
}
|
||||
|
||||
function fillRepository(templateXml, templateName, id, name, url, releases, snapshots) {
|
||||
|
||||
if (!id || !url) {
|
||||
core.setFailed(templateName + ' must contain id and url');
|
||||
return;
|
||||
}
|
||||
|
||||
const repositoryXml = getTemplate(templateName + '.xml')
|
||||
repositoryXml.getElementsByTagName('id')[0].textContent = id;
|
||||
|
||||
const repositoryTags = {
|
||||
'name': name,
|
||||
'url': url
|
||||
};
|
||||
for (const tag in repositoryTags) {
|
||||
const repositoryTag = repositoryXml.getElementsByTagName(tag)[0];
|
||||
const tagValue = repositoryTags[tag];
|
||||
if (tagValue) {
|
||||
repositoryTag.textContent = tagValue;
|
||||
} else {
|
||||
repositoryXml.documentElement.removeChild(repositoryTag);
|
||||
}
|
||||
}
|
||||
|
||||
const additionalTags = {
|
||||
'releases': releases,
|
||||
'snapshots': snapshots
|
||||
};
|
||||
for (const tag in additionalTags) {
|
||||
const repositoryTag = repositoryXml.getElementsByTagName(tag)[0];
|
||||
const tagValue = additionalTags[tag];
|
||||
if (tagValue) {
|
||||
jsonToXml(templateXml, repositoryTag, tagValue);
|
||||
} else {
|
||||
repositoryXml.documentElement.removeChild(repositoryTag);
|
||||
}
|
||||
}
|
||||
|
||||
const repositoriesXml = templateXml.getElementsByTagName(templateName)[0];
|
||||
repositoriesXml.appendChild(repositoryXml);
|
||||
}
|
||||
|
||||
function fillRepositories(template) {
|
||||
|
||||
const repositories = core.getInput('repositories');
|
||||
const pluginRepositories = core.getInput('pluginRepositories');
|
||||
|
||||
if (!repositories && !pluginRepositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const customRepositoriesTemplate = getTemplate('custom-repositories.xml');
|
||||
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||
profilesXml.appendChild(customRepositoriesTemplate);
|
||||
|
||||
if (repositories) {
|
||||
JSON.parse(repositories).forEach((repository) =>
|
||||
fillRepository(customRepositoriesTemplate, 'repositories',
|
||||
repository.id, repository.name, repository.url, repository.releases, repository.snapshots));
|
||||
}
|
||||
if (pluginRepositories) {
|
||||
JSON.parse(pluginRepositories).forEach((repository) =>
|
||||
fillRepository(customRepositoriesTemplate, 'pluginRepositories',
|
||||
repository.id, repository.name, repository.url, repository.releases, repository.snapshots));
|
||||
}
|
||||
}
|
||||
|
||||
function fillMirror(template, id, name, mirrorOf, url) {
|
||||
|
||||
if (!id || !name || !mirrorOf || !url) {
|
||||
@ -160,10 +228,10 @@ function fillProxies(template) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts));
|
||||
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts, proxy.user, proxy.password));
|
||||
}
|
||||
|
||||
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
|
||||
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts, proxyUser, proxyPassword) {
|
||||
if(!id || !active || !protocol || !host || !port || !nonProxyHosts) {
|
||||
core.setFailed('proxies must contain id, active, protocol, host, port and nonProxyHosts');
|
||||
return;
|
||||
@ -177,6 +245,13 @@ function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
|
||||
proxyXml.getElementsByTagName("port")[0].textContent = port;
|
||||
proxyXml.getElementsByTagName("nonProxyHosts")[0].textContent = nonProxyHosts;
|
||||
|
||||
if(proxyUser) {
|
||||
jsonToXml(proxyXml, proxyXml.documentElement, {username: proxyUser});
|
||||
}
|
||||
if(proxyPassword) {
|
||||
jsonToXml(proxyXml, proxyXml.documentElement, {password: proxyPassword});
|
||||
}
|
||||
|
||||
const proxiesXml = template.getElementsByTagName('proxies')[0];
|
||||
proxiesXml.appendChild(proxyXml);
|
||||
}
|
||||
@ -247,7 +322,7 @@ function generate() {
|
||||
|
||||
const settingsPath = getSettingsPath();
|
||||
|
||||
core.info('Prepare maven setings: ' + settingsPath);
|
||||
core.info('Prepare maven settings: ' + settingsPath);
|
||||
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
if (isInputTrue('override')) {
|
||||
@ -268,6 +343,7 @@ function generate() {
|
||||
addApacheSnapshots(settingsXml);
|
||||
addSonatypeSnapshots(settingsXml);
|
||||
addOracleRepo(settingsXml);
|
||||
fillRepositories(settingsXml)
|
||||
writeSettings(settingsPath, settingsXml);
|
||||
core.saveState('maven-settings', 'ok');
|
||||
}
|
||||
@ -279,12 +355,12 @@ function cleanup() {
|
||||
if (mavenSettingsState == 'ok') {
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
fs.unlinkSync(settingsPath);
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file was removed');
|
||||
core.info('Cleanup maven settings: ' + settingsPath + ' - file was removed');
|
||||
} else {
|
||||
core.warning('Cleanup maven setings: ' + settingsPath + ' - file not exist');
|
||||
core.warning('Cleanup maven settings: ' + settingsPath + ' - file not exist');
|
||||
}
|
||||
} else {
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file wasn\'t generated by action');
|
||||
core.info('Cleanup maven settings: ' + settingsPath + ' - file wasn\'t generated by action');
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,6 +372,7 @@ module.exports = {
|
||||
fillProxies,
|
||||
fillServerForGithub,
|
||||
fillProperties,
|
||||
fillRepositories,
|
||||
addApacheSnapshots,
|
||||
addSonatypeSnapshots,
|
||||
addOracleRepo,
|
||||
|
||||
167
settings.test.js
167
settings.test.js
@ -87,7 +87,7 @@ afterAll(() => {
|
||||
}
|
||||
|
||||
try {
|
||||
fs.rmdirSync(testHomePath);
|
||||
fs.rmSync(testHomePath, { recursive: true });
|
||||
} catch (error) {
|
||||
}
|
||||
});
|
||||
@ -466,6 +466,26 @@ test("fillProxies one proxy", () => {
|
||||
|
||||
})
|
||||
|
||||
test("fillProxies one proxy with auth info", () => {
|
||||
const xml = stringAsXml("<proxies/>");
|
||||
|
||||
process.env['INPUT_PROXIES'] = `[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol",
|
||||
"host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxyUser", "password": "somepassword"}]`;
|
||||
|
||||
settings.fillProxies(xml);
|
||||
|
||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||
expect(xmlStr).toBe(`<proxies><proxy>
|
||||
<id>proxyId</id>
|
||||
<active>isActive</active>
|
||||
<protocol>proxyProtocol</protocol>
|
||||
<host>proxyHost</host>
|
||||
<port>proxyPort</port>
|
||||
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
||||
<username>proxyUser</username><password>somepassword</password></proxy></proxies>`)
|
||||
|
||||
})
|
||||
|
||||
test("fillProxies two proxies", () => {
|
||||
const xml = stringAsXml("<proxies/>");
|
||||
|
||||
@ -572,18 +592,8 @@ test('addSonatypeSnapshots', () => {
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
@ -594,18 +604,8 @@ test('addSonatypeSnapshots', () => {
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
@ -708,7 +708,7 @@ test('cleanup - not generated', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/Cleanup maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file wasn\'t generated by action/)
|
||||
expect.stringMatching(/Cleanup maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file wasn\'t generated by action/)
|
||||
])
|
||||
);
|
||||
})
|
||||
@ -721,7 +721,7 @@ test('cleanup - not exist', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/::warning::Cleanup maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file not exist/)
|
||||
expect.stringMatching(/::warning::Cleanup maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file not exist/)
|
||||
])
|
||||
);
|
||||
})
|
||||
@ -735,13 +735,13 @@ test('cleanup - ok', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/Cleanup maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file was removed/)
|
||||
expect.stringMatching(/Cleanup maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml - file was removed/)
|
||||
])
|
||||
);
|
||||
expect(fs.existsSync(settingsPath)).not.toBeTruthy();
|
||||
})
|
||||
|
||||
test('genereate', () => {
|
||||
test('generate', () => {
|
||||
|
||||
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "username", "password": "password"}]';
|
||||
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||
@ -751,13 +751,13 @@ test('genereate', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/Prepare maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/Prepare maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/:save-state name=maven-settings::ok/)
|
||||
])
|
||||
);
|
||||
})
|
||||
|
||||
test('genereate - skip', () => {
|
||||
test('generate - skip', () => {
|
||||
|
||||
fs.closeSync(fs.openSync(settingsPath, 'w'));
|
||||
|
||||
@ -765,13 +765,13 @@ test('genereate - skip', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/Prepare maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/Prepare maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/::warning::maven settings.xml already exists - skip/)
|
||||
])
|
||||
);
|
||||
})
|
||||
|
||||
test('genereate - override', () => {
|
||||
test('generate - override', () => {
|
||||
|
||||
fs.closeSync(fs.openSync(settingsPath, 'w'));
|
||||
process.env['INPUT_OVERRIDE'] = 'true';
|
||||
@ -780,7 +780,7 @@ test('genereate - override', () => {
|
||||
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/Prepare maven setings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/Prepare maven settings: \..+[\/\\]{1,2}\.m2[\/\\]{1,2}settings.xml/),
|
||||
expect.stringMatching(/maven settings.xml already exists - override/),
|
||||
expect.stringMatching(/:save-state name=maven-settings::ok/)
|
||||
])
|
||||
@ -801,3 +801,102 @@ test('generate - custom path', () => {
|
||||
expect(settingsStatus.isFile()).toBeTruthy();
|
||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('addCustomRepositories - one with snapshots one without', () => {
|
||||
|
||||
process.env['INPUT_REPOSITORIES'] = '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}},{"id":"repoId2","url":"url2"}]'
|
||||
|
||||
const xml = stringAsXml('<profiles/>');
|
||||
|
||||
settings.fillRepositories(xml,'repositories');
|
||||
|
||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||
expect(xmlStr).toBe(`<profiles>
|
||||
<profile>
|
||||
<id>_custom_repositories_</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories> <repository>
|
||||
<id>repoId</id>
|
||||
<name>repoName</name>
|
||||
<url>url</url>
|
||||
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</repository> <repository>
|
||||
<id>repoId2</id>
|
||||
|
||||
<url>url2</url>
|
||||
|
||||
|
||||
</repository></repositories>
|
||||
<pluginRepositories/>
|
||||
</profile></profiles>`);
|
||||
});
|
||||
|
||||
test('addCustomPluginRepositories - one with releases and snapshots one without', () => {
|
||||
|
||||
process.env['INPUT_PLUGINREPOSITORIES'] = `
|
||||
[{"id":"repoId",
|
||||
"name":"repoName",
|
||||
"url":"url",
|
||||
"releases":{"enabled":false},
|
||||
"snapshots":{"enabled":true}
|
||||
},{
|
||||
"id":"repoId2",
|
||||
"url":"url2"
|
||||
}]`
|
||||
|
||||
const xml = stringAsXml('<profiles/>');
|
||||
|
||||
settings.fillRepositories(xml,'pluginRepositories');
|
||||
|
||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||
expect(xmlStr).toBe(`<profiles>
|
||||
<profile>
|
||||
<id>_custom_repositories_</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories/>
|
||||
<pluginRepositories> <pluginRepository>
|
||||
<id>repoId</id>
|
||||
<name>repoName</name>
|
||||
<url>url</url>
|
||||
<releases><enabled>false</enabled></releases>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</pluginRepository> <pluginRepository>
|
||||
<id>repoId2</id>
|
||||
|
||||
<url>url2</url>
|
||||
|
||||
|
||||
</pluginRepository></pluginRepositories>
|
||||
</profile></profiles>`);
|
||||
});
|
||||
|
||||
test('addCustomRepositories - fail if url is missing', () => {
|
||||
|
||||
process.env['INPUT_REPOSITORIES'] = '[{"id":"repoId","name":"repoName"}]'
|
||||
|
||||
const xml = stringAsXml('<profiles/>');
|
||||
|
||||
settings.fillRepositories(xml,'repositories');
|
||||
|
||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||
|
||||
expect(xmlStr).toBe(`<profiles>
|
||||
<profile>
|
||||
<id>_custom_repositories_</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories/>
|
||||
<pluginRepositories/>
|
||||
</profile></profiles>`);
|
||||
expect(consoleOutput).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(/::error::repositories must contain id and url/)
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
9
templates/custom-repositories.xml
Normal file
9
templates/custom-repositories.xml
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
<profile>
|
||||
<id>_custom_repositories_</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<repositories/>
|
||||
<pluginRepositories/>
|
||||
</profile>
|
||||
7
templates/pluginRepositories.xml
Normal file
7
templates/pluginRepositories.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<pluginRepository>
|
||||
<id/>
|
||||
<name/>
|
||||
<url/>
|
||||
<releases/>
|
||||
<snapshots/>
|
||||
</pluginRepository>
|
||||
7
templates/repositories.xml
Normal file
7
templates/repositories.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<repository>
|
||||
<id/>
|
||||
<name/>
|
||||
<url/>
|
||||
<releases/>
|
||||
<snapshots/>
|
||||
</repository>
|
||||
@ -6,18 +6,8 @@
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
@ -28,18 +18,8 @@
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<id>central-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
|
||||
Reference in New Issue
Block a user