Skip to content

Commit bfbdaa6

Browse files
committed
Added support for configuring multiple maven repositories with separate usernames and passwords
1 parent f4f1212 commit bfbdaa6

File tree

9 files changed

+13219
-12977
lines changed

9 files changed

+13219
-12977
lines changed

.github/workflows/e2e-publishing.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,45 @@ jobs:
151151
if (-not (Test-Path $path)) {
152152
throw "settings.xml file is not found in expected location"
153153
}
154+
test-publishing-multiple-repositories-with-gpg-passphrase:
155+
name: Validate settings.xml
156+
runs-on: ${{ matrix.os }}
157+
strategy:
158+
fail-fast: false
159+
matrix:
160+
os: [macos-latest, windows-latest, ubuntu-latest]
161+
steps:
162+
- name: Checkout
163+
uses: actions/checkout@v4
164+
- name: setup-java
165+
uses: ./
166+
id: setup-java
167+
with:
168+
distribution: 'adopt'
169+
java-version: '11'
170+
mvn-repositories-len: 2
171+
server-id-0: maven-0
172+
server-username-0: MAVEN_USERNAME-0
173+
server-password-0: MAVEN_CENTRAL_TOKEN-0
174+
server-id-1: maven-1
175+
server-username-1: MAVEN_USERNAME-1
176+
server-password-1: MAVEN_CENTRAL_TOKEN-1
177+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
178+
- name: Validate settings.xml
179+
run: |
180+
$xmlPath = Join-Path $HOME ".m2" "settings.xml"
181+
Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
182+
183+
[xml]$xml = Get-Content $xmlPath
184+
$servers = $xml.settings.servers.server
185+
if (($servers[0].id -ne 'maven-0') -or ($servers[0].username -ne '${env.MAVEN_USERNAME-0}') -or ($servers[0].password -ne '${env.MAVEN_CENTRAL_TOKEN-0}')) {
186+
throw "Generated XML file is incorrect"
187+
}
188+
189+
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}')) {
190+
throw "Generated XML file is incorrect"
191+
}
192+
193+
if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
194+
throw "Generated XML file is incorrect"
195+
}

__tests__/auth.test.ts

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ describe('auth tests', () => {
4343
await io.rmRF(altHome); // ensure it doesn't already exist
4444

4545
await auth.createAuthenticationSettings(
46-
id,
47-
username,
48-
password,
46+
[{id, username, password}],
4947
altHome,
5048
true
5149
);
@@ -56,7 +54,7 @@ describe('auth tests', () => {
5654
expect(fs.existsSync(altHome)).toBe(true);
5755
expect(fs.existsSync(altSettingsFile)).toBe(true);
5856
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
59-
auth.generate(id, username, password)
57+
auth.generate([{id, username, password}])
6058
);
6159

6260
await io.rmRF(altHome);
@@ -68,17 +66,15 @@ describe('auth tests', () => {
6866
const password = 'TOKEN';
6967

7068
await auth.createAuthenticationSettings(
71-
id,
72-
username,
73-
password,
69+
[{id, username, password}],
7470
m2Dir,
7571
true
7672
);
7773

7874
expect(fs.existsSync(m2Dir)).toBe(true);
7975
expect(fs.existsSync(settingsFile)).toBe(true);
8076
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
81-
auth.generate(id, username, password)
77+
auth.generate([{id, username, password}])
8278
);
8379
}, 100000);
8480

@@ -89,18 +85,15 @@ describe('auth tests', () => {
8985
const gpgPassphrase = 'GPG';
9086

9187
await auth.createAuthenticationSettings(
92-
id,
93-
username,
94-
password,
88+
[{id, username, password, gpgPassphrase}],
9589
m2Dir,
96-
true,
97-
gpgPassphrase
90+
true
9891
);
9992

10093
expect(fs.existsSync(m2Dir)).toBe(true);
10194
expect(fs.existsSync(settingsFile)).toBe(true);
10295
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
103-
auth.generate(id, username, password, gpgPassphrase)
96+
auth.generate([{id, username, password, gpgPassphrase}])
10497
);
10598
}, 100000);
10699

@@ -115,17 +108,15 @@ describe('auth tests', () => {
115108
expect(fs.existsSync(settingsFile)).toBe(true);
116109

117110
await auth.createAuthenticationSettings(
118-
id,
119-
username,
120-
password,
111+
[{id, username, password}],
121112
m2Dir,
122113
true
123114
);
124115

125116
expect(fs.existsSync(m2Dir)).toBe(true);
126117
expect(fs.existsSync(settingsFile)).toBe(true);
127118
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
128-
auth.generate(id, username, password)
119+
auth.generate([{id, username, password}])
129120
);
130121
}, 100000);
131122

@@ -140,9 +131,7 @@ describe('auth tests', () => {
140131
expect(fs.existsSync(settingsFile)).toBe(true);
141132

142133
await auth.createAuthenticationSettings(
143-
id,
144-
username,
145-
password,
134+
[{id, username, password}],
146135
m2Dir,
147136
false
148137
);
@@ -169,7 +158,7 @@ describe('auth tests', () => {
169158
</servers>
170159
</settings>`;
171160

172-
expect(auth.generate(id, username, password)).toEqual(expectedSettings);
161+
expect(auth.generate([{id, username, password}])).toEqual(expectedSettings);
173162
});
174163

175164
it('generates valid settings.xml with additional configuration', () => {
@@ -194,8 +183,50 @@ describe('auth tests', () => {
194183
</servers>
195184
</settings>`;
196185

197-
expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
198-
expectedSettings
199-
);
186+
expect(
187+
auth.generate([
188+
{id, username, password},
189+
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
190+
])
191+
).toEqual(expectedSettings);
192+
});
193+
194+
it('generates valid settings.xml for multiple repositories', () => {
195+
const id0 = 'packages0';
196+
const username0 = 'USER0';
197+
const password0 = '&<>"\'\'"><&0';
198+
const id1 = 'packages1';
199+
const username1 = 'USER1';
200+
const password1 = '&<>"\'\'"><&1';
201+
const gpgPassphrase = 'PASSPHRASE';
202+
203+
const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
204+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
205+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
206+
<servers>
207+
<server>
208+
<id>${id0}</id>
209+
<username>\${env.${username0}}</username>
210+
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;0}</password>
211+
</server>
212+
<server>
213+
<id>${id1}</id>
214+
<username>\${env.${username1}}</username>
215+
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;1}</password>
216+
</server>
217+
<server>
218+
<id>gpg.passphrase</id>
219+
<passphrase>\${env.${gpgPassphrase}}</passphrase>
220+
</server>
221+
</servers>
222+
</settings>`;
223+
224+
expect(
225+
auth.generate([
226+
{id: id0, username: username0, password: password0},
227+
{id: id1, username: username1, password: password1},
228+
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
229+
])
230+
).toEqual(expectedSettings);
200231
});
201232
});

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ inputs:
3939
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
4040
required: false
4141
default: 'GITHUB_TOKEN'
42+
mvn-repositories-len:
43+
description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured'
44+
required: false
45+
server-id-0:
46+
description: 'ID of the first distributionManagement repository in the pom.xml
47+
file - Only applicable if more than one Maven repository is being configured'
48+
required: false
49+
server-username-0:
50+
description: 'Environment variable name for the username for authentication
51+
to the first Maven repository - Only applicable if more than one Maven repository is being configured'
52+
required: false
53+
server-password-0:
54+
description: 'Environment variable name for password or token for
55+
authentication to the first Maven repository - Only applicable if more than one Maven repository is being configured'
56+
required: false
57+
server-id-1:
58+
description: 'ID of the second distributionManagement repository in the pom.xml
59+
file - Only applicable if more than one Maven repository is being configured'
60+
required: false
61+
server-username-1:
62+
description: 'Environment variable name for the username for authentication
63+
to the second Maven repository - Only applicable if more than one Maven repository is being configured'
64+
required: false
65+
server-password-1:
66+
description: 'Environment variable name for password or token for
67+
authentication to the second Maven repository - Only applicable if more than one Maven repository is being configured'
68+
required: false
4269
settings-path:
4370
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
4471
required: false

dist/cleanup/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93365,7 +93365,7 @@ else {
9336593365
"use strict";
9336693366

9336793367
Object.defineProperty(exports, "__esModule", ({ value: true }));
93368-
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
93368+
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_NUM_MVN_REPOS = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
9336993369
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
9337093370
exports.INPUT_JAVA_VERSION = 'java-version';
9337193371
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
@@ -93374,6 +93374,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
9337493374
exports.INPUT_DISTRIBUTION = 'distribution';
9337593375
exports.INPUT_JDK_FILE = 'jdkFile';
9337693376
exports.INPUT_CHECK_LATEST = 'check-latest';
93377+
exports.INPUT_NUM_MVN_REPOS = 'mvn-repositories-len';
9337793378
exports.INPUT_SERVER_ID = 'server-id';
9337893379
exports.INPUT_SERVER_USERNAME = 'server-username';
9337993380
exports.INPUT_SERVER_PASSWORD = 'server-password';

0 commit comments

Comments
 (0)