From f9f7965bdf77daf62038b3e434b1a979c3b90df6 Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Sat, 21 Sep 2019 09:46:58 +0900 Subject: [PATCH] refactor: enhance error handling --- node_modules/@actions/exec/package.json | 68 ++++++++----------------- src/index.ts | 45 ++++++++-------- 2 files changed, 45 insertions(+), 68 deletions(-) diff --git a/node_modules/@actions/exec/package.json b/node_modules/@actions/exec/package.json index d9497e6..bb85262 100644 --- a/node_modules/@actions/exec/package.json +++ b/node_modules/@actions/exec/package.json @@ -1,39 +1,15 @@ { - "_from": "@actions/exec", - "_id": "@actions/exec@1.0.1", - "_inBundle": false, - "_integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==", - "_location": "/@actions/exec", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "@actions/exec", - "name": "@actions/exec", - "escapedName": "@actions%2fexec", - "scope": "@actions", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER", - "/", - "/@actions/tool-cache" - ], - "_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz", - "_shasum": "1624b541165697e7008d7c87bc1f69f191263c6c", - "_spec": "@actions/exec", - "_where": "/Users/iris/Documents/repos/github.com/peaceiris/actions-hugo", - "bugs": { - "url": "https://github.com/actions/toolkit/issues" - }, - "bundleDependencies": false, - "deprecated": false, + "name": "@actions/exec", + "version": "1.0.1", "description": "Actions exec lib", - "devDependencies": { - "@actions/io": "^1.0.1" - }, + "keywords": [ + "github", + "actions", + "exec" + ], + "homepage": "https://github.com/actions/toolkit/tree/master/packages/exec", + "license": "MIT", + "main": "lib/exec.js", "directories": { "lib": "lib", "test": "__tests__" @@ -41,16 +17,6 @@ "files": [ "lib" ], - "gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52", - "homepage": "https://github.com/actions/toolkit/tree/master/packages/exec", - "keywords": [ - "github", - "actions", - "exec" - ], - "license": "MIT", - "main": "lib/exec.js", - "name": "@actions/exec", "publishConfig": { "access": "public" }, @@ -62,5 +28,15 @@ "test": "echo \"Error: run tests from root\" && exit 1", "tsc": "tsc" }, - "version": "1.0.1" -} + "bugs": { + "url": "https://github.com/actions/toolkit/issues" + }, + "devDependencies": { + "@actions/io": "^1.0.1" + }, + "gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52" + +,"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz" +,"_integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==" +,"_from": "@actions/exec@1.0.1" +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 00f0229..6b09d7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,30 +5,31 @@ import installer from "./installer"; // most @actions toolkit packages have async methods async function run() { + const dump = async () => { + // Show version + await exec.exec("hugo version"); + await exec.exec("go version"); + await exec.exec("git --version"); + }; + try { - getLatestVersion().then( - async function(latestVersion): Promise { - const hugoVersion: string = core.getInput("hugo-version"); - console.log(`Hugo version: ${hugoVersion}`); - const version = (v: string, latestVersion: string): string => { - if (v === "" || v === "latest") { - return latestVersion; - } else { - return v; - } - }; + const hugoVersion: string = core.getInput("hugo-version"); + console.log(`Hugo version: ${hugoVersion}`); - await installer(version(hugoVersion, latestVersion)); - - // Show version - await exec.exec("hugo version"); - await exec.exec("go version"); - await exec.exec("git --version"); - }, - function(error) { - core.setFailed(error); - } - ); + if (hugoVersion === "" || hugoVersion === "latest") { + getLatestVersion().then( + async function(latestVersion): Promise { + await installer(latestVersion); + await dump(); + }, + function(error) { + core.setFailed(error); + } + ); + } else { + await installer(hugoVersion); + await dump(); + } } catch (error) { core.setFailed(error.message); }