Corretto toolcache folder name fix (#480)

This commit is contained in:
Ivan
2023-04-10 10:29:19 +02:00
committed by GitHub
parent 404e5db3a1
commit ddb82ce8a6
7 changed files with 62 additions and 49 deletions

View File

@ -2,7 +2,11 @@ import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import fs from 'fs';
import path from 'path';
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
import {
extractJdkFile,
getDownloadArchiveExtension,
convertVersionToSemver
} from '../../util';
import {JavaBase} from '../base-installer';
import {
JavaDownloadRelease,
@ -62,7 +66,7 @@ export class CorrettoDistribution extends JavaBase {
.filter(item => item.version == version)
.map(item => {
return {
version: item.correttoVersion,
version: convertVersionToSemver(item.correttoVersion),
url: item.downloadLink
} as JavaDownloadRelease;
});

View File

@ -10,6 +10,7 @@ import {IZuluVersions} from './models';
import {
extractJdkFile,
getDownloadArchiveExtension,
convertVersionToSemver,
isVersionSatisfies
} from '../../util';
import {
@ -29,9 +30,9 @@ export class ZuluDistribution extends JavaBase {
const availableVersionsRaw = await this.getAvailableVersions();
const availableVersions = availableVersionsRaw.map(item => {
return {
version: this.convertVersionToSemver(item.jdk_version),
version: convertVersionToSemver(item.jdk_version),
url: item.url,
zuluVersion: this.convertVersionToSemver(item.zulu_version)
zuluVersion: convertVersionToSemver(item.zulu_version)
};
});
@ -172,15 +173,4 @@ export class ZuluDistribution extends JavaBase {
return process.platform;
}
}
// Azul API returns jdk_version as array of digits like [11, 0, 2, 1]
private convertVersionToSemver(version_array: number[]) {
const mainVersion = version_array.slice(0, 3).join('.');
if (version_array.length > 3) {
// intentionally ignore more than 4 numbers because it is invalid semver
return `${mainVersion}+${version_array[3]}`;
}
return mainVersion;
}
}

View File

@ -151,3 +151,13 @@ export function getVersionFromFileContent(
function avoidOldNotation(content: string): string {
return content.startsWith('1.') ? content.substring(2) : content;
}
export function convertVersionToSemver(version: number[] | string) {
// Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1)
const versionArray = Array.isArray(version) ? version : version.split('.');
const mainVersion = versionArray.slice(0, 3).join('.');
if (versionArray.length > 3) {
return `${mainVersion}+${versionArray.slice(3).join('.')}`;
}
return mainVersion;
}