From b99d85a130c5eab3f9de0d301ffb1deacbcc5ae1 Mon Sep 17 00:00:00 2001 From: Rimo Date: Wed, 15 Jan 2020 17:27:30 +0800 Subject: [PATCH] Make ossutil executable --- __tests__/installer.test.ts | 10 +++++++--- dist/index.js | 10 ++++++++-- src/installer.ts | 4 +++- src/setup-ossutil.ts | 6 +++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 5efcea5..cb93ed4 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -12,16 +12,18 @@ import * as installer from '../src/installer' const FILE_NAME = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil' +jest.setTimeout(60000) + describe('installer tests', () => { beforeAll(async () => { await io.rmRF(TOOL_DIR) await io.rmRF(TEMP_DIR) - }, 60000) + }) afterAll(async () => { await io.rmRF(TOOL_DIR) await io.rmRF(TEMP_DIR) - }, 60000) + }) it('install ossutil 1.6.10', async () => { const version = '1.6.10' @@ -32,7 +34,9 @@ describe('installer tests', () => { const exist = fs.existsSync(path.join(ossutilDir, FILE_NAME)) expect(exist).toBe(true) - }, 60000) + + expect(await io.which('ossutil', true)).toBeTruthy() + }) it('throw if wrong version', async () => { let thrown = false diff --git a/dist/index.js b/dist/index.js index 084f989..989e8cf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4013,6 +4013,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); const tc = __importStar(__webpack_require__(533)); const path = __importStar(__webpack_require__(622)); +const fs = __importStar(__webpack_require__(747)); const TOOL_NAME = 'ossutil'; /** * Get ossutil ready for use @@ -4025,7 +4026,7 @@ function getOssutil(version) { // download, extract, cache toolPath = yield acquireOssutil(version); } - core.info(`ossutil is cached under ${toolPath}`); + core.debug(`ossutil is cached under ${toolPath}`); core.addPath(toolPath); }); } @@ -4056,6 +4057,7 @@ function acquireOssutil(version) { toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe'); core.debug(`ossutil extracted to: ${toolFile}`); } + fs.chmodSync(toolFile, 0o755); // cache const fileName = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil'; const toolPath = yield tc.cacheFile(toolFile, fileName, TOOL_NAME, version); @@ -4163,6 +4165,7 @@ function run() { // download const version = core.getInput('ossutil-version'); yield installer.getOssutil(version); + core.info('ossutil is successfully installed'); // config const endpoint = core.getInput('endpoint'); const accessKeyId = core.getInput('access-key-id'); @@ -4178,7 +4181,10 @@ function run() { '--sts-token', stsToken ]; - yield exec.exec('ossutil', args); + const exitCode = yield exec.exec('ossutil', args); + if (exitCode === 0) { + core.info('ossutil config is done'); + } } catch (error) { core.setFailed(error.message); diff --git a/src/installer.ts b/src/installer.ts index 5570deb..eaeddc7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core' import * as tc from '@actions/tool-cache' import * as path from 'path' +import * as fs from 'fs' const TOOL_NAME = 'ossutil' @@ -15,7 +16,7 @@ export async function getOssutil(version: string): Promise { toolPath = await acquireOssutil(version) } - core.info(`ossutil is cached under ${toolPath}`) + core.debug(`ossutil is cached under ${toolPath}`) core.addPath(toolPath) } @@ -44,6 +45,7 @@ async function acquireOssutil(version: string): Promise { toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe') core.debug(`ossutil extracted to: ${toolFile}`) } + fs.chmodSync(toolFile, 0o755) // cache const fileName = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil' diff --git a/src/setup-ossutil.ts b/src/setup-ossutil.ts index 52f620c..24aff6a 100644 --- a/src/setup-ossutil.ts +++ b/src/setup-ossutil.ts @@ -7,6 +7,7 @@ async function run(): Promise { // download const version = core.getInput('ossutil-version') await installer.getOssutil(version) + core.info('ossutil is successfully installed') // config const endpoint = core.getInput('endpoint') @@ -23,7 +24,10 @@ async function run(): Promise { '--sts-token', stsToken ] - await exec.exec('ossutil', args) + const exitCode = await exec.exec('ossutil', args) + if (exitCode === 0) { + core.info('ossutil config is done') + } } catch (error) { core.setFailed(error.message) }