diff --git a/README.md b/README.md index 97678958..e7d97dc8 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ steps: result will be: ```xml - + serverId value1 @@ -176,6 +176,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 4347df6d..591ae43e 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 b518e01c..8b79694c 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 fd9e1fb6..eefa56ec 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 01f228d1..f124b786 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) { @@ -321,7 +336,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 02ce6494..d1bc7492 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) { } }); @@ -821,17 +821,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"}]' @@ -856,4 +899,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 00000000..ee34e39d --- /dev/null +++ b/templates/pluginRepositories.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/templates/repositories.xml b/templates/repositories.xml index 220972f4..4f98b355 100644 --- a/templates/repositories.xml +++ b/templates/repositories.xml @@ -2,5 +2,6 @@ + - \ No newline at end of file +