mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-11 00:00:47 +08:00
Resolves s4u/maven-settings-action#348, plugin repositories support
This commit is contained in:
committed by
Slawomir Jaranowski
parent
06520eb502
commit
074e0bfd5e
10
README.md
10
README.md
@ -80,7 +80,7 @@ steps:
|
||||
result will be:
|
||||
|
||||
```xml
|
||||
<server>
|
||||
<servers><server>
|
||||
<id>serverId</id>
|
||||
<configuration>
|
||||
<item1>value1</item1>
|
||||
@ -177,6 +177,14 @@ steps:
|
||||
repositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
```
|
||||
|
||||
## ```settings.xml``` with custom plugin repositories
|
||||
```yml
|
||||
steps:
|
||||
- uses: s4u/maven-settings-action@v3.0.0
|
||||
with:
|
||||
pluginRepositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||
```
|
||||
|
||||
|
||||
## GitHub actions secrets
|
||||
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
});
|
||||
|
||||
@ -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>`);
|
||||
})
|
||||
})
|
||||
|
||||
43
settings.js
43
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) {
|
||||
@ -328,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) {
|
||||
}
|
||||
});
|
||||
@ -841,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"}]'
|
||||
@ -876,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