diff --git a/README.md b/README.md index 50d6d1b0e..ed9bf98c6 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ steps: result will be: ```xml - + serverId value1 @@ -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 diff --git a/action.yml b/action.yml index 4347df6de..591ae43ea 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/cleanup.test.js b/cleanup.test.js index b518e01c9..8b79694cf 100644 --- a/cleanup.test.js +++ b/cleanup.test.js @@ -49,7 +49,7 @@ afterAll(() => { } try { - fs.rmdirSync(testHomePath); + fs.rmSync(testHomePath, { recursive: true }); } catch (error) { } }); diff --git a/index.test.js b/index.test.js index fd9e1fb6e..eefa56eca 100644 --- a/index.test.js +++ b/index.test.js @@ -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 true - + + repoId + repoName + url + true + @@ -265,4 +271,4 @@ test('run with all feature', () => { nonProxyHost `); -}) \ No newline at end of file +}) diff --git a/settings.js b/settings.js index 64eb4412b..fce67ce3e 100644 --- a/settings.js +++ b/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'); } diff --git a/settings.test.js b/settings.test.js index b46702f34..0c0a4f4e9 100644 --- a/settings.test.js +++ b/settings.test.js @@ -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', () => { repoId repoName url + true repoId2 url2 + `); }); +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(''); + + settings.fillRepositories(xml,'pluginRepositories'); + + const xmlStr = new XMLSerializer().serializeToString(xml); + expect(xmlStr).toBe(` + + _custom_repositories_ + + true + + + + repoId + repoName + url + false + true + + repoId2 + + url2 + + + +`); +}); + 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/) ]) ); -}); \ No newline at end of file +}); diff --git a/templates/pluginRepositories.xml b/templates/pluginRepositories.xml new file mode 100644 index 000000000..ee34e39d8 --- /dev/null +++ b/templates/pluginRepositories.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/templates/repositories.xml b/templates/repositories.xml index 220972f49..4f98b355c 100644 --- a/templates/repositories.xml +++ b/templates/repositories.xml @@ -2,5 +2,6 @@ + - \ No newline at end of file +