-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Infer version information for go-install #4516
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ package cmd | |||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"runtime" | ||||||
"runtime/debug" | ||||||
) | ||||||
|
||||||
|
@@ -27,38 +28,69 @@ const unknown = "unknown" | |||||
// information in the release process | ||||||
var ( | ||||||
kubeBuilderVersion = unknown | ||||||
kubernetesVendorVersion = unknown | ||||||
goos = unknown | ||||||
goarch = unknown | ||||||
gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD) | ||||||
kubernetesVendorVersion = "1.32.1" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to share, if you want to work on this one. We can do that as a follow up, but we need a target to be called when we run amke generate that will update the k8s version here and in the goreleaser based on the k8s/api (like https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/Makefile#L179) so, that we can ensure that it is in sync always. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: #4588 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I thought of that too while I was working on this file. I'll give it go. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ops, it has been assigned already. All good. |
||||||
goVersion = unknown | ||||||
goOs = unknown | ||||||
goArch = unknown | ||||||
gitCommit = unknown // "$Format:%H$" sha1 from git, output of $(git rev-parse HEAD) | ||||||
|
||||||
buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||||||
// "1970-01-01T00:00:00Z" build date in ISO8601 format | ||||||
// Output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||||||
buildDate = unknown | ||||||
) | ||||||
|
||||||
// version contains all the information related to the CLI version | ||||||
type version struct { | ||||||
KubeBuilderVersion string `json:"kubeBuilderVersion"` | ||||||
KubernetesVendor string `json:"kubernetesVendor"` | ||||||
GitCommit string `json:"gitCommit"` | ||||||
BuildDate string `json:"buildDate"` | ||||||
GoVersion string `json:"goVersion"` | ||||||
GoOs string `json:"goOs"` | ||||||
GoArch string `json:"goArch"` | ||||||
GitCommit string `json:"gitCommit"` | ||||||
BuildDate string `json:"buildDate"` | ||||||
} | ||||||
|
||||||
// versionString returns the CLI version | ||||||
func versionString() string { | ||||||
if kubeBuilderVersion == unknown { | ||||||
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" { | ||||||
kubeBuilderVersion = info.Main.Version | ||||||
if goVersion == unknown { | ||||||
goVersion = runtime.Version() | ||||||
} | ||||||
|
||||||
if goOs == unknown { | ||||||
goOs = runtime.GOOS | ||||||
} | ||||||
|
||||||
if goArch == unknown { | ||||||
goArch = runtime.GOARCH | ||||||
} | ||||||
|
||||||
info, ok := debug.ReadBuildInfo() | ||||||
|
||||||
if ok { | ||||||
if info.Main.Version != "" { | ||||||
if kubeBuilderVersion == unknown { | ||||||
kubeBuilderVersion = info.Main.Version | ||||||
} | ||||||
} | ||||||
|
||||||
for _, setting := range info.Settings { | ||||||
if buildDate == unknown && setting.Key == "vcs.revision" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This should be a Also would be nice to have a minimal test for this case, as I described before mocking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /hold until @dmvolod give LGTM |
||||||
buildDate = setting.Value | ||||||
} | ||||||
|
||||||
if gitCommit == unknown && setting.Key == "vcs.revision" { | ||||||
gitCommit = setting.Value | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return fmt.Sprintf("Version: %#v", version{ | ||||||
kubeBuilderVersion, | ||||||
kubernetesVendorVersion, | ||||||
goVersion, | ||||||
goOs, | ||||||
goArch, | ||||||
gitCommit, | ||||||
buildDate, | ||||||
goos, | ||||||
goarch, | ||||||
}) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @migueleliasweb and @dmvolod
Could we ensure that this one is rebased with master?
Also, is this one good to fly or what would be missing?
Is possible ensure that we have in the description an example of test executed for we ensure that all is fine and make easier the review/validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, @camilamacedo86 I can't help with rebase this PR as can't owns it.
Just fixed suggesting and it can be applied who can owns repo or PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry all, I've got stuck on a crazy hectic week and a bit at work. Once this is off by back, I'll come back to this if that's okay. 🙏 I didn't forget this PR!