update version splitter

This commit is contained in:
Evgenii Korolevskii 2022-11-24 19:06:00 +01:00
parent 4a04cfa3c7
commit d0a3b38995
2 changed files with 24 additions and 37 deletions

30
dist/setup/index.js vendored
View file

@ -105044,7 +105044,6 @@ const constants = __importStar(__nccwpck_require__(9042));
const cache_1 = __nccwpck_require__(4810); const cache_1 = __nccwpck_require__(4810);
const path = __importStar(__nccwpck_require__(1017)); const path = __importStar(__nccwpck_require__(1017));
const distribution_factory_1 = __nccwpck_require__(924); const distribution_factory_1 = __nccwpck_require__(924);
const semver = __importStar(__nccwpck_require__(1383));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
@ -105064,29 +105063,22 @@ function run() {
core.debug("JAVA_VERSION input is empty, looking for .java-version file"); core.debug("JAVA_VERSION input is empty, looking for .java-version file");
const versionFileName = '.java-version'; const versionFileName = '.java-version';
const contents = fs_1.default.readFileSync(versionFileName).toString().trim(); const contents = fs_1.default.readFileSync(versionFileName).toString().trim();
const semverRegExp = /(\d+\.\d+\.\d+|\d+\.\d+|\d+$)/; const semverRegExp = /(\d+\.\d+\.\d+.*ea.*$|\d+\.\d+\.\d+\+\d*$|\d+\.\d+\.\d+|\d+\.\d+|\d+\-ea$|\d+$)/;
const version = semverRegExp.test(contents) ? RegExp.$1 : ""; let version = semverRegExp.test(contents) ? RegExp.$1 : "";
const coercedVer = semver.coerce(version); let installed = false;
const validVer = semver.valid(coercedVer); while (!installed && version != "") {
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);
try { try {
yield installVersion(majorMinorVersion); yield installVersion(version);
installed = true;
} }
catch (error) { catch (error) {
core.debug(`${error.toString()}`); core.debug(`${error.toString()}`);
const majorVersion = getHigherVersion(majorMinorVersion); version = getHigherVersion(version);
yield installVersion(majorVersion);
} }
} }
if (!installed) {
throw new Error("Сan't install appropriate version from .java-version file");
}
} }
for (const [index, version] of versions.entries()) { for (const [index, version] of versions.entries()) {
yield installVersion(version, index); yield installVersion(version, index);
@ -105121,7 +105113,7 @@ function run() {
}); });
} }
function getHigherVersion(version) { function getHigherVersion(version) {
return version.substring(0, version.lastIndexOf(".")); return version.split("-")[0] === version ? version.substring(0, version.lastIndexOf(".")) : version.split("-")[0];
} }
} }
catch (error) { catch (error) {

View file

@ -31,27 +31,21 @@ async function run() {
core.debug("JAVA_VERSION input is empty, looking for .java-version file") core.debug("JAVA_VERSION input is empty, looking for .java-version file")
const versionFileName = '.java-version' const versionFileName = '.java-version'
const contents = fs.readFileSync(versionFileName).toString().trim(); const contents = fs.readFileSync(versionFileName).toString().trim();
const semverRegExp = /(\d+\.\d+\.\d+|\d+\.\d+|\d+$)/ const semverRegExp = /(\d+\.\d+\.\d+.*ea.*$|\d+\.\d+\.\d+\+\d*$|\d+\.\d+\.\d+|\d+\.\d+|\d+\-ea$|\d+$)/
const version = semverRegExp.test(contents) ? RegExp.$1 : ""; let version = semverRegExp.test(contents) ? RegExp.$1 : "";
const coercedVer = semver.coerce(version) let installed = false;
const validVer = semver.valid(coercedVer) while (!installed && version != "") {
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)
try { try {
await installVersion(majorMinorVersion) await installVersion(version)
installed = true
} catch (error) { } catch (error) {
core.debug(`${error.toString()}`) core.debug(`${error.toString()}`);
const majorVersion = getHigherVersion(majorMinorVersion) version = getHigherVersion(version)
await installVersion(majorVersion)
} }
} }
if (!installed) {
throw new Error("Сan't install appropriate version from .java-version file")
}
} }
for (const [index, version] of versions.entries()) { for (const [index, version] of versions.entries()) {
@ -96,8 +90,9 @@ async function run() {
} }
function getHigherVersion(version: string) { 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) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }