mirror of
https://code.forgejo.org/actions/setup-go
synced 2025-06-08 19:48:21 +02:00
Add 'go-version' Output (#85)
* Add go-version to action outputs This provides the semver version of Go that has been installed. This is useful if only a major or minor version has been provided as the input go-version value. * Convert version extraction to a function Simplify how the version is extracted and add a simple test at the same time. Co-authored-by: Peter Mescalchin <peter@magnetikonline.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> Co-authored-by: Peter Mescalchin <peter@magnetikonline.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
This commit is contained in:
parent
115d6e6004
commit
4a4352b330
4 changed files with 29 additions and 2 deletions
10
src/main.ts
10
src/main.ts
|
@ -48,6 +48,8 @@ export async function run() {
|
|||
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
||||
core.info(goVersion);
|
||||
|
||||
core.setOutput('go-version', parseGoVersion(goVersion));
|
||||
|
||||
core.startGroup('go env');
|
||||
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||
core.info(goEnv);
|
||||
|
@ -94,3 +96,11 @@ function isGhes(): boolean {
|
|||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
export function parseGoVersion(versionString: string): string {
|
||||
// get the installed version as an Action output
|
||||
// based on go/src/cmd/go/internal/version/version.go:
|
||||
// fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
// expecting go<version> for runtime.Version()
|
||||
return versionString.split(' ')[2].slice('go'.length);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue