From 2081cee43cd5b67daf0f091422565f82f08822e3 Mon Sep 17 00:00:00 2001 From: Rimo <4203620+yizhoumo@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:13:18 +0000 Subject: [PATCH] fix for mac --- dist/index.js | 35 ++++++++++++++++++++++++++++------- src/installer.ts | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index 518c744..b30041f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32830,10 +32830,10 @@ exports.installOssutil = installOssutil; */ async function downloadOssutil(version) { // download - const downloadFileName = getDownloadFileName(version); + const zipFileName = getZipFileName(version); let downloadedFile; try { - const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip`; + const downloadUrl = `${DownloadEndpoint}/${version}/${zipFileName}.zip`; core.info(`Downloading ossutil from: ${downloadUrl}`); downloadedFile = await tc.downloadTool(downloadUrl); } @@ -32846,8 +32846,8 @@ async function downloadOssutil(version) { const zipFile = `${downloadedFile}.zip`; await io.mv(downloadedFile, zipFile); const extractFolder = await tc.extractZip(zipFile); - const toolFileName = IS_WINDOWS ? 'ossutil64.exe' : 'ossutil64'; - const toolFile = path.join(extractFolder, downloadFileName, toolFileName); + const toolFileName = getToolFileName(); + const toolFile = path.join(extractFolder, zipFileName, toolFileName); if (fs.existsSync(toolFile)) { core.info(`ossutil extracted to: ${toolFile}`); } @@ -32863,11 +32863,11 @@ async function downloadOssutil(version) { return toolPath; } /** - * Get the file name of the specific version of ossutil + * Get the zip file name of the specific version of ossutil * @param version the version of ossutil to download - * @returns the file name (e.g., ossutil-v1.7.19-linux-amd64) + * @returns the zip file name (e.g., ossutil-v1.7.19-linux-amd64) */ -function getDownloadFileName(version) { +function getZipFileName(version) { let platform = ''; switch (process.platform) { case 'linux': @@ -32895,6 +32895,27 @@ function getDownloadFileName(version) { } return `ossutil-v${version}-${platform}-${arch}`; } +/** + * Get the file name of ossutil + * @returns the file name (e.g., ossutil64) + */ +function getToolFileName() { + let filename = 'ossutil'; + switch (process.platform) { + case 'linux': + filename += '64'; + break; + case 'win32': + filename += '64.exe'; + break; + case 'darwin': + filename += 'mac64'; + break; + default: + throw new Error(`Unsupported platform ${process.platform}`); + } + return filename; +} /** * Get the latest version of ossutil * @returns the latest version diff --git a/src/installer.ts b/src/installer.ts index 8f0804d..0999c00 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -34,10 +34,10 @@ export async function installOssutil(version: string): Promise { */ async function downloadOssutil(version: string): Promise { // download - const downloadFileName = getDownloadFileName(version) + const zipFileName = getZipFileName(version) let downloadedFile: string try { - const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip` + const downloadUrl = `${DownloadEndpoint}/${version}/${zipFileName}.zip` core.info(`Downloading ossutil from: ${downloadUrl}`) downloadedFile = await tc.downloadTool(downloadUrl) } catch (error) { @@ -50,8 +50,8 @@ async function downloadOssutil(version: string): Promise { const zipFile = `${downloadedFile}.zip` await io.mv(downloadedFile, zipFile) const extractFolder = await tc.extractZip(zipFile) - const toolFileName = IS_WINDOWS ? 'ossutil64.exe' : 'ossutil64' - const toolFile = path.join(extractFolder, downloadFileName, toolFileName) + const toolFileName = getToolFileName() + const toolFile = path.join(extractFolder, zipFileName, toolFileName) if (fs.existsSync(toolFile)) { core.info(`ossutil extracted to: ${toolFile}`) } else { @@ -74,11 +74,11 @@ async function downloadOssutil(version: string): Promise { } /** - * Get the file name of the specific version of ossutil + * Get the zip file name of the specific version of ossutil * @param version the version of ossutil to download - * @returns the file name (e.g., ossutil-v1.7.19-linux-amd64) + * @returns the zip file name (e.g., ossutil-v1.7.19-linux-amd64) */ -function getDownloadFileName(version: string): string { +function getZipFileName(version: string): string { let platform = '' switch (process.platform) { case 'linux': @@ -109,6 +109,29 @@ function getDownloadFileName(version: string): string { return `ossutil-v${version}-${platform}-${arch}` } +/** + * Get the file name of ossutil + * @returns the file name (e.g., ossutil64) + */ +function getToolFileName(): string { + let filename = 'ossutil' + switch (process.platform) { + case 'linux': + filename += '64' + break + case 'win32': + filename += '64.exe' + break + case 'darwin': + filename += 'mac64' + break + default: + throw new Error(`Unsupported platform ${process.platform}`) + } + + return filename +} + /** * Get the latest version of ossutil * @returns the latest version