add bin to path

This commit is contained in:
Bryan MacFarlane
2020-03-26 11:53:35 -04:00
parent e0b6a4d694
commit 9c31f591e9
3 changed files with 35 additions and 1 deletions

View File

@ -1,9 +1,12 @@
import * as tc from '@actions/tool-cache';
import * as cm from '@actions/core';
import * as path from 'path';
import * as semver from 'semver';
import * as httpm from '@actions/http-client';
import * as sys from './system';
import {debug} from '@actions/core';
import * as cp from 'child_process';
import * as fs from 'fs';
export async function downloadGo(
versionSpec: string,
@ -34,6 +37,8 @@ export async function downloadGo(
// extracts with a root folder that matches the fileName downloaded
const toolRoot = path.join(extPath, 'go');
toolPath = await tc.cacheDir(toolRoot, 'go', makeSemver(match.version));
addBinToPath();
}
} catch (error) {
throw new Error(`Failed to download version ${versionSpec}: ${error}`);
@ -55,6 +60,17 @@ export interface IGoVersion {
files: IGoVersionFile[];
}
export async function addBinToPath() {
let buf = cp.execSync('go env GOPATH');
if (buf) {
let d = buf.toString().trim();
let bp = path.join(d, 'bin');
if (fs.existsSync(bp)) {
cm.addPath(bp);
}
}
}
export async function findMatch(
versionSpec: string,
stable: boolean