From 2930331465b244cefad18aeca848a78a1112bd11 Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Wed, 18 Nov 2020 14:03:03 -0500 Subject: [PATCH] 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. --- action.yml | 5 ++++- dist/index.js | 6 ++++++ src/main.ts | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8bbaebef5..ab0fdcaf1 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: 'Setup Go environment' description: 'Setup a Go environment and add it to the PATH' author: 'GitHub' -inputs: +inputs: go-version: description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' check-latest: @@ -10,6 +10,9 @@ inputs: token: description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user. default: ${{ github.token }} +outputs: + go-version: + description: 'The installed Go version. Useful when given a version range as input.' runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 48ceb0396..d194ebfda 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2100,6 +2100,12 @@ function run() { let goPath = yield io.which('go'); let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); core.info(goVersion); + // 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 for runtime.Version() + let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); + core.setOutput('go-version', goVersionOutput); core.startGroup('go env'); let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); core.info(goEnv); diff --git a/src/main.ts b/src/main.ts index 34784c47d..75c958719 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,6 +48,13 @@ export async function run() { let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); core.info(goVersion); + // 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 for runtime.Version() + let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); + core.setOutput('go-version', goVersionOutput); + core.startGroup('go env'); let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); core.info(goEnv);