2019-07-10 22:54:25 +08:00
|
|
|
import * as core from '@actions/core';
|
2019-11-16 08:01:13 +08:00
|
|
|
import * as auth from './auth';
|
2022-04-01 03:09:57 +08:00
|
|
|
import { getBooleanInput, isCacheFeatureAvailable } from './util';
|
2020-07-16 09:53:39 +08:00
|
|
|
import * as constants from './constants';
|
2021-08-20 01:19:35 +08:00
|
|
|
import { restore } from './cache';
|
2019-07-12 10:57:54 +08:00
|
|
|
import * as path from 'path';
|
2021-04-05 18:02:27 +08:00
|
|
|
import { getJavaDistribution } from './distributions/distribution-factory';
|
|
|
|
import { JavaInstallerOptions } from './distributions/base-models';
|
2019-07-10 22:54:25 +08:00
|
|
|
|
|
|
|
async function run() {
|
2019-07-11 11:11:48 +08:00
|
|
|
try {
|
2021-04-05 18:02:27 +08:00
|
|
|
const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true });
|
|
|
|
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
|
|
|
|
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
|
|
|
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
|
|
|
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
2021-08-20 01:19:35 +08:00
|
|
|
const cache = core.getInput(constants.INPUT_CACHE);
|
2021-04-05 18:02:27 +08:00
|
|
|
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
|
|
|
|
|
|
|
const installerOptions: JavaInstallerOptions = {
|
|
|
|
architecture,
|
|
|
|
packageType,
|
|
|
|
version,
|
|
|
|
checkLatest
|
|
|
|
};
|
|
|
|
|
|
|
|
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
|
|
|
if (!distribution) {
|
|
|
|
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
2019-08-14 04:24:39 +08:00
|
|
|
}
|
2020-08-24 18:35:41 +08:00
|
|
|
|
2021-04-05 18:02:27 +08:00
|
|
|
const result = await distribution.setupJava();
|
2019-07-11 11:11:48 +08:00
|
|
|
|
2021-04-05 18:02:27 +08:00
|
|
|
core.info('');
|
|
|
|
core.info('Java configuration:');
|
|
|
|
core.info(` Distribution: ${distributionName}`);
|
|
|
|
core.info(` Version: ${result.version}`);
|
|
|
|
core.info(` Path: ${result.path}`);
|
|
|
|
core.info('');
|
2019-07-12 10:57:54 +08:00
|
|
|
|
2020-05-02 19:33:15 +08:00
|
|
|
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
2020-07-16 09:53:39 +08:00
|
|
|
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
|
|
|
|
2021-04-05 18:02:27 +08:00
|
|
|
await auth.configureAuthentication();
|
2022-04-01 03:09:57 +08:00
|
|
|
if (cache && isCacheFeatureAvailable()) {
|
2021-08-20 01:19:35 +08:00
|
|
|
await restore(cache);
|
|
|
|
}
|
2019-07-11 11:11:48 +08:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
2019-07-10 22:54:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
run();
|