Set GOPATH to the default directory if unset

This commit is contained in:
CrazyMax 2019-09-04 01:36:31 +02:00 committed by CrazyMax
parent 595aed780b
commit eb3673a122
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
2 changed files with 234 additions and 207 deletions

View file

@ -113,16 +113,28 @@ function getDownloadUrl(filename) {
} }
function setGoEnvironmentVariables(goRoot) { function setGoEnvironmentVariables(goRoot) {
core.exportVariable('GOROOT', goRoot); core.exportVariable('GOROOT', goRoot);
const goPath = process.env['GOPATH'] || ''; const goPath = getGoPath();
const goBin = process.env['GOBIN'] || ''; const goBin = process.env['GOBIN'] || '';
// set GOPATH and GOBIN as user value // set GOPATH and GOBIN if defined
if (goPath) { if (goPath) {
core.exportVariable('GOPATH', goPath); core.exportVariable('GOPATH', goPath);
core.addPath(path.join(goPath, 'bin'));
} }
if (goBin) { if (goBin) {
core.exportVariable('GOBIN', goBin); core.exportVariable('GOBIN', goBin);
} }
} }
// Get GOPATH as user value or as defined by https://golang.org/doc/code.html#GOPATH
function getGoPath() {
const home = process.env['HOME'] || '';
const goPath = process.env['GOPATH'] || '';
if (goPath) {
return goPath;
} else if (home) {
return path.join(home, 'go');
}
return '';
}
// This function is required to convert the version 1.10 to 1.10.0. // This function is required to convert the version 1.10 to 1.10.0.
// Because caching utility accept only sementic version, // Because caching utility accept only sementic version,
// which have patch number as well. // which have patch number as well.

View file

@ -109,18 +109,33 @@ function getDownloadUrl(filename: string): string {
function setGoEnvironmentVariables(goRoot: string) { function setGoEnvironmentVariables(goRoot: string) {
core.exportVariable('GOROOT', goRoot); core.exportVariable('GOROOT', goRoot);
const goPath: string = process.env['GOPATH'] || ''; const goPath = getGoPath();
const goBin: string = process.env['GOBIN'] || ''; const goBin = process.env['GOBIN'] || '';
// set GOPATH and GOBIN as user value // set GOPATH and GOBIN as user value
if (goPath) { if (goPath) {
core.exportVariable('GOPATH', goPath); core.exportVariable('GOPATH', goPath);
core.addPath(path.join(goPath, 'bin'));
} }
if (goBin) { if (goBin) {
core.exportVariable('GOBIN', goBin); core.exportVariable('GOBIN', goBin);
} }
} }
// Get GOPATH as user value or as defined by https://golang.org/doc/code.html#GOPATH
function getGoPath(): string {
const home: string = process.env['HOME'] || '';
const goPath: string = process.env['GOPATH'] || '';
if (goPath) {
return goPath;
} else if (home) {
return path.join(home, 'go');
}
return '';
}
// This function is required to convert the version 1.10 to 1.10.0. // This function is required to convert the version 1.10 to 1.10.0.
// Because caching utility accept only sementic version, // Because caching utility accept only sementic version,
// which have patch number as well. // which have patch number as well.