From f0f199da8d88ccf67d6ab6128dd2fc010f3c9cdc Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Sat, 24 Aug 2019 17:19:28 +0200 Subject: [PATCH] fix bin folder --- __tests__/main.test.ts | 24 ++++++++++++------------ lib/installer.js | 7 +++++++ src/installer.ts | 9 +++++++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 2afa1c9..b88e3d3 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -39,9 +39,9 @@ describe('installer tests', () => { expect(fs.existsSync(`${taskDir}.complete`)).toBe(true); if (IS_WINDOWS) { - expect(fs.existsSync(path.join(taskDir, 'task.exe'))).toBe(true); + expect(fs.existsSync(path.join(taskDir, 'bin', 'task.exe'))).toBe(true); } else { - expect(fs.existsSync(path.join(taskDir, 'task'))).toBe(true); + expect(fs.existsSync(path.join(taskDir, 'bin', 'task'))).toBe(true); } }, 100000); @@ -63,33 +63,33 @@ describe('installer tests', () => { expect(fs.existsSync(`${taskDir}.complete`)).toBe(true); if (IS_WINDOWS) { - expect(fs.existsSync(path.join(taskDir, 'task.exe'))).toBe(true); + expect(fs.existsSync(path.join(taskDir, 'bin', 'task.exe'))).toBe(true); } else { - expect(fs.existsSync(path.join(taskDir, 'task'))).toBe(true); + expect(fs.existsSync(path.join(taskDir, 'bin', 'task'))).toBe(true); } }); it('Gets latest version of Task using 2.x and no matching version is installed', async () => { await installer.getTask('2.x'); - const goDir = path.join(toolDir, 'task', '2.6.0', os.arch()); + const taskdir = path.join(toolDir, 'task', '2.6.0', os.arch()); - expect(fs.existsSync(`${goDir}.complete`)).toBe(true); + expect(fs.existsSync(`${taskdir}.complete`)).toBe(true); if (IS_WINDOWS) { - expect(fs.existsSync(path.join(goDir, 'task.exe'))).toBe(true); + expect(fs.existsSync(path.join(taskdir, 'bin', 'task.exe'))).toBe(true); } else { - expect(fs.existsSync(path.join(goDir, 'task'))).toBe(true); + expect(fs.existsSync(path.join(taskdir, 'bin', 'task'))).toBe(true); } }); it('Gets preview version of Task using 3.x and no matching version is installed', async () => { await installer.getTask('3.x'); - const goDir = path.join(toolDir, 'task', '3.0.0-preview1', os.arch()); + const taskdir = path.join(toolDir, 'task', '3.0.0-preview1', os.arch()); - expect(fs.existsSync(`${goDir}.complete`)).toBe(true); + expect(fs.existsSync(`${taskdir}.complete`)).toBe(true); if (IS_WINDOWS) { - expect(fs.existsSync(path.join(goDir, 'task.exe'))).toBe(true); + expect(fs.existsSync(path.join(taskdir, 'bin', 'task.exe'))).toBe(true); } else { - expect(fs.existsSync(path.join(goDir, 'task'))).toBe(true); + expect(fs.existsSync(path.join(taskdir, 'bin', 'task'))).toBe(true); } }); }); diff --git a/lib/installer.js b/lib/installer.js index 4f6d96a..b7b997b 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -40,6 +40,7 @@ if (!tempDirectory) { } const core = __importStar(require("@actions/core")); const tc = __importStar(require("@actions/tool-cache")); +const io = require("@actions/io"); let osPlat = os.platform(); let osArch = os.arch(); function getTask(version) { @@ -79,9 +80,15 @@ function downloadRelease(version) { let extPath = null; if (osPlat == 'win32') { extPath = yield tc.extractZip(downloadPath); + // Create a bin/ folder and move `task` there + yield io.mkdirP(path.join(extPath, 'bin')); + yield io.mv(path.join(extPath, 'task.exe'), path.join(extPath, 'bin')); } else { extPath = yield tc.extractTar(downloadPath); + // Create a bin/ folder and move `task` there + yield io.mkdirP(path.join(extPath, 'bin')); + yield io.mv(path.join(extPath, 'task'), path.join(extPath, 'bin')); } // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded return yield tc.cacheDir(extPath, 'task', version); diff --git a/src/installer.ts b/src/installer.ts index aea33da..bb9a8e2 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -24,8 +24,7 @@ if (!tempDirectory) { import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; -import { Cipher } from 'crypto'; -import { conditionalExpression } from '@babel/types'; +import io = require('@actions/io'); let osPlat: string = os.platform(); let osArch: string = os.arch(); @@ -75,8 +74,14 @@ async function downloadRelease(version: string): Promise { let extPath: string | null = null; if (osPlat == 'win32') { extPath = await tc.extractZip(downloadPath); + // Create a bin/ folder and move `task` there + await io.mkdirP(path.join(extPath, 'bin')) + await io.mv(path.join(extPath, 'task.exe'), path.join(extPath, 'bin')) } else { extPath = await tc.extractTar(downloadPath); + // Create a bin/ folder and move `task` there + await io.mkdirP(path.join(extPath, 'bin')) + await io.mv(path.join(extPath, 'task'), path.join(extPath, 'bin')) } // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded