-
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
✨ [Improvement] Infer version information for go-install #4516
base: master
Are you sure you want to change the base?
✨ [Improvement] Infer version information for go-install #4516
Conversation
Signed-off-by: Miguel Elias dos Santos <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: migueleliasweb The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @migueleliasweb. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@@ -27,12 +30,11 @@ const unknown = "unknown" | |||
// information in the release process | |||
var ( | |||
kubeBuilderVersion = unknown | |||
kubernetesVendorVersion = unknown | |||
kubernetesVendorVersion = "1.31.0" |
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.
I took the liberty of making this the default value originally from https://github.com/kubernetes-sigs/kubebuilder/blob/master/build/.goreleaser.yml. Potentially, this value could be tracked solely here to avoid having to update 2 places every time.
If it is preferred to keep the value as unknown
, let me know.
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.
I think it is fine, but we need to bump 1.32.0
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.
} | ||
|
||
if gitCommit == unknown && info.Main.Version != "" { | ||
mainVersionSplit := strings.Split(info.Main.Version, "-") |
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.
@migueleliasweb wdyt about to utilize a semver parsing library who supports pre-release segments, i.e. https://github.com/Masterminds/semver instead of custom code?
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.
I'm not against it if it's compatible. I'd have to check. Also, adding a new dependency for such a small usecase kinda feels a bit unnecessary.
I'll give it a shot.
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" { | ||
info, ok := debug.ReadBuildInfo() | ||
|
||
if ok && info.Main.Version != "" { |
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.
Since the code becomes more complex than it was before, it would be nice to be able to write tests, mocking debug.ReadBuildInfo()
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.
I'll definitely be interesting creating mock for it. I'll give it a shot.
// For released semvers like "v4.5.0" | ||
// Result: info.Main.Version == "semver" | ||
if len(mainVersionSplit) == 1 { | ||
gitCommit = info.Main.Version |
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.
It should be validated, but probably much easy to get commit hash (vcs.revision) and time (vcs.time) from the info.Settings
like
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
gitCommit = setting.Value
}
}
/ok-to-test |
Now that
kubebuilder
is go-installable 🎉, this is a small improvement to fetch more information when dealing withgo install
installations.Currently, the output from
kubebuilder version
looks like this:With this PR, we will now infer correctly
GitCommit
,BuildDate
,GoOs
andGoArch
for normalGoReleaser
builds but alsogo install
installations.