diff --git a/dist/main.js b/dist/main.js index 1e31899..44241fb 100644 --- a/dist/main.js +++ b/dist/main.js @@ -3,7 +3,7 @@ import require$$0$4, { createHash, randomUUID as randomUUID$2, createHmac } from import * as fs from 'fs'; import fs__default, { readdirSync, readFileSync, existsSync } from 'fs'; import * as require$$1$1 from 'path'; -import require$$1__default, { join, basename as basename$1 } from 'path'; +import require$$1__default, { join, extname, basename as basename$1 } from 'path'; import require$$0$5 from 'http'; import require$$1$2 from 'https'; import require$$0$7 from 'net'; @@ -38705,6 +38705,20 @@ async function downloadExtractAndCacheJDK(downloader, toolName, version) { } return findJavaHomeInSubfolder(toolPath); } +/** + * This copy of tc.downloadTool() preserves the file extension in the dest. + * The file extension is required on Windows runners without .NET to extract zip files correctly. + * See #195 and https://github.com/actions/toolkit/blob/6b63a2bfc339a753a113d2266323a4d52d84dee0/packages/tool-cache/src/tool-cache.ts#L44 + */ +async function downloadFile(downloadUrl) { + const dest = join(_getTempDirectory(), crypto.randomUUID(), extname(downloadUrl)); + return toolCacheExports.downloadTool(downloadUrl, dest); +} +function _getTempDirectory() { + const tempDirectory = process.env['RUNNER_TEMP'] || ''; + ok(tempDirectory, 'Expected RUNNER_TEMP to be defined'); + return tempDirectory; +} function calculateSHA256(filePath) { const hashSum = createHash('sha256'); hashSum.update(readFileSync(filePath)); @@ -40549,7 +40563,7 @@ function determineToolName$2(javaVersion, isCommunity) { } async function downloadGraalVMJDK(downloadUrl, javaVersion) { try { - return await toolCacheExports.downloadTool(downloadUrl); + return await downloadFile(downloadUrl); } catch (error) { if (error instanceof Error && error.message.includes('404')) { @@ -40642,7 +40656,7 @@ async function downloadGraalVMCELegacy(version, javaVersion) { const graalVMIdentifier = determineGraalVMLegacyIdentifier(false, version, javaVersion); const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${GRAALVM_FILE_EXTENSION}`; try { - return await toolCacheExports.downloadTool(downloadUrl); + return await downloadFile(downloadUrl); } catch (error) { if (error instanceof Error && error.message.includes('404')) { @@ -93580,7 +93594,7 @@ async function setUpLiberica(javaVersion, javaPackage) { const resolvedJavaVersion = await findLatestLibericaJavaVersion(javaVersion); const downloadUrl = await findLibericaURL(resolvedJavaVersion, javaPackage); const toolName = determineToolName(javaVersion, javaPackage); - return downloadExtractAndCacheJDK(async () => toolCacheExports.downloadTool(downloadUrl), toolName, javaVersion); + return downloadExtractAndCacheJDK(async () => downloadFile(downloadUrl), toolName, javaVersion); } async function findLatestLibericaJavaVersion(javaVersion) { const matchingRefs = await getMatchingTags(LIBERICA_GH_USER, LIBERICA_RELEASES_REPO, `${LIBERICA_JDK_TAG_PREFIX}${javaVersion}`); @@ -93673,7 +93687,7 @@ async function setUpNativeImageMusl() { } else { coreExports.startGroup(`Setting up musl for GraalVM Native Image...`); - const muslDownloadPath = await toolCacheExports.downloadTool(`https://gds.oracle.com/download/bfs/archive/musl-toolchain-${MUSL_VERSION}-linux-amd64.tar.gz`); + const muslDownloadPath = await downloadFile(`https://gds.oracle.com/download/bfs/archive/musl-toolchain-${MUSL_VERSION}-linux-amd64.tar.gz`); const muslExtractPath = await toolCacheExports.extractTar(muslDownloadPath); const muslPath = join(muslExtractPath, MUSL_NAME); coreExports.info(`Adding ${MUSL_NAME} ${MUSL_VERSION} to tool-cache ...`); diff --git a/src/features/musl.ts b/src/features/musl.ts index ca31076..ff1e89b 100644 --- a/src/features/musl.ts +++ b/src/features/musl.ts @@ -2,6 +2,7 @@ import * as c from '../constants.js' import * as core from '@actions/core' import * as tc from '@actions/tool-cache' import { join } from 'path' +import { downloadFile } from '../utils.js' const MUSL_NAME = 'musl-toolchain' const MUSL_VERSION = '1.2.5-oracle-00001' @@ -16,7 +17,7 @@ export async function setUpNativeImageMusl(): Promise { core.info(`Found ${MUSL_NAME} ${MUSL_VERSION} in tool-cache @ ${toolPath}`) } else { core.startGroup(`Setting up musl for GraalVM Native Image...`) - const muslDownloadPath = await tc.downloadTool( + const muslDownloadPath = await downloadFile( `https://gds.oracle.com/download/bfs/archive/musl-toolchain-${MUSL_VERSION}-linux-amd64.tar.gz` ) const muslExtractPath = await tc.extractTar(muslDownloadPath) diff --git a/src/graalvm.ts b/src/graalvm.ts index 3196c03..6a62382 100644 --- a/src/graalvm.ts +++ b/src/graalvm.ts @@ -2,6 +2,7 @@ import * as c from './constants.js' import * as core from '@actions/core' import * as semver from 'semver' import { + downloadFile, downloadAndExtractJDK, downloadExtractAndCacheJDK, getContents, @@ -10,7 +11,6 @@ import { getTaggedRelease } from './utils.js' import { downloadGraalVM, downloadGraalVMEELegacy } from './gds.js' -import { downloadTool } from '@actions/tool-cache' import { basename } from 'path' const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm' @@ -153,7 +153,7 @@ function determineToolName(javaVersion: string, isCommunity: boolean) { async function downloadGraalVMJDK(downloadUrl: string, javaVersion: string): Promise { try { - return await downloadTool(downloadUrl) + return await downloadFile(downloadUrl) } catch (error) { if (error instanceof Error && error.message.includes('404')) { // Not Found @@ -265,7 +265,7 @@ async function downloadGraalVMCELegacy(version: string, javaVersion: string): Pr const graalVMIdentifier = determineGraalVMLegacyIdentifier(false, version, javaVersion) const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}` try { - return await downloadTool(downloadUrl) + return await downloadFile(downloadUrl) } catch (error) { if (error instanceof Error && error.message.includes('404')) { // Not Found diff --git a/src/liberica.ts b/src/liberica.ts index 3a0fa87..78be247 100644 --- a/src/liberica.ts +++ b/src/liberica.ts @@ -1,7 +1,6 @@ import * as c from './constants.js' import * as semver from 'semver' -import { downloadExtractAndCacheJDK, getTaggedRelease, getMatchingTags } from './utils.js' -import { downloadTool } from '@actions/tool-cache' +import { downloadFile, downloadExtractAndCacheJDK, getTaggedRelease, getMatchingTags } from './utils.js' import { spawnSync } from 'child_process' const LIBERICA_GH_USER = 'bell-sw' @@ -13,7 +12,7 @@ export async function setUpLiberica(javaVersion: string, javaPackage: string): P const resolvedJavaVersion = await findLatestLibericaJavaVersion(javaVersion) const downloadUrl = await findLibericaURL(resolvedJavaVersion, javaPackage) const toolName = determineToolName(javaVersion, javaPackage) - return downloadExtractAndCacheJDK(async () => downloadTool(downloadUrl), toolName, javaVersion) + return downloadExtractAndCacheJDK(async () => downloadFile(downloadUrl), toolName, javaVersion) } export async function findLatestLibericaJavaVersion(javaVersion: string): Promise { diff --git a/src/utils.ts b/src/utils.ts index 720af3b..9cf48d9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,9 +5,10 @@ import * as semver from 'semver' import * as tc from '@actions/tool-cache' import * as fs from 'fs' import { ExecOptions, exec as e } from '@actions/exec' +import { ok } from 'assert' import { readFileSync, readdirSync } from 'fs' import { createHash } from 'crypto' -import { join } from 'path' +import { extname, join } from 'path' import { tmpdir } from 'os' import { GitHub } from '@actions/github/lib/utils.js' @@ -86,6 +87,22 @@ export async function downloadExtractAndCacheJDK( return findJavaHomeInSubfolder(toolPath) } +/** + * This copy of tc.downloadTool() preserves the file extension in the dest. + * The file extension is required on Windows runners without .NET to extract zip files correctly. + * See #195 and https://github.com/actions/toolkit/blob/6b63a2bfc339a753a113d2266323a4d52d84dee0/packages/tool-cache/src/tool-cache.ts#L44 + */ +export async function downloadFile(downloadUrl: string): Promise { + const dest = join(_getTempDirectory(), crypto.randomUUID(), extname(downloadUrl)) + return tc.downloadTool(downloadUrl, dest) +} + +function _getTempDirectory(): string { + const tempDirectory = process.env['RUNNER_TEMP'] || '' + ok(tempDirectory, 'Expected RUNNER_TEMP to be defined') + return tempDirectory +} + export function calculateSHA256(filePath: string): string { const hashSum = createHash('sha256') hashSum.update(readFileSync(filePath))