mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-12 00:05:49 +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:
|
result will be:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<server>
|
<servers><server>
|
||||||
<id>serverId</id>
|
<id>serverId</id>
|
||||||
<configuration>
|
<configuration>
|
||||||
<item1>value1</item1>
|
<item1>value1</item1>
|
||||||
@ -177,6 +177,14 @@ steps:
|
|||||||
repositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
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
|
## GitHub actions secrets
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,9 @@ inputs:
|
|||||||
repositories:
|
repositories:
|
||||||
description: 'list of custom repositories as json array, e.g: [{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
description: 'list of custom repositories as json array, e.g: [{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
|
||||||
required: false
|
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:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
|
|||||||
@ -49,7 +49,7 @@ afterAll(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.rmdirSync(testHomePath);
|
fs.rmSync(testHomePath, { recursive: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -55,7 +55,7 @@ afterAll(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.rmdirSync(testHomePath);
|
fs.rmSync(testHomePath, { recursive: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -75,6 +75,7 @@ test('run with all feature', () => {
|
|||||||
process.env['INPUT_SONATYPESNAPSHOTS'] = true;
|
process.env['INPUT_SONATYPESNAPSHOTS'] = true;
|
||||||
process.env['INPUT_ORACLEREPO'] = true;
|
process.env['INPUT_ORACLEREPO'] = true;
|
||||||
process.env['INPUT_REPOSITORIES'] = '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":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' });
|
cp.spawnSync('node', [ `${indexPath}` ], { env: process.env, stdio: 'inherit' });
|
||||||
const settingsStatus = fs.lstatSync(settingsPath);
|
const settingsStatus = fs.lstatSync(settingsPath);
|
||||||
@ -213,7 +214,12 @@ test('run with all feature', () => {
|
|||||||
<url>url</url>
|
<url>url</url>
|
||||||
<snapshots><enabled>true</enabled></snapshots>
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
</repository></repositories>
|
</repository></repositories>
|
||||||
<pluginRepositories/>
|
<pluginRepositories> <pluginRepository>
|
||||||
|
<id>repoId</id>
|
||||||
|
<name>repoName</name>
|
||||||
|
<url>url</url>
|
||||||
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
|
</pluginRepository></pluginRepositories>
|
||||||
</profile></profiles>
|
</profile></profiles>
|
||||||
<servers>
|
<servers>
|
||||||
<server>
|
<server>
|
||||||
@ -265,4 +271,4 @@ test('run with all feature', () => {
|
|||||||
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
<nonProxyHosts>nonProxyHost</nonProxyHosts>
|
||||||
</proxy></proxies>
|
</proxy></proxies>
|
||||||
</settings>`);
|
</settings>`);
|
||||||
})
|
})
|
||||||
|
|||||||
43
settings.js
43
settings.js
@ -124,7 +124,7 @@ function fillServers(template, templateName) {
|
|||||||
server.configuration));
|
server.configuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillRepository(templateXml, templateName, id, name, url, snapshots) {
|
function fillRepository(templateXml, templateName, id, name, url, releases, snapshots) {
|
||||||
|
|
||||||
if (!id || !url) {
|
if (!id || !url) {
|
||||||
core.setFailed(templateName + ' must contain id and 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];
|
const additionalTags = {
|
||||||
if (snapshots) {
|
'releases': releases,
|
||||||
jsonToXml(templateXml, snapshotsTag, snapshots);
|
'snapshots': snapshots
|
||||||
} else {
|
};
|
||||||
repositoryXml.documentElement.removeChild(snapshotsTag);
|
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);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,9 +180,16 @@ function fillRepositories(template, templateName) {
|
|||||||
const profilesXml = template.getElementsByTagName('profiles')[0];
|
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||||
profilesXml.appendChild(customRepositoriesTemplate);
|
profilesXml.appendChild(customRepositoriesTemplate);
|
||||||
|
|
||||||
JSON.parse(repositories).forEach((repository) =>
|
if (repositories) {
|
||||||
fillRepository(customRepositoriesTemplate, templateName, repository.id, repository.name, repository.url,
|
JSON.parse(repositories).forEach((repository) =>
|
||||||
repository.snapshots));
|
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) {
|
function fillMirror(template, id, name, mirrorOf, url) {
|
||||||
@ -328,7 +343,7 @@ function generate() {
|
|||||||
addApacheSnapshots(settingsXml);
|
addApacheSnapshots(settingsXml);
|
||||||
addSonatypeSnapshots(settingsXml);
|
addSonatypeSnapshots(settingsXml);
|
||||||
addOracleRepo(settingsXml);
|
addOracleRepo(settingsXml);
|
||||||
fillRepositories(settingsXml,'repositories')
|
fillRepositories(settingsXml)
|
||||||
writeSettings(settingsPath, settingsXml);
|
writeSettings(settingsPath, settingsXml);
|
||||||
core.saveState('maven-settings', 'ok');
|
core.saveState('maven-settings', 'ok');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,7 @@ afterAll(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.rmdirSync(testHomePath);
|
fs.rmSync(testHomePath, { recursive: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -841,17 +841,60 @@ test('addCustomRepositories - one with snapshots one without', () => {
|
|||||||
<id>repoId</id>
|
<id>repoId</id>
|
||||||
<name>repoName</name>
|
<name>repoName</name>
|
||||||
<url>url</url>
|
<url>url</url>
|
||||||
|
|
||||||
<snapshots><enabled>true</enabled></snapshots>
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
</repository> <repository>
|
</repository> <repository>
|
||||||
<id>repoId2</id>
|
<id>repoId2</id>
|
||||||
|
|
||||||
<url>url2</url>
|
<url>url2</url>
|
||||||
|
|
||||||
|
|
||||||
</repository></repositories>
|
</repository></repositories>
|
||||||
<pluginRepositories/>
|
<pluginRepositories/>
|
||||||
</profile></profiles>`);
|
</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', () => {
|
test('addCustomRepositories - fail if url is missing', () => {
|
||||||
|
|
||||||
process.env['INPUT_REPOSITORIES'] = '[{"id":"repoId","name":"repoName"}]'
|
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/)
|
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/>
|
<id/>
|
||||||
<name/>
|
<name/>
|
||||||
<url/>
|
<url/>
|
||||||
|
<releases/>
|
||||||
<snapshots/>
|
<snapshots/>
|
||||||
</repository>
|
</repository>
|
||||||
|
|||||||
Reference in New Issue
Block a user