diff --git a/dist/setup/index.js b/dist/setup/index.js index 37b7af53..455c00d9 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -105044,7 +105044,6 @@ const constants = __importStar(__nccwpck_require__(9042)); const cache_1 = __nccwpck_require__(4810); const path = __importStar(__nccwpck_require__(1017)); const distribution_factory_1 = __nccwpck_require__(924); -const semver = __importStar(__nccwpck_require__(1383)); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -105064,29 +105063,22 @@ function run() { core.debug("JAVA_VERSION input is empty, looking for .java-version file"); const versionFileName = '.java-version'; const contents = fs_1.default.readFileSync(versionFileName).toString().trim(); - const semverRegExp = /(\d+\.\d+\.\d+|\d+\.\d+|\d+$)/; - const version = semverRegExp.test(contents) ? RegExp.$1 : ""; - const coercedVer = semver.coerce(version); - const validVer = semver.valid(coercedVer); - if (validVer === null) { - throw new Error("No version found"); - } - const stringVersion = validVer; - try { - yield installVersion(stringVersion); - } - catch (error) { - core.debug(`${error.toString()}`); - const majorMinorVersion = getHigherVersion(stringVersion); + const semverRegExp = /(\d+\.\d+\.\d+.*ea.*$|\d+\.\d+\.\d+\+\d*$|\d+\.\d+\.\d+|\d+\.\d+|\d+\-ea$|\d+$)/; + let version = semverRegExp.test(contents) ? RegExp.$1 : ""; + let installed = false; + while (!installed && version != "") { try { - yield installVersion(majorMinorVersion); + yield installVersion(version); + installed = true; } catch (error) { core.debug(`${error.toString()}`); - const majorVersion = getHigherVersion(majorMinorVersion); - yield installVersion(majorVersion); + version = getHigherVersion(version); } } + if (!installed) { + throw new Error("Сan't install appropriate version from .java-version file"); + } } for (const [index, version] of versions.entries()) { yield installVersion(version, index); @@ -105121,7 +105113,7 @@ function run() { }); } function getHigherVersion(version) { - return version.substring(0, version.lastIndexOf(".")); + return version.split("-")[0] === version ? version.substring(0, version.lastIndexOf(".")) : version.split("-")[0]; } } catch (error) { diff --git a/src/setup-java.ts b/src/setup-java.ts index b48cec9d..c094deac 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -31,27 +31,21 @@ async function run() { core.debug("JAVA_VERSION input is empty, looking for .java-version file") const versionFileName = '.java-version' const contents = fs.readFileSync(versionFileName).toString().trim(); - const semverRegExp = /(\d+\.\d+\.\d+|\d+\.\d+|\d+$)/ - const version = semverRegExp.test(contents) ? RegExp.$1 : ""; - const coercedVer = semver.coerce(version) - const validVer = semver.valid(coercedVer) - if (validVer === null) { - throw new Error("No version found") - } - const stringVersion = validVer as string; - try { - await installVersion(stringVersion) - } catch (error) { - core.debug(`${error.toString()}`) - const majorMinorVersion = getHigherVersion(stringVersion) + const semverRegExp = /(\d+\.\d+\.\d+.*ea.*$|\d+\.\d+\.\d+\+\d*$|\d+\.\d+\.\d+|\d+\.\d+|\d+\-ea$|\d+$)/ + let version = semverRegExp.test(contents) ? RegExp.$1 : ""; + let installed = false; + while (!installed && version != "") { try { - await installVersion(majorMinorVersion) + await installVersion(version) + installed = true } catch (error) { - core.debug(`${error.toString()}`) - const majorVersion = getHigherVersion(majorMinorVersion) - await installVersion(majorVersion) + core.debug(`${error.toString()}`); + version = getHigherVersion(version) } } + if (!installed) { + throw new Error("Сan't install appropriate version from .java-version file") + } } for (const [index, version] of versions.entries()) { @@ -96,8 +90,9 @@ async function run() { } function getHigherVersion(version: string) { - return version.substring(0, version.lastIndexOf(".")) + return version.split("-")[0] === version ? version.substring(0, version.lastIndexOf(".")) : version.split("-")[0] } + } catch (error) { core.setFailed(error.message); }