From 17fabeb6e0f7c6abac79083a8f724ae720f1f6a2 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Fri, 3 Jan 2020 17:08:32 +0900 Subject: [PATCH] refactor: Remove extra try-catch (#30) * refactor: Remove extra try-catch * refactor: Rename mdbook to tool --- src/installer.ts | 64 +++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 1857009..fbc0974 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -17,42 +17,38 @@ if (!tempDir) { } export default async function installer(version: string) { - try { - const osName: string = getOS(process.platform); - console.log(`Operating System: ${osName}`); + const osName: string = getOS(process.platform); + console.log(`Operating System: ${osName}`); - const mdbookURL: string = getURL(osName, version); - core.debug(`mdbookURL: ${mdbookURL}`); + const toolURL: string = getURL(osName, version); + core.debug(`toolURL: ${toolURL}`); - let baseLocation: string; - if (process.platform === 'win32') { - baseLocation = process.env['USERPROFILE'] || 'C:\\'; - } else { - baseLocation = `${process.env.HOME}`; - } - const mdbookPath: string = path.join(baseLocation, 'mdbookbin'); - await io.mkdirP(mdbookPath); - core.addPath(mdbookPath); + let baseLocation: string; + if (process.platform === 'win32') { + baseLocation = process.env['USERPROFILE'] || 'C:\\'; + } else { + baseLocation = `${process.env.HOME}`; + } + const toolPath: string = path.join(baseLocation, 'toolbin'); + await io.mkdirP(toolPath); + core.addPath(toolPath); - // Download and extract mdbook binary - await io.mkdirP(tempDir); - const mdbookAssets: string = await tc.downloadTool(mdbookURL); - let mdbookBin: string = ''; - if (osName === 'pc-windows-msvc') { - const mdbookExtractedFolder: string = await tc.extractZip( - mdbookAssets, - tempDir - ); - mdbookBin = `${mdbookExtractedFolder}/mdbook.exe`; - } else { - const mdbookExtractedFolder: string = await tc.extractTar( - mdbookAssets, - tempDir - ); - mdbookBin = `${mdbookExtractedFolder}/mdbook`; - } - await io.mv(mdbookBin, mdbookPath); - } catch (error) { - core.setFailed(error.message); + // Download and extract mdbook binary + await io.mkdirP(tempDir); + const toolAssets: string = await tc.downloadTool(toolURL); + let toolBin: string = ''; + if (osName === 'pc-windows-msvc') { + const toolExtractedFolder: string = await tc.extractZip( + toolAssets, + tempDir + ); + toolBin = `${toolExtractedFolder}/mdbook.exe`; + } else { + const toolExtractedFolder: string = await tc.extractTar( + toolAssets, + tempDir + ); + toolBin = `${toolExtractedFolder}/mdbook`; } + await io.mv(toolBin, toolPath); }