10BC0 Allow for alternate settings.xml file location · actions/setup-java@ae11e1a · GitHub
[go: up one dir, main page]

Skip to content

Commit ae11e1a

Browse files
author
Bryan Clark
committed
Allow for alternate settings.xml file location
Use the m2-home to specify a new location for the settings.xml file
1 parent 4757680 commit ae11e1a

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ jobs:
137137
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
138138
username: ${{ github.actor }} # username for server authentication
139139
password: ${{ github.token }} # password or token for authentication
140-
m2-home: ${{ $GITHUB_WORKSPACE }} # location of the .m2 directory
140+
m2-home: ${{ $GITHUB_WORKSPACE }} # location for the settings.xml file
141141
- name: Build with Maven
142142
run: mvn -B package --file pom.xml
143143
- name: Publish to GitHub Packages Apache Maven
144-
run: mvn deploy
144+
run: mvn deploy -s ${{ $GITHUB_WORKSPACE }}/settings.xml
145145
```
146146

147147
# License

__tests__/auth.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ describe('auth tests', () => {
2828
}
2929
}, 100000);
3030

31+
it('creates settings.xml in alternate locations', async () => {
32+
const id = 'packages';
33+
const username = 'bluebottle';
34+
const password = 'SingleOrigin';
35+
36+
const altHome = path.join(__dirname, 'runner', 'settings');
37+
const altSettingsFile = path.join(altHome, auth.SETTINGS_FILE);
38+
process.env[`INPUT_M2-HOME`] = altHome;
39+
await io.rmRF(altHome); // ensure it doesn't already exist
40+
41+
await auth.configAuthentication(id, username, password);
42+
43+
expect(fs.existsSync(m2Dir)).toBe(false);
44+
expect(fs.existsSync(settingsFile)).toBe(false);
45+
46+
expect(fs.existsSync(altHome)).toBe(true);
47+
expect(fs.existsSync(altSettingsFile)).toBe(true);
48+
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
49+
auth.generate(id, username, password)
50+
);
51+
52+
delete process.env[`INPUT_M2-HOME`];
53+
await io.rmRF(altHome);
54+
}, 100000);
55+
3156
it('creates settings.xml with username and password', async () => {
3257
const id = 'packages';
3358
const username = 'bluebottle';

dist/index.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auth.ts

Lines changed: 6 additions & 1 deletion
< 546C td data-grid-cell-id="diff-84a5d130fb4cccb80f78601d140f1d5397dc0272f94cea672a8470539fcf6dc7-19-23-2" data-line-anchor="diff-84a5d130fb4cccb80f78601d140f1d5397dc0272f94cea672a8470539fcf6dc7R23" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
core.getInput('m2-home') ? '' : M2_DIR
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export async function configAuthentication(
1616
console.log(
1717
`creating ${SETTINGS_FILE} with server-id: ${id}, username: ${username}, and a password`
1818
);
19-
const directory: string = path.join(os.homedir(), M2_DIR);
19+
// when an alternate m2 location is specified use only that location (no .m2 directory)
20+
// otherwise use the home/.m2/ path
21+
const directory: string = path.join(
22+
core.getInput('m2-home') || os.homedir(),
23
24+
);
2025
await io.mkdirP(directory);
2126
core.debug(`created directory ${directory}`);
2227
await write(directory, generate(id, username, password));

0 commit comments

Comments
 (0)
0