mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-16 00:00:27 +08:00
Merge remote-tracking branch 'origin/master' into releases/v3
This commit is contained in:
@ -1,17 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"globals": {
|
||||
"Atomics": "readonly",
|
||||
"SharedArrayBuffer": "readonly"
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@ -25,8 +25,8 @@ jobs:
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
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
|
||||
43
README.md
43
README.md
@ -31,14 +31,14 @@ See [action.yml](action.yml)
|
||||
## default ```settings.xml```
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
```
|
||||
|
||||
## ```settings.xml``` with servers section
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||
```
|
||||
@ -104,15 +104,16 @@ steps:
|
||||
## ```settings.xml``` with proxies section
|
||||
```yml
|
||||
step:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
|
||||
```
|
||||
@ -121,7 +122,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
sonatypeSnapshots: true
|
||||
```
|
||||
@ -130,7 +131,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
githubServer: false
|
||||
```
|
||||
@ -155,7 +156,7 @@ steps:
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||
```
|
||||
@ -163,7 +164,7 @@ 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@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
oracleRepo: true
|
||||
```
|
||||
@ -171,11 +172,19 @@ steps:
|
||||
## ```settings.xml``` with custom repositories
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.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@v3.1.0
|
||||
with:
|
||||
pluginRepositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
```
|
||||
|
||||
|
||||
## GitHub actions secrets
|
||||
|
||||
@ -183,7 +192,7 @@ It is also possible pass in Github Secrets e.g.
|
||||
|
||||
``` yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
with:
|
||||
servers: |
|
||||
[{
|
||||
@ -213,7 +222,7 @@ steps:
|
||||
with:
|
||||
java-version: 8
|
||||
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
- uses: s4u/maven-settings-action@v3.1.0
|
||||
|
||||
- run: mvn verify
|
||||
```
|
||||
|
||||
@ -46,6 +46,9 @@ inputs:
|
||||
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: 'node20'
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
});
|
||||
@ -75,6 +75,7 @@ test('run with all feature', () => {
|
||||
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);
|
||||
@ -213,7 +214,12 @@ test('run with all feature', () => {
|
||||
<url>url</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</repository></repositories>
|
||||
<pluginRepositories/>
|
||||
<pluginRepositories> <pluginRepository>
|
||||
<id>repoId</id>
|
||||
<name>repoName</name>
|
||||
<url>url</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</pluginRepository></pluginRepositories>
|
||||
</profile></profiles>
|
||||
<servers>
|
||||
<server>
|
||||
@ -265,4 +271,4 @@ test('run with all feature', () => {
|
||||
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
||||
</proxy></proxies>
|
||||
</settings>`);
|
||||
})
|
||||
})
|
||||
|
||||
1819
package-lock.json
generated
1819
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "maven-settings-action",
|
||||
"version": "3.0.0",
|
||||
"version": "3.1.0",
|
||||
"description": "Prepare maven settings",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -30,7 +30,7 @@
|
||||
"@xmldom/xmldom": "^0.8.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.56.0",
|
||||
"eslint": "^9.14.0",
|
||||
"jest": "^29.7.0"
|
||||
}
|
||||
}
|
||||
|
||||
54
settings.js
54
settings.js
@ -124,7 +124,7 @@ function fillServers(template, templateName) {
|
||||
server.configuration));
|
||||
}
|
||||
|
||||
function fillRepository(templateXml, templateName, id, name, url, snapshots) {
|
||||
function fillRepository(templateXml, templateName, id, name, url, releases, snapshots) {
|
||||
|
||||
if (!id || !url) {
|
||||
core.setFailed(templateName + ' must contain id and url');
|
||||
@ -148,22 +148,30 @@ function fillRepository(templateXml, templateName, id, name, url, snapshots) {
|
||||
}
|
||||
}
|
||||
|
||||
const snapshotsTag = repositoryXml.getElementsByTagName('snapshots')[0];
|
||||
if (snapshots) {
|
||||
jsonToXml(templateXml, snapshotsTag, snapshots);
|
||||
} else {
|
||||
repositoryXml.documentElement.removeChild(snapshotsTag);
|
||||
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('repositories')[0];
|
||||
const repositoriesXml = templateXml.getElementsByTagName(templateName)[0];
|
||||
repositoriesXml.appendChild(repositoryXml);
|
||||
}
|
||||
|
||||
function fillRepositories(template, templateName) {
|
||||
function fillRepositories(template) {
|
||||
|
||||
const repositories = core.getInput(templateName);
|
||||
const repositories = core.getInput('repositories');
|
||||
const pluginRepositories = core.getInput('pluginRepositories');
|
||||
|
||||
if (!repositories) {
|
||||
if (!repositories && !pluginRepositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,9 +180,16 @@ function fillRepositories(template, templateName) {
|
||||
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||
profilesXml.appendChild(customRepositoriesTemplate);
|
||||
|
||||
JSON.parse(repositories).forEach((repository) =>
|
||||
fillRepository(customRepositoriesTemplate, templateName, repository.id, repository.name, repository.url,
|
||||
repository.snapshots));
|
||||
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) {
|
||||
@ -213,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;
|
||||
@ -230,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);
|
||||
}
|
||||
@ -321,7 +343,7 @@ function generate() {
|
||||
addApacheSnapshots(settingsXml);
|
||||
addSonatypeSnapshots(settingsXml);
|
||||
addOracleRepo(settingsXml);
|
||||
fillRepositories(settingsXml,'repositories')
|
||||
fillRepositories(settingsXml)
|
||||
writeSettings(settingsPath, settingsXml);
|
||||
core.saveState('maven-settings', 'ok');
|
||||
}
|
||||
|
||||
@ -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/>");
|
||||
|
||||
@ -821,17 +841,60 @@ test('addCustomRepositories - one with snapshots one without', () => {
|
||||
<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"}]'
|
||||
@ -856,4 +919,4 @@ test('addCustomRepositories - fail if url is missing', () => {
|
||||
expect.stringMatching(/::error::repositories must contain id and url/)
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
7
templates/pluginRepositories.xml
Normal file
7
templates/pluginRepositories.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<pluginRepository>
|
||||
<id/>
|
||||
<name/>
|
||||
<url/>
|
||||
<releases/>
|
||||
<snapshots/>
|
||||
</pluginRepository>
|
||||
@ -2,5 +2,6 @@
|
||||
<id/>
|
||||
<name/>
|
||||
<url/>
|
||||
<releases/>
|
||||
<snapshots/>
|
||||
</repository>
|
||||
</repository>
|
||||
|
||||
Reference in New Issue
Block a user