Add 'go-version' Output#85
Conversation
|
Just a friendly bump/ping. |
|
Friendly bump @brcrista @magnetikonline :) |
| go-version: | ||
| description: 'The installed Go version. Useful when given a version range as input.' | ||
| runs: | ||
| using: 'node12' |
There was a problem hiding this comment.
@mcdonnnj you should do a git rebase main - some of this is out of date.
There was a problem hiding this comment.
Sorry, with no attention on this pull request it fell off my radar.
There was a problem hiding this comment.
It happens to the best of us @mcdonnnj - just figured it might shake out any merge issues for you. 👍
| // 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(''); |
There was a problem hiding this comment.
@mcdonnnj is this reliable cross-platform? Probably?
Also this is a simpler way?
| let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); | |
| let goVersionOutput = goVersion.split(' ')[2].slice(2); |
There was a problem hiding this comment.
Could probably avoid the use of goVersionOutput entirely too?
There was a problem hiding this comment.
@magnetikonline Sorry I had to knock the cobwebs out because it's been a long while since I looked at this pull request. I'm not sure why I felt I needed to expand it to an array and join() but yes your suggestion works fine. I'd also be happy to remove the variable entirely if that is preferred.
I just double-checked that this worked cross-platform in this Action run with jobs using ubuntu-latest, macos-latest, and windows-latest.
There was a problem hiding this comment.
+1 to @magnetikonline's suggestion, but we can also remove the magic number '2':
| let goVersionOutput = [...goVersion.split(' ')[2]].slice(2).join(''); | |
| let goVersionOutput = goVersion.split(' ')[2].slice('go'.length); |
There was a problem hiding this comment.
It would also be great if you could factor out this version-parsing logic to its own function and add a quick test for it. I think this is enough:
const goVersionOutput = "go version go1.16.6 darwin/amd64";
expect(parseGoVersion(goVersionOutput)).toBe("1.16.6")There was a problem hiding this comment.
@magnetikonline @brcrista Please see aa36c7f for your consideration. Please let me know if you'd like me to make any changes.
There was a problem hiding this comment.
Sorry was out for the weekend. @brcrista nice solution to the magic number 2 👍
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.
6adf460 to
2930331
Compare
|
@mcdonnnj looks like CI is failing. Could you run https://github.com/actions/setup-go/runs/5885728533?check_suite_focus=true#step:5:10 |
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>
aa36c7f to
b2f8b6e
Compare
@brcrista I've force-pushed with the corrected file. |
|
Good result all round, worthy addition 👍 |
* 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>
* 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>
* 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 provides a
go-versionoutput from this Action to provide the version that was installed. This is useful if you specify only a partial version such as1.15, but need the full version installed such as1.15.5for later use in a workflow. This is similar to the same functionality in actions/setup-python -https://github.com/actions/setup-python/blob/41b7212b1668f5de9d65e9c82aa777e6bbedb3a8/action.yml#L14-L16
Example
build.yml: