download from zip

This commit is contained in:
Rimo
2024-01-26 15:22:17 +00:00
parent fdb656e148
commit 9dea1aac7e
5 changed files with 93 additions and 54 deletions

View File

@@ -47,7 +47,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
version: [1.7.0, 1.7.14, latest] version: [1.7.15, latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:

View File

@@ -20,7 +20,7 @@ describe('installer tests', () => {
await io.rmRF(TEMP_DIR) 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 => { it.each(versions)('install ossutil %s', async version => {
await installer.installOssutil(version) await installer.installOssutil(version)

71
dist/index.js generated vendored
View File

@@ -32806,6 +32806,7 @@ const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017)); const path = __importStar(__nccwpck_require__(1017));
const ToolName = 'ossutil'; const ToolName = 'ossutil';
const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil'; const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil';
const IS_WINDOWS = process.platform === 'win32';
/** /**
* Install ossutil to PATH * Install ossutil to PATH
* @param version the version of ossutil * @param version the version of ossutil
@@ -32829,54 +32830,70 @@ exports.installOssutil = installOssutil;
*/ */
async function downloadOssutil(version) { async function downloadOssutil(version) {
// download // download
let toolFile; const downloadFileName = getDownloadFileName(version);
let downloadedFile;
try { try {
const downloadUrl = getDownloadUrl(version); const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip`;
core.info(`Downloading ossutil from: ${downloadUrl}`); core.info(`Downloading ossutil from: ${downloadUrl}`);
toolFile = await tc.downloadTool(downloadUrl); downloadedFile = await tc.downloadTool(downloadUrl);
} }
catch (error) { catch (error) {
core.error('Failed to download ossutil'); core.error('Failed to download ossutil');
throw error; throw error;
} }
core.debug(`ossutil downloaded to: ${toolFile}`); core.info(`ossutil downloaded to: ${downloadedFile}`);
// extract (if needed) // extract
if (process.platform === 'win32') { const zipFile = `${downloadedFile}.zip`;
const zipFile = `${toolFile}.zip`; await io.mv(downloadedFile, zipFile);
await io.mv(toolFile, zipFile); const extractFolder = await tc.extractZip(zipFile);
const extractFolder = await tc.extractZip(zipFile); const toolFileName = IS_WINDOWS ? 'ossutil64.exe' : 'ossutil64';
toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe'); const toolFile = path.join(extractFolder, downloadFileName, toolFileName);
core.debug(`ossutil extracted to: ${toolFile}`); if (fs.existsSync(toolFile)) {
core.info(`ossutil extracted to: ${toolFile}`);
}
else {
throw new Error('Unrecognized zip file structure');
} }
// change permission // change permission
fs.chmodSync(toolFile, 0o755); fs.chmodSync(toolFile, 0o755);
// cache // cache
const fileName = process.platform === 'win32' ? `${ToolName}.exe` : ToolName; const cacheFileName = IS_WINDOWS ? `${ToolName}.exe` : ToolName;
const toolPath = await tc.cacheFile(toolFile, fileName, ToolName, version); const toolPath = await tc.cacheFile(toolFile, cacheFileName, ToolName, version);
core.debug(`ossutil cached to: ${toolPath}`); core.info(`ossutil installed to: ${toolPath}`);
return 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 * @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) { function getDownloadFileName(version) {
let downloadUrl = `${DownloadEndpoint}/${version}/`; let platform = '';
switch (process.platform) { switch (process.platform) {
case 'linux': case 'linux':
downloadUrl += 'ossutil64'; platform = 'linux';
break; break;
case 'win32': case 'win32':
downloadUrl += 'ossutil64.zip'; platform = 'windows';
break; break;
case 'darwin': case 'darwin':
downloadUrl += 'ossutilmac64'; platform = 'mac';
break; break;
default: 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 * Get the latest version of ossutil
@@ -32940,8 +32957,8 @@ const installer = __importStar(__nccwpck_require__(2574));
*/ */
async function run() { async function run() {
try { try {
install(); await install();
config(); await config();
} }
catch (error) { catch (error) {
// Fail the workflow run if an error occurs // Fail the workflow run if an error occurs
@@ -32957,7 +32974,7 @@ async function install() {
} }
async function config() { async function config() {
const endpoint = core.getInput('endpoint'); const endpoint = core.getInput('endpoint');
if (endpoint.length == 0) { if (endpoint.length === 0) {
core.info('ossutil config is skipped'); core.info('ossutil config is skipped');
return; return;
} }
@@ -32981,7 +32998,7 @@ async function config() {
core.info('ossutil config is done'); core.info('ossutil config is done');
} }
else { else {
core.error('ossutil config is failed with exit code: ' + exitCode); core.error(`ossutil config is failed with exit code: ${exitCode}`);
} }
} }

View File

@@ -7,6 +7,7 @@ import * as path from 'path'
const ToolName = 'ossutil' const ToolName = 'ossutil'
const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil' const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil'
const IS_WINDOWS = process.platform === 'win32'
/** /**
* Install ossutil to PATH * Install ossutil to PATH
@@ -33,58 +34,79 @@ export async function installOssutil(version: string): Promise<void> {
*/ */
async function downloadOssutil(version: string): Promise<string> { async function downloadOssutil(version: string): Promise<string> {
// download // download
let toolFile: string const downloadFileName = getDownloadFileName(version)
let downloadedFile: string
try { try {
const downloadUrl = getDownloadUrl(version) const downloadUrl = `${DownloadEndpoint}/${version}/${downloadFileName}.zip`
core.info(`Downloading ossutil from: ${downloadUrl}`) core.info(`Downloading ossutil from: ${downloadUrl}`)
toolFile = await tc.downloadTool(downloadUrl) downloadedFile = await tc.downloadTool(downloadUrl)
} catch (error) { } catch (error) {
core.error('Failed to download ossutil') core.error('Failed to download ossutil')
throw error throw error
} }
core.debug(`ossutil downloaded to: ${toolFile}`) core.info(`ossutil downloaded to: ${downloadedFile}`)
// extract (if needed) // extract
if (process.platform === 'win32') { const zipFile = `${downloadedFile}.zip`
const zipFile = `${toolFile}.zip` await io.mv(downloadedFile, zipFile)
await io.mv(toolFile, zipFile) const extractFolder = await tc.extractZip(zipFile)
const extractFolder = await tc.extractZip(zipFile) const toolFileName = IS_WINDOWS ? 'ossutil64.exe' : 'ossutil64'
toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe') const toolFile = path.join(extractFolder, downloadFileName, toolFileName)
core.debug(`ossutil extracted to: ${toolFile}`) if (fs.existsSync(toolFile)) {
core.info(`ossutil extracted to: ${toolFile}`)
} else {
throw new Error('Unrecognized zip file structure')
} }
// change permission // change permission
fs.chmodSync(toolFile, 0o755) fs.chmodSync(toolFile, 0o755)
// cache // cache
const fileName = process.platform === 'win32' ? `${ToolName}.exe` : ToolName const cacheFileName = IS_WINDOWS ? `${ToolName}.exe` : ToolName
const toolPath = await tc.cacheFile(toolFile, fileName, ToolName, version) const toolPath = await tc.cacheFile(
core.debug(`ossutil cached to: ${toolPath}`) toolFile,
cacheFileName,
ToolName,
version
)
core.info(`ossutil installed to: ${toolPath}`)
return 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 * @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 { function getDownloadFileName(version: string): string {
let downloadUrl = `${DownloadEndpoint}/${version}/` let platform = ''
switch (process.platform) { switch (process.platform) {
case 'linux': case 'linux':
downloadUrl += 'ossutil64' platform = 'linux'
break break
case 'win32': case 'win32':
downloadUrl += 'ossutil64.zip' platform = 'windows'
break break
case 'darwin': case 'darwin':
downloadUrl += 'ossutilmac64' platform = 'mac'
break break
default: 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}`
} }
/** /**

View File

@@ -8,8 +8,8 @@ import * as installer from './installer'
*/ */
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
install() await install()
config() await config()
} catch (error) { } catch (error) {
// Fail the workflow run if an error occurs // Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message) if (error instanceof Error) core.setFailed(error.message)