Clean up func version verbose output format#3581
Clean up func version verbose output format#3581Ankitsinghsisodya wants to merge 8 commits intoknative:mainfrom
Conversation
- Omit empty fields (Knative, Commit, BuildDate) from verbose output - Add BuildDate field injected via Makefile ldflags - Update TestVerbose to assert field presence/absence rather than line count
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankitsinghsisodya The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Ankitsinghsisodya. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
There was a problem hiding this comment.
Pull request overview
Updates the func version -v command output to be cleaner and more informative by omitting unset metadata fields and adding a build timestamp when available via Makefile ldflags.
Changes:
- Omit empty metadata fields (Knative/Commit/BuildDate) from
func version -voutput. - Inject and surface a
BuildDatevalue via Makefile-ldflags. - Rewrite
TestVerboseto assert presence/absence of fields instead of relying on a fixed line count.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/version/version.go | Adds a new BuildDate variable for ldflags injection. |
| Makefile | Injects a UTC build timestamp into pkg/version.BuildDate via ldflags. |
| cmd/version.go | Populates BuildDate (when unset), and rewrites verbose formatting to omit empty fields. |
| cmd/root_test.go | Updates verbose output tests to check for specific included/omitted fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3581 +/- ##
==========================================
+ Coverage 56.24% 56.31% +0.06%
==========================================
Files 180 180
Lines 20465 20466 +1
==========================================
+ Hits 11511 11525 +14
+ Misses 7755 7742 -13
Partials 1199 1199
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Inject BuildDate at startup in pkg/app/app.go instead of reading pkgversion.BuildDate as a side-effect in runVersion, making tests deterministic regardless of ldflags - Fix kver prefix stripping to use strings.TrimPrefix, preserving commit-distance suffixes (e.g. knative-v1.10.0-5-g... → v1.10.0-5-g...) - Remove trailing space from 'Middleware Versions: ' label - Delete cmd/version_test.go; consolidate all version tests into TestVerbose subtests in cmd/root_test.go - Strengthen JSON assertion to check for exact field value - Add subtest for empty MiddlewareVersions omission - Add subtest for kver with commit-distance suffix
…ilds - Replace wall-clock date with git log -1 --format=%cI HEAD so that rebuilding the same commit always produces the same binary hash - Assert buildDate appears in JSON output when populated - Add exact-output subtest to guard against blank lines between fields
|
cc @gauron99 |
Changes
func version -voutput instead of showing blank lines; affected fields: Knative, Commit, BuildDate, SocatImage, TarImage, Middleware VersionsBuildDatefield to the version output, injected via Makefile ldflags at build timeTestVerboseto assert field presence and absence rather than a hardcoded line count/kind cleanup
Fixes #3518
Release Note
Docs