diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 126eda1..fe8cf51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - version: [1.7.0, 1.7.14, latest] + version: [1.7.15, latest] runs-on: ${{ matrix.os }} steps: diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 25ffa00..938c16a 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -20,7 +20,7 @@ describe('installer tests', () => { await io.rmRF(TEMP_DIR) }) - const versions = ['1.7.0', '1.7.14'] + const versions = ['1.7.15', '1.7.18'] it.each(versions)('install ossutil %s', async version => { await installer.installOssutil(version) diff --git a/dist/index.js b/dist/index.js index 76d2147..518c744 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32806,6 +32806,7 @@ const fs = __importStar(__nccwpck_require__(7147)); const path = __importStar(__nccwpck_require__(1017)); const ToolName = 'ossutil'; const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil'; +const IS_WINDOWS = process.platform === 'win32'; /** * Install ossutil to PATH * @param version the version of ossutil @@ -32829,54 +32830,70 @@ exports.installOssutil = installOssutil; */ async function downloadOssutil(version) { // download - let toolFile; + const downloadFileName = getDownloadFileName(version); + let downloadedFile; try { - const downloadUrl = getDownloadUrl(version); + const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip`; core.info(`Downloading ossutil from: ${downloadUrl}`); - toolFile = await tc.downloadTool(downloadUrl); + downloadedFile = await tc.downloadTool(downloadUrl); } catch (error) { core.error('Failed to download ossutil'); throw error; } - core.debug(`ossutil downloaded to: ${toolFile}`); - // extract (if needed) - if (process.platform === 'win32') { - const zipFile = `${toolFile}.zip`; - await io.mv(toolFile, zipFile); - const extractFolder = await tc.extractZip(zipFile); - toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe'); - core.debug(`ossutil extracted to: ${toolFile}`); + core.info(`ossutil downloaded to: ${downloadedFile}`); + // extract + 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); + if (fs.existsSync(toolFile)) { + core.info(`ossutil extracted to: ${toolFile}`); + } + else { + throw new Error('Unrecognized zip file structure'); } // change permission fs.chmodSync(toolFile, 0o755); // cache - const fileName = process.platform === 'win32' ? `${ToolName}.exe` : ToolName; - const toolPath = await tc.cacheFile(toolFile, fileName, ToolName, version); - core.debug(`ossutil cached to: ${toolPath}`); + const cacheFileName = IS_WINDOWS ? `${ToolName}.exe` : ToolName; + const toolPath = await tc.cacheFile(toolFile, cacheFileName, ToolName, version); + core.info(`ossutil installed to: ${toolPath}`); return toolPath; } /** - * Get the URL of the specific version of ossutil + * Get the file name of the specific version of ossutil * @param version the version of ossutil to download - * @returns the URL + * @returns the file name (e.g., ossutil-v1.7.19-linux-amd64) */ -function getDownloadUrl(version) { - let downloadUrl = `${DownloadEndpoint}/${version}/`; +function getDownloadFileName(version) { + let platform = ''; switch (process.platform) { case 'linux': - downloadUrl += 'ossutil64'; + platform = 'linux'; break; case 'win32': - downloadUrl += 'ossutil64.zip'; + platform = 'windows'; break; case 'darwin': - downloadUrl += 'ossutilmac64'; + platform = 'mac'; break; default: - throw new Error(`Unknown platform ${process.platform}`); + throw new Error(`Unsupported platform ${process.platform}`); } - return downloadUrl; + let arch = ''; + switch (process.arch) { + case 'arm64': + arch = 'arm64'; + break; + case 'x64': + arch = 'amd64'; + break; + default: + throw new Error(`Unsupported arch ${process.arch}`); + } + return `ossutil-v${version}-${platform}-${arch}`; } /** * Get the latest version of ossutil @@ -32940,8 +32957,8 @@ const installer = __importStar(__nccwpck_require__(2574)); */ async function run() { try { - install(); - config(); + await install(); + await config(); } catch (error) { // Fail the workflow run if an error occurs @@ -32957,7 +32974,7 @@ async function install() { } async function config() { const endpoint = core.getInput('endpoint'); - if (endpoint.length == 0) { + if (endpoint.length === 0) { core.info('ossutil config is skipped'); return; } @@ -32981,7 +32998,7 @@ async function config() { core.info('ossutil config is done'); } else { - core.error('ossutil config is failed with exit code: ' + exitCode); + core.error(`ossutil config is failed with exit code: ${exitCode}`); } } diff --git a/src/installer.ts b/src/installer.ts index d253003..8f0804d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,6 +7,7 @@ import * as path from 'path' const ToolName = 'ossutil' const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil' +const IS_WINDOWS = process.platform === 'win32' /** * Install ossutil to PATH @@ -33,58 +34,79 @@ export async function installOssutil(version: string): Promise { */ async function downloadOssutil(version: string): Promise { // download - let toolFile: string + const downloadFileName = getDownloadFileName(version) + let downloadedFile: string try { - const downloadUrl = getDownloadUrl(version) + const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip` core.info(`Downloading ossutil from: ${downloadUrl}`) - toolFile = await tc.downloadTool(downloadUrl) + downloadedFile = await tc.downloadTool(downloadUrl) } catch (error) { core.error('Failed to download ossutil') throw error } - core.debug(`ossutil downloaded to: ${toolFile}`) + core.info(`ossutil downloaded to: ${downloadedFile}`) - // extract (if needed) - if (process.platform === 'win32') { - const zipFile = `${toolFile}.zip` - await io.mv(toolFile, zipFile) - const extractFolder = await tc.extractZip(zipFile) - toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe') - core.debug(`ossutil extracted to: ${toolFile}`) + // extract + 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) + if (fs.existsSync(toolFile)) { + core.info(`ossutil extracted to: ${toolFile}`) + } else { + throw new Error('Unrecognized zip file structure') } // change permission fs.chmodSync(toolFile, 0o755) // cache - const fileName = process.platform === 'win32' ? `${ToolName}.exe` : ToolName - const toolPath = await tc.cacheFile(toolFile, fileName, ToolName, version) - core.debug(`ossutil cached to: ${toolPath}`) + const cacheFileName = IS_WINDOWS ? `${ToolName}.exe` : ToolName + const toolPath = await tc.cacheFile( + toolFile, + cacheFileName, + ToolName, + version + ) + core.info(`ossutil installed to: ${toolPath}`) return toolPath } /** - * Get the URL of the specific version of ossutil + * Get the file name of the specific version of ossutil * @param version the version of ossutil to download - * @returns the URL + * @returns the file name (e.g., ossutil-v1.7.19-linux-amd64) */ -function getDownloadUrl(version: string): string { - let downloadUrl = `${DownloadEndpoint}/${version}/` +function getDownloadFileName(version: string): string { + let platform = '' switch (process.platform) { case 'linux': - downloadUrl += 'ossutil64' + platform = 'linux' break case 'win32': - downloadUrl += 'ossutil64.zip' + platform = 'windows' break case 'darwin': - downloadUrl += 'ossutilmac64' + platform = 'mac' break default: - throw new Error(`Unknown platform ${process.platform}`) + throw new Error(`Unsupported platform ${process.platform}`) } - return downloadUrl + let arch = '' + switch (process.arch) { + case 'arm64': + arch = 'arm64' + break + case 'x64': + arch = 'amd64' + break + default: + throw new Error(`Unsupported arch ${process.arch}`) + } + + return `ossutil-v${version}-${platform}-${arch}` } /** diff --git a/src/main.ts b/src/main.ts index 3fa1ec1..3202ba5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,8 @@ import * as installer from './installer' */ export async function run(): Promise { try { - install() - config() + await install() + await config() } catch (error) { // Fail the workflow run if an error occurs if (error instanceof Error) core.setFailed(error.message)