create bin if not under go env GOPATH

This commit is contained in:
Bryan MacFarlane 2020-03-26 12:40:41 -04:00
parent 3e014ec8a4
commit 1fea44b3f0
3 changed files with 40 additions and 19 deletions

35
dist/index.js vendored
View File

@ -1276,6 +1276,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const io = __importStar(__webpack_require__(1));
const tc = __importStar(__webpack_require__(533)); const tc = __importStar(__webpack_require__(533));
const installer = __importStar(__webpack_require__(749)); const installer = __importStar(__webpack_require__(749));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
@ -1327,19 +1328,29 @@ function run() {
} }
exports.run = run; exports.run = run;
function addBinToPath() { function addBinToPath() {
let added = false; return __awaiter(this, void 0, void 0, function* () {
let buf = cp.execSync('go env GOPATH'); let added = false;
if (buf) { let g = yield io.which('go');
let d = buf.toString().trim(); if (!g) {
core.debug(`go env GOPATH: ${d}`); core.debug('go not in the path');
let bp = path.join(d, 'bin'); return added;
if (fs.existsSync(bp)) {
core.debug(`${bp} exists`);
core.addPath(bp);
added = true;
} }
} let buf = cp.execSync('go env GOPATH');
return added; 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;
});
} }

View File

@ -25,6 +25,7 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.2.2", "@actions/core": "^1.2.2",
"@actions/http-client": "^1.0.6", "@actions/http-client": "^1.0.6",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.3.1", "@actions/tool-cache": "^1.3.1",
"semver": "^6.1.1" "semver": "^6.1.1"
}, },

View File

@ -1,4 +1,5 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as installer from './installer'; import * as installer from './installer';
import * as path from 'path'; import * as path from 'path';
@ -59,17 +60,25 @@ export async function run() {
} }
} }
function addBinToPath(): boolean { async function addBinToPath(): Promise<boolean> {
let added = false; 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'); let buf = cp.execSync('go env GOPATH');
if (buf) { if (buf) {
let d = buf.toString().trim(); let gp = buf.toString().trim();
core.debug(`go env GOPATH: ${d}`); core.debug(`go env GOPATH: ${gp}`);
let bp = path.join(d, 'bin'); 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); core.addPath(bp);
added = true; added = true;
} }