mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 09:52:15 +00:00
Set GOPATH to the default directory if unset
This commit is contained in:
parent
595aed780b
commit
eb3673a122
2 changed files with 234 additions and 207 deletions
|
@ -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.
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue