{{ message }}
Added support for configuring multiple maven repositories with separate usernames and passwords#827
Closed
sudiptosarkar wants to merge 1 commit into
Closed
Conversation
8c10b2a to
bfbdaa6
Compare
Contributor
…te usernames and passwords
bfbdaa6 to
0b51851
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Maven authentication/settings.xml generation in actions/setup-java to support configuring multiple Maven <server> entries (intended for scenarios like separate release/snapshot repositories), and updates documentation and CI to demonstrate/validate the behavior.
Changes:
- Introduces a
MvnSettingDefinitionmodel and updates settings.xml generation to emit multiple<server>entries. - Adds a new input (
mvn-repositories-len) and indexed server inputs in the action metadata and documentation. - Updates unit tests and the e2e publishing workflow to exercise multi-repo settings generation.
Show a summary per file
| File | Description |
|---|---|
src/mvn.setting.definition.ts |
Adds a typed definition for Maven server/GPG setting entries. |
src/constants.ts |
Adds a new input constant for mvn-repositories-len. |
src/auth.ts |
Refactors settings.xml generation to support multiple server entries and indexed inputs. |
__tests__/auth.test.ts |
Updates tests for new generate(mvnSettings) signature and adds a multi-repo settings.xml test. |
action.yml |
Adds new inputs for multi-repo configuration (currently only indexes 0 and 1). |
docs/advanced-usage.md |
Documents multi-repo Maven configuration and provides an example settings.xml output. |
.github/workflows/e2e-publishing.yml |
Adds an e2e job intended to validate multi-repo settings.xml output. |
dist/setup/index.js |
Updates compiled distribution bundle for the new auth logic/constants. |
dist/cleanup/index.js |
Updates compiled distribution bundle exports for the new input constant. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/9 changed files
- Comments generated: 9
Comment on lines
+24
to
+28
| let gpgPrivateKey; | ||
| if (numMvnRepos === '' || core.getInput(constants.INPUT_GPG_PRIVATE_KEY)) { | ||
| gpgPrivateKey = populateMvnSettings(mvnSettings); | ||
| } else { | ||
| for (let i = 0; i < parseInt(numMvnRepos); i++) { |
Comment on lines
+57
to
+59
| if (username !== '' && password !== '') { | ||
| mvnSettings.push({id: id, username: username, password: password}); | ||
| } |
Comment on lines
87
to
91
| await auth.createAuthenticationSettings( | ||
| id, | ||
| username, | ||
| password, | ||
| [{id, username, password, gpgPassphrase}], | ||
| m2Dir, | ||
| true, | ||
| gpgPassphrase | ||
| true | ||
| ); |
Comment on lines
+189
to
+191
| if (($servers[1].id -ne 'maven-1') -or ($servers[0].username -ne '${env.MAVEN_PASSWORD-1}') -or ($servers[1].password -ne '${env.MAVEN_CENTRAL_TOKEN-1}')) { | ||
| throw "Generated XML file is incorrect" | ||
| } |
Comment on lines
+193
to
+195
| if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) { | ||
| throw "Generated XML file is incorrect" | ||
| } |
Comment on lines
+457
to
+462
| env: | ||
| ARTIFACTORY_USERNAME: maven_username123 | ||
| ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_USERNAME }} | ||
| SNAPSHOT_ARTIFACTORY_USERNAME: snapshot_maven_username123 | ||
| SNAPSHOT_ARTIFACTORY_TOKEN: ${{ secrets.SNAPSHOT_ARTIFACTORY_TOKEN }} | ||
| MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | ||
| ``` | ||
|
|
||
| Here `mvn-repositories-len` specifies how many artifactories we're configuring here. In this example, the value is 2. In this case, the action will look for `server-id-0`, `server-username-0`, `server-password-0`, `server-id-1`, `server-username-1` and `server-password-1`. |
Comment on lines
+44
to
+46
| mvn-repositories-len: | ||
| description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured' | ||
| required: false |
Comment on lines
+15
to
19
| const numMvnRepos = core.getInput(constants.INPUT_NUM_MVN_REPOS); | ||
| const mvnSettings: Array<MvnSettingDefinition> = []; | ||
| const settingsDirectory = | ||
| core.getInput(constants.INPUT_SETTINGS_PATH) || | ||
| path.join(os.homedir(), constants.M2_DIR); |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description:
This PR adds support for configuring multiple maven repositories with separate usernames and passwords for each. Currently the action only supports one repository configuration, which makes it impossible to specify more than one (release and snapshot repositories for example). That would inevitably lead to changing the maven config in the action yaml every time the version changes to/from release/snapshot.
Related issue:
#828
Check list: