Skip to content

Commit 9c31f59

Browse files
add bin to path
1 parent e0b6a4d commit 9c31f59

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.github/workflows/versions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ jobs:
4343
- name: validate version
4444
run: go version | grep "go1.12.9"
4545

46-
- name: show cache
46+
- name: dump env
4747
shell: bash
4848
run: |
49+
echo $PATH
4950
echo go versions in tool cache:
5051
echo $(ls $RUNNER_TOOL_CACHE/go)

dist/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4576,11 +4576,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
45764576
};
45774577
Object.defineProperty(exports, "__esModule", { value: true });
45784578
const tc = __importStar(__webpack_require__(533));
4579+
const cm = __importStar(__webpack_require__(470));
45794580
const path = __importStar(__webpack_require__(622));
45804581
const semver = __importStar(__webpack_require__(280));
45814582
const httpm = __importStar(__webpack_require__(539));
45824583
const sys = __importStar(__webpack_require__(737));
45834584
const core_1 = __webpack_require__(470);
4585+
const cp = __importStar(__webpack_require__(129));
4586+
const fs = __importStar(__webpack_require__(747));
45844587
function downloadGo(versionSpec, stable) {
45854588
return __awaiter(this, void 0, void 0, function* () {
45864589
let toolPath;
@@ -4602,6 +4605,7 @@ function downloadGo(versionSpec, stable) {
46024605
// extracts with a root folder that matches the fileName downloaded
46034606
const toolRoot = path.join(extPath, 'go');
46044607
toolPath = yield tc.cacheDir(toolRoot, 'go', makeSemver(match.version));
4608+
addBinToPath();
46054609
}
46064610
}
46074611
catch (error) {
@@ -4611,6 +4615,19 @@ function downloadGo(versionSpec, stable) {
46114615
});
46124616
}
46134617
exports.downloadGo = downloadGo;
4618+
function addBinToPath() {
4619+
return __awaiter(this, void 0, void 0, function* () {
4620+
let buf = cp.execSync('go env GOPATH');
4621+
if (buf) {
4622+
let d = buf.toString().trim();
4623+
let bp = path.join(d, 'bin');
4624+
if (fs.existsSync(bp)) {
4625+
cm.addPath(bp);
4626+
}
4627+
}
4628+
});
4629+
}
4630+
exports.addBinToPath = addBinToPath;
46144631
function findMatch(versionSpec, stable) {
46154632
return __awaiter(this, void 0, void 0, function* () {
46164633
let archFilter = sys.getArch();

src/installer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import * as tc from '@actions/tool-cache';
2+
import * as cm from '@actions/core';
23
import * as path from 'path';
34
import * as semver from 'semver';
45
import * as httpm from '@actions/http-client';
56
import * as sys from './system';
67
import {debug} from '@actions/core';
8+
import * as cp from 'child_process';
9+
import * as fs from 'fs';
710

811
export async function downloadGo(
912
versionSpec: string,
@@ -34,6 +37,8 @@ export async function downloadGo(
3437
// extracts with a root folder that matches the fileName downloaded
3538
const toolRoot = path.join(extPath, 'go');
3639
toolPath = await tc.cacheDir(toolRoot, 'go', makeSemver(match.version));
40+
41+
addBinToPath();
3742
}
3843
} catch (error) {
3944
throw new Error(`Failed to download version ${versionSpec}: ${error}`);
@@ -55,6 +60,17 @@ export interface IGoVersion {
5560
files: IGoVersionFile[];
5661
}
5762

63+
export async function addBinToPath() {
64+
let buf = cp.execSync('go env GOPATH');
65+
if (buf) {
66+
let d = buf.toString().trim();
67+
let bp = path.join(d, 'bin');
68+
if (fs.existsSync(bp)) {
69+
cm.addPath(bp);
70+
}
71+
}
72+
}
73+
5874
export async function findMatch(
5975
versionSpec: string,
6076
stable: boolean

0 commit comments

Comments
 (0)