Adding maven auth support

This commit is contained in:
Bryan Clark
2019-11-15 16:01:13 -08:00
parent 081536e071
commit a3e6ce2153
5 changed files with 167 additions and 0 deletions

31
src/auth.ts Normal file
View File

@ -0,0 +1,31 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
export async function configAuthentication(username: string, password: string) {
const directory: string = path.join(os.homedir(), '.m2');
await io.mkdirP(directory);
await write(directory, generate(username, password));
}
// only exported for testing purposes
export function generate(
username = '${actions.username}',
password = '${actions.password}'
) {
return `<settings>
<servers>
<server>
<username>${username}</username>
<password>${password}</password>
</server>
</servers>
</settings>
`;
}
async function write(directory: string, settings: string) {
return fs.writeFileSync(path.join(directory, 'settings.xml'), settings);
}

View File

@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as installer from './installer';
import * as auth from './auth';
import * as path from 'path';
async function run() {
@ -14,6 +15,13 @@ async function run() {
await installer.getJava(version, arch, jdkFile, javaPackage);
const username = core.getInput('username', {required: false});
const password = core.getInput('password', {required: false});
if (username && password) {
await auth.configAuthentication(username, password);
}
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
} catch (error) {