From ae11e1a1b65b1ac2350dbf764d37e0970ef02725 Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Tue, 10 Dec 2019 10:03:33 -0800 Subject: [PATCH] Allow for alternate settings.xml file location Use the m2-home to specify a new location for the settings.xml file --- README.md | 4 ++-- __tests__/auth.test.ts | 25 +++++++++++++++++++++++++ dist/index.js | Bin 158179 -> 158387 bytes src/auth.ts | 7 ++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e376b55..a98d883a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/__tests__/auth.test.ts b/__tests__/auth.test.ts index 7134e5cc..ce13ef79 100644 --- a/__tests__/auth.test.ts +++ b/__tests__/auth.test.ts @@ -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'; diff --git a/dist/index.js b/dist/index.js index c7b1f986e251ef46b80e725ac2b5ef0c6a671f10..f4ff8d1035d31a253d4aa6dc99c16529974084d0 100644 GIT binary patch delta 235 zcmZ{dF$%&!6htwV3c15{Nk9`wX=Cjftd{t77n1#9^MeS27T&>gh=QG$5Kmy?B`n-j z+Bi%z@Mh+DADkb9{h@aWZs9J=u-0Uuyh|Zxl@O{NB^OEzTbKq-O@&z+TA*zRY|9Nq zEBP|9Wu(5eFpdggw@HThk^f-P>HO}?YfF+G8giH|qGST7?#H#H@*NJCR+`*uF2KhXfI C9T7DE diff --git a/src/auth.ts b/src/auth.ts index ca43c201..9cfa69a7 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -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));