From 1fea44b3f04009d8a74be981ab94ae7ca3fe7ff7 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Thu, 26 Mar 2020 12:40:41 -0400 Subject: [PATCH] create bin if not under go env GOPATH --- dist/index.js | 35 +++++++++++++++++++++++------------ package.json | 1 + src/main.ts | 23 ++++++++++++++++------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/dist/index.js b/dist/index.js index fee1cca..9bcdebb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1276,6 +1276,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); +const io = __importStar(__webpack_require__(1)); const tc = __importStar(__webpack_require__(533)); const installer = __importStar(__webpack_require__(749)); const path = __importStar(__webpack_require__(622)); @@ -1327,19 +1328,29 @@ function run() { } exports.run = run; function addBinToPath() { - let added = false; - let buf = cp.execSync('go env GOPATH'); - if (buf) { - let d = buf.toString().trim(); - core.debug(`go env GOPATH: ${d}`); - let bp = path.join(d, 'bin'); - if (fs.existsSync(bp)) { - core.debug(`${bp} exists`); - core.addPath(bp); - added = true; + return __awaiter(this, void 0, void 0, function* () { + let added = false; + let g = yield io.which('go'); + if (!g) { + core.debug('go not in the path'); + return added; } - } - return added; + let buf = cp.execSync('go env GOPATH'); + if (buf) { + let gp = buf.toString().trim(); + core.debug(`go env GOPATH: ${gp}`); + if (fs.existsSync(gp)) { + let bp = path.join(gp, 'bin'); + if (!fs.existsSync(bp)) { + core.debug(`creating ${bp}`); + io.mkdirP(bp); + } + core.addPath(bp); + added = true; + } + } + return added; + }); } diff --git a/package.json b/package.json index 8a40f82..1a26449 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "@actions/core": "^1.2.2", "@actions/http-client": "^1.0.6", + "@actions/io": "^1.0.2", "@actions/tool-cache": "^1.3.1", "semver": "^6.1.1" }, diff --git a/src/main.ts b/src/main.ts index 9431d05..0c0aa6b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import * as installer from './installer'; import * as path from 'path'; @@ -59,17 +60,25 @@ export async function run() { } } -function addBinToPath(): boolean { +async function addBinToPath(): Promise { let added = false; + let g = await io.which('go'); + if (!g) { + core.debug('go not in the path'); + return added; + } + let buf = cp.execSync('go env GOPATH'); - if (buf) { - let d = buf.toString().trim(); - core.debug(`go env GOPATH: ${d}`); - let bp = path.join(d, 'bin'); + let gp = buf.toString().trim(); + core.debug(`go env GOPATH: ${gp}`); + if (fs.existsSync(gp)) { + let bp = path.join(gp, 'bin'); + if (!fs.existsSync(bp)) { + core.debug(`creating ${bp}`); + io.mkdirP(bp); + } - if (fs.existsSync(bp)) { - core.debug(`${bp} exists`); core.addPath(bp); added = true; }