Add generated auth and setup-java

This commit is contained in:
Bryan Clark 2019-11-20 10:25:37 -08:00
parent 56eacf97f5
commit 86e89385e5
2 changed files with 29 additions and 17 deletions

View File

@ -18,30 +18,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io")); const io = __importStar(require("@actions/io"));
exports.M2_DIR = '.m2';
exports.SETTINGS_FILE = 'settings.xml';
function configAuthentication(username, password) { function configAuthentication(username, password) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const directory = path.join(os.homedir(), '.m2'); if (username && password) {
yield io.mkdirP(directory); core.debug(`configAuthentication with ${username} and a password`);
yield write(directory, generate(username, password)); const directory = path.join(os.homedir(), exports.M2_DIR);
yield io.mkdirP(directory);
core.debug(`created directory ${directory}`);
yield write(directory, generate(username, password));
}
else {
core.debug(`no auth without username: ${username} and password: ${password}`);
}
}); });
} }
exports.configAuthentication = configAuthentication; exports.configAuthentication = configAuthentication;
// only exported for testing purposes // only exported for testing purposes
function generate(username = '${actions.username}', password = '${actions.password}') { function generate(username, password) {
return `<settings> return `
<servers> <settings>
<server> <servers>
<username>${username}</username> <server>
<password>${password}</password> <username>${username}</username>
</server> <password>${password}</password>
</servers> </server>
</settings> </servers>
`; </settings>
`;
} }
exports.generate = generate; exports.generate = generate;
function write(directory, settings) { function write(directory, settings) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
return fs.writeFileSync(path.join(directory, 'settings.xml'), settings); const options = { encoding: 'utf-8' };
const location = path.join(directory, exports.SETTINGS_FILE);
core.debug(`writing ${location}`);
return fs.writeFileSync(location, settings, options);
}); });
} }

View File

@ -31,9 +31,7 @@ function run() {
yield installer.getJava(version, arch, jdkFile); yield installer.getJava(version, arch, jdkFile);
const username = core.getInput('username', { required: false }); const username = core.getInput('username', { required: false });
const password = core.getInput('password', { required: false }); const password = core.getInput('password', { required: false });
if (username && password) { yield auth.configAuthentication(username, password);
yield auth.configAuthentication(username, password);
}
const matchersPath = path.join(__dirname, '..', '.github'); const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
} }