Added support for configuring multiple maven repositories with separate usernames and passwords#827
Conversation
8c10b2a to
bfbdaa6
Compare
|
Linking this PR to the tracked issue: #828 (Need support for multiple maven repositories). |
…te usernames and passwords
bfbdaa6 to
0b51851
Compare
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
| let gpgPrivateKey; | ||
| if (numMvnRepos === '' || core.getInput(constants.INPUT_GPG_PRIVATE_KEY)) { | ||
| gpgPrivateKey = populateMvnSettings(mvnSettings); | ||
| } else { | ||
| for (let i = 0; i < parseInt(numMvnRepos); i++) { |
| if (username !== '' && password !== '') { | ||
| mvnSettings.push({id: id, username: username, password: password}); | ||
| } |
| await auth.createAuthenticationSettings( | ||
| id, | ||
| username, | ||
| password, | ||
| [{id, username, password, gpgPassphrase}], | ||
| m2Dir, | ||
| true, | ||
| gpgPassphrase | ||
| true | ||
| ); |
| 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" | ||
| } |
| if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) { | ||
| throw "Generated XML file is incorrect" | ||
| } |
| 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`. |
| mvn-repositories-len: | ||
| description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured' | ||
| required: false |
| 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); |
|
Maintainer design follow-up: I implemented an alternative in #1037 with a tighter surface area. Why this design: #827 introduces indexed input tuples (for example server-id-0/server-username-0/server-password-0), which scale poorly and increase maintenance and docs complexity as the number of repositories grows. What #1037 does differently:
Net effect: same multi-repository capability with less API complexity and clearer long-term maintainability. |
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: