Skip to content

Commit

Permalink
Add go-version to action outputs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcdonnnj committed Apr 7, 2022
1 parent bf7ccf1 commit 2930331
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion 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:
Expand All @@ -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'
6 changes: 6 additions & 0 deletions dist/index.js
Expand Up @@ -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<version> 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);
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Expand Up @@ -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<version> 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);
Expand Down

0 comments on commit 2930331

Please sign in to comment.