install version from file

This commit is contained in:
Evgenii Korolevskii 2022-11-24 18:06:32 +01:00
parent 5a37903655
commit f8c67ed9c3
2 changed files with 68 additions and 41 deletions

64
dist/setup/index.js vendored
View file

@ -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);

View file

@ -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);
}