-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨Add RELEASE_TAG to tools/setup-envtest to show binary version with setup-envtest version #3166
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
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 | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||||
package version | ||||||||
|
||||||||
import "runtime/debug" | ||||||||
|
||||||||
// Version to be set using ldflags: | ||||||||
// -ldflags "-X sigs.k8s.io/controller-tools/pkg/version.version=v1.0.0" | ||||||||
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
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. @sbueringer I can make a PR for this to fix the godoc rendering with the correct comment. 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. Ups. Yup, thx! |
||||||||
// falls back to module information is unse | ||||||||
var version = "" | ||||||||
|
||||||||
// Version returns the version of the main module | ||||||||
func Version() string { | ||||||||
if version != "" { | ||||||||
return version | ||||||||
} | ||||||||
info, ok := debug.ReadBuildInfo() | ||||||||
if !ok || info == nil || info.Main.Version == "" { | ||||||||
// binary has not been built with module support or doesn't contain a version. | ||||||||
return "(unknown)" | ||||||||
} | ||||||||
return info.Main.Version | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package version | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestVersioning(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Test Version Suite") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
||
See the License for the specific language governing permissions and | ||
|
||
limitations under the License. | ||
*/ | ||
|
||
package version | ||
|
||
import ( | ||
"runtime/debug" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("TestVersion", func() { | ||
|
||
info, ok := debug.ReadBuildInfo() | ||
Expect(ok).To(BeTrue()) | ||
tests := map[string]struct { | ||
version string | ||
expected string | ||
}{ | ||
"empty returns build info": { | ||
version: "", | ||
expected: info.Main.Version, | ||
}, | ||
"set to a value returns it": { | ||
version: "1.2.3", | ||
expected: "1.2.3", | ||
}, | ||
} | ||
for name, tc := range tests { | ||
It("Version set to "+name, func() { | ||
versionBackup := version | ||
defer func() { | ||
version = versionBackup | ||
}() | ||
version = tc.version | ||
result := Version() | ||
Expect(result).To(Equal(tc.expected)) | ||
}) | ||
} | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.