Skip to content

Commit 1fea44b

Browse files
create bin if not under go env GOPATH
1 parent 3e014ec commit 1fea44b

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

dist/index.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
12761276
};
12771277
Object.defineProperty(exports, "__esModule", { value: true });
12781278
const core = __importStar(__webpack_require__(470));
1279+
const io = __importStar(__webpack_require__(1));
12791280
const tc = __importStar(__webpack_require__(533));
12801281
const installer = __importStar(__webpack_require__(749));
12811282
const path = __importStar(__webpack_require__(622));
@@ -1327,19 +1328,29 @@ function run() {
13271328
}
13281329
exports.run = run;
13291330
function addBinToPath() {
1330-
let added = false;
1331-
let buf = cp.execSync('go env GOPATH');
1332-
if (buf) {
1333-
let d = buf.toString().trim();
1334-
core.debug(`go env GOPATH: ${d}`);
1335-
let bp = path.join(d, 'bin');
1336-
if (fs.existsSync(bp)) {
1337-
core.debug(`${bp} exists`);
1338-
core.addPath(bp);
1339-
added = true;
1331+
return __awaiter(this, void 0, void 0, function* () {
1332+
let added = false;
1333+
let g = yield io.which('go');
1334+
if (!g) {
1335+
core.debug('go not in the path');
1336+
return added;
13401337
}
1341-
}
1342-
return added;
1338+
let buf = cp.execSync('go env GOPATH');
1339+
if (buf) {
1340+
let gp = buf.toString().trim();
1341+
core.debug(`go env GOPATH: ${gp}`);
1342+
if (fs.existsSync(gp)) {
1343+
let bp = path.join(gp, 'bin');
1344+
if (!fs.existsSync(bp)) {
1345+
core.debug(`creating ${bp}`);
1346+
io.mkdirP(bp);
1347+
}
1348+
core.addPath(bp);
1349+
added = true;
1350+
}
1351+
}
1352+
return added;
1353+
});
13431354
}
13441355

13451356

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependencies": {
2626
"@actions/core": "^1.2.2",
2727
"@actions/http-client": "^1.0.6",
28+
"@actions/io": "^1.0.2",
2829
"@actions/tool-cache": "^1.3.1",
2930
"semver": "^6.1.1"
3031
},

src/main.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@actions/core';
2+
import * as io from '@actions/io';
23
import * as tc from '@actions/tool-cache';
34
import * as installer from './installer';
45
import * as path from 'path';
@@ -59,17 +60,25 @@ export async function run() {
5960
}
6061
}
6162

62-
function addBinToPath(): boolean {
63+
async function addBinToPath(): Promise<boolean> {
6364
let added = false;
64-
let buf = cp.execSync('go env GOPATH');
65+
let g = await io.which('go');
66+
if (!g) {
67+
core.debug('go not in the path');
68+
return added;
69+
}
6570

71+
let buf = cp.execSync('go env GOPATH');
6672
if (buf) {
67-
let d = buf.toString().trim();
68-
core.debug(`go env GOPATH: ${d}`);
69-
let bp = path.join(d, 'bin');
73+
let gp = buf.toString().trim();
74+
core.debug(`go env GOPATH: ${gp}`);
75+
if (fs.existsSync(gp)) {
76+
let bp = path.join(gp, 'bin');
77+
if (!fs.existsSync(bp)) {
78+
core.debug(`creating ${bp}`);
79+
io.mkdirP(bp);
80+
}
7081

71-
if (fs.existsSync(bp)) {
72-
core.debug(`${bp} exists`);
7382
core.addPath(bp);
7483
added = true;
7584
}

0 commit comments

Comments
 (0)