From f8c67ed9c3fa9b25afe936bb065b62831228954d Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Thu, 24 Nov 2022 18:06:32 +0100 Subject: [PATCH] install version from file --- dist/setup/index.js | 64 +++++++++++++++++++++++++++------------------ src/setup-java.ts | 45 +++++++++++++++++++------------ 2 files changed, 68 insertions(+), 41 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 6cf46e7a..2adc7310 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -105056,6 +105056,10 @@ function run() { const cache = core.getInput(constants.INPUT_CACHE); const checkLatest = util_1.getBooleanInput(constants.INPUT_CHECK_LATEST, false); let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID); + core.startGroup('Installed distributions'); + if (versions.length !== toolchainIds.length) { + toolchainIds = []; + } if (!versions.length) { core.debug("JAVA_VERSION input is empty, looking for .java-version file"); const versionFileName = '.java-version'; @@ -105064,32 +105068,20 @@ function run() { const version = semverRegExp.test(contents) ? RegExp.$1 : ""; const coercedVer = semver.coerce(version); const validVer = semver.valid(coercedVer); - core.info(validVer ? validVer : "not found"); - versions.push(contents); - } - if (versions.length !== toolchainIds.length) { - toolchainIds = []; - } - core.startGroup('Installed distributions'); - for (const [index, version] of versions.entries()) { - const installerOptions = { - architecture, - packageType, - version, - checkLatest - }; - const distribution = distribution_factory_1.getJavaDistribution(distributionName, installerOptions, jdkFile); - if (!distribution) { - throw new Error(`No supported distribution was found for input ${distributionName}`); + if (validVer === null) { + throw new Error("No version found"); } - const result = yield distribution.setupJava(); - yield toolchains.configureToolchains(version, distributionName, result.path, toolchainIds[index]); - core.info(''); - core.info('Java configuration:'); - core.info(` Distribution: ${distributionName}`); - core.info(` Version: ${result.version}`); - core.info(` Path: ${result.path}`); - core.info(''); + const stringVersion = validVer; + try { + installVersion(stringVersion); + } + catch (error) { + core.info(`${stringVersion} not found`); + throw new Error("some err"); + } + } + for (const [index, version] of versions.entries()) { + yield installVersion(version, index); } core.endGroup(); const matchersPath = path.join(__dirname, '..', '..', '.github'); @@ -105098,6 +105090,28 @@ function run() { if (cache && util_1.isCacheFeatureAvailable()) { yield cache_1.restore(cache); } + function installVersion(version, toolchainId = 0) { + return __awaiter(this, void 0, void 0, function* () { + const installerOptions = { + architecture, + packageType, + version, + checkLatest + }; + const distribution = distribution_factory_1.getJavaDistribution(distributionName, installerOptions, jdkFile); + if (!distribution) { + throw new Error(`No supported distribution was found for input ${distributionName}`); + } + const result = yield distribution.setupJava(); + yield toolchains.configureToolchains(version, distributionName, result.path, toolchainIds[toolchainId]); + core.info(''); + core.info('Java configuration:'); + core.info(` Distribution: ${distributionName}`); + core.info(` Version: ${result.version}`); + core.info(` Path: ${result.path}`); + core.info(''); + }); + } } catch (error) { core.setFailed(error.message); diff --git a/src/setup-java.ts b/src/setup-java.ts index a79e18f0..3ec14892 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -21,6 +21,12 @@ async function run() { const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false); let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID); + core.startGroup('Installed distributions'); + + if (versions.length !== toolchainIds.length) { + toolchainIds = []; + } + if (!versions.length) { core.debug("JAVA_VERSION input is empty, looking for .java-version file") const versionFileName = '.java-version' @@ -29,16 +35,31 @@ async function run() { const version = semverRegExp.test(contents) ? RegExp.$1 : ""; const coercedVer = semver.coerce(version) const validVer = semver.valid(coercedVer) - core.info(validVer ? validVer as string : "not found") - versions.push(contents) + if (validVer === null) { + throw new Error("No version found") + } + const stringVersion = validVer as string; + try { + installVersion(stringVersion) + } catch (error) { + core.info(`${stringVersion} not found`) + throw new Error("some err") + } } - if (versions.length !== toolchainIds.length) { - toolchainIds = []; - } - - core.startGroup('Installed distributions'); for (const [index, version] of versions.entries()) { + await installVersion(version, index) + } + core.endGroup(); + const matchersPath = path.join(__dirname, '..', '..', '.github'); + core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); + + await auth.configureAuthentication(); + if (cache && isCacheFeatureAvailable()) { + await restore(cache); + } + + async function installVersion(version:string, toolchainId = 0 ) { const installerOptions: JavaInstallerOptions = { architecture, packageType, @@ -56,7 +77,7 @@ async function run() { version, distributionName, result.path, - toolchainIds[index] + toolchainIds[toolchainId] ); core.info(''); @@ -66,14 +87,6 @@ async function run() { core.info(` Path: ${result.path}`); core.info(''); } - core.endGroup(); - const matchersPath = path.join(__dirname, '..', '..', '.github'); - core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); - - await auth.configureAuthentication(); - if (cache && isCacheFeatureAvailable()) { - await restore(cache); - } } catch (error) { core.setFailed(error.message); }