Skip to content

Commit

Permalink
Allow for alternate settings.xml file location
Browse files Browse the repository at this point in the history
Use the m2-home to specify a new location for the settings.xml file
  • Loading branch information
Bryan Clark committed Dec 10, 2019
1 parent 4757680 commit ae11e1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ jobs:
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
username: ${{ github.actor }} # username for server authentication
password: ${{ github.token }} # password or token for authentication
m2-home: ${{ $GITHUB_WORKSPACE }} # location of the .m2 directory
m2-home: ${{ $GITHUB_WORKSPACE }} # location for the settings.xml file
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
run: mvn deploy -s ${{ $GITHUB_WORKSPACE }}/settings.xml
```

# License
Expand Down
25 changes: 25 additions & 0 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ describe('auth tests', () => {
}
}, 100000);

it('creates settings.xml in alternate locations', async () => {
const id = 'packages';
const username = 'bluebottle';
const password = 'SingleOrigin';

const altHome = path.join(__dirname, 'runner', 'settings');
const altSettingsFile = path.join(altHome, auth.SETTINGS_FILE);
process.env[`INPUT_M2-HOME`] = altHome;
await io.rmRF(altHome); // ensure it doesn't already exist

await auth.configAuthentication(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(false);
expect(fs.existsSync(settingsFile)).toBe(false);

expect(fs.existsSync(altHome)).toBe(true);
expect(fs.existsSync(altSettingsFile)).toBe(true);
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);

delete process.env[`INPUT_M2-HOME`];
await io.rmRF(altHome);
}, 100000);

it('creates settings.xml with username and password', async () => {
const id = 'packages';
const username = 'bluebottle';
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export async function configAuthentication(
console.log(
`creating ${SETTINGS_FILE} with server-id: ${id}, username: ${username}, and a password`
);
const directory: string = path.join(os.homedir(), M2_DIR);
// when an alternate m2 location is specified use only that location (no .m2 directory)
// otherwise use the home/.m2/ path
const directory: string = path.join(
core.getInput('m2-home') || os.homedir(),
core.getInput('m2-home') ? '' : M2_DIR
);
await io.mkdirP(directory);
core.debug(`created directory ${directory}`);
await write(directory, generate(id, username, password));
Expand Down

0 comments on commit ae11e1a

Please sign in to comment.