Use semver-conform versions for tool-cache.

This commit is contained in:
Fabio Niephaus 2022-03-08 11:12:22 +01:00
parent b76e2627a2
commit 0f01291c2e
No known key found for this signature in database
GPG Key ID: F21CF5275F31DFD6
3 changed files with 42 additions and 13 deletions

35
dist/index.js generated vendored
View File

@ -673,14 +673,15 @@ function downloadAndExtractJDK(downloadUrl) {
exports.downloadAndExtractJDK = downloadAndExtractJDK; exports.downloadAndExtractJDK = downloadAndExtractJDK;
function downloadExtractAndCacheJDK(downloadUrl, toolName, version) { function downloadExtractAndCacheJDK(downloadUrl, toolName, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find(toolName, version); const semVersion = toSemVer(version);
let toolPath = tc.find(toolName, semVersion);
if (toolPath) { if (toolPath) {
core.info(`Found ${toolName} ${version} in tool-cache @ ${toolPath}`); core.info(`Found ${toolName} ${version} in tool-cache @ ${toolPath}`);
} }
else { else {
const extractDir = yield downloadAndExtract(downloadUrl); const extractDir = yield downloadAndExtract(downloadUrl);
core.info(`Adding ${toolName} ${version} to tool-cache ...`); core.info(`Adding ${toolName} ${version} to tool-cache ...`);
toolPath = yield tc.cacheDir(extractDir, toolName, version); toolPath = yield tc.cacheDir(extractDir, toolName, semVersion);
} }
return findJavaHomeInSubfolder(toolPath); return findJavaHomeInSubfolder(toolPath);
}); });
@ -709,6 +710,18 @@ function findJavaHomeInSubfolder(searchPath) {
throw new Error(`Unexpected amount of directory items found: ${baseContents.length}`); throw new Error(`Unexpected amount of directory items found: ${baseContents.length}`);
} }
} }
/**
* This helper turns GraalVM version numbers (e.g., `22.0.0.2`) into valid
* semver.org versions (e.g., `22.0.0-2`), which is needed because
* @actions/tool-cache uses `semver` to validate versions.
*/
function toSemVer(version) {
const parts = version.split('.');
const major = parts[0];
const minor = parts.length > 1 ? parts[1] : '0';
const patch = parts.length > 2 ? parts.slice(2).join('-') : '0';
return `${major}.${minor}.${patch}`;
}
/***/ }), /***/ }),
@ -11255,14 +11268,16 @@ function bytesToUuid(buf, offset) {
var i = offset || 0; var i = offset || 0;
var bth = byteToHex; var bth = byteToHex;
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return ([bth[buf[i++]], bth[buf[i++]], return ([
bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]]).join(''); bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]
]).join('');
} }
module.exports = bytesToUuid; module.exports = bytesToUuid;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -40,13 +40,14 @@ export async function downloadExtractAndCacheJDK(
toolName: string, toolName: string,
version: string version: string
): Promise<string> { ): Promise<string> {
let toolPath = tc.find(toolName, version) const semVersion = toSemVer(version)
let toolPath = tc.find(toolName, semVersion)
if (toolPath) { if (toolPath) {
core.info(`Found ${toolName} ${version} in tool-cache @ ${toolPath}`) core.info(`Found ${toolName} ${version} in tool-cache @ ${toolPath}`)
} else { } else {
const extractDir = await downloadAndExtract(downloadUrl) const extractDir = await downloadAndExtract(downloadUrl)
core.info(`Adding ${toolName} ${version} to tool-cache ...`) core.info(`Adding ${toolName} ${version} to tool-cache ...`)
toolPath = await tc.cacheDir(extractDir, toolName, version) toolPath = await tc.cacheDir(extractDir, toolName, semVersion)
} }
return findJavaHomeInSubfolder(toolPath) return findJavaHomeInSubfolder(toolPath)
} }
@ -72,3 +73,16 @@ function findJavaHomeInSubfolder(searchPath: string): string {
) )
} }
} }
/**
* This helper turns GraalVM version numbers (e.g., `22.0.0.2`) into valid
* semver.org versions (e.g., `22.0.0-2`), which is needed because
* @actions/tool-cache uses `semver` to validate versions.
*/
function toSemVer(version: string): string {
const parts = version.split('.')
const major = parts[0]
const minor = parts.length > 1 ? parts[1] : '0'
const patch = parts.length > 2 ? parts.slice(2).join('-') : '0'
return `${major}.${minor}.${patch}`
}