Skip to content

Clean up func version verbose output format#3581

Open
Ankitsinghsisodya wants to merge 8 commits intoknative:mainfrom
Ankitsinghsisodya:fix/version-output-cleanup
Open

Clean up func version verbose output format#3581
Ankitsinghsisodya wants to merge 8 commits intoknative:mainfrom
Ankitsinghsisodya:fix/version-output-cleanup

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented Apr 3, 2026

Changes

  • Omit fields with empty values from func version -v output instead of showing blank lines; affected fields: Knative, Commit, BuildDate, SocatImage, TarImage, Middleware Versions
  • Add BuildDate field to the version output, injected via Makefile ldflags at build time
  • Rewrite TestVerbose to assert field presence and absence rather than a hardcoded line count

/kind cleanup

Fixes #3518

Release Note

`func version -v` no longer displays blank lines for unpopulated fields. The following fields are now omitted when empty: Knative, Commit, BuildDate, SocatImage, TarImage, and Middleware Versions. A new BuildDate field is shown when the binary is built via the Makefile.

Docs


- 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
Copilot AI review requested due to automatic review settings April 3, 2026 18:44
@knative-prow knative-prow bot added the kind/cleanup Cleanup label Apr 3, 2026
@knative-prow knative-prow bot requested review from dsimansk and jrangelramos April 3, 2026 18:44
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Apr 3, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 3, 2026

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -v output.
  • Inject and surface a BuildDate value via Makefile -ldflags.
  • Rewrite TestVerbose to 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
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.31%. Comparing base (3e493ac) to head (3664809).
⚠️ Report is 1 commits behind head on main.

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              
Flag Coverage Δ
e2e 36.11% <91.66%> (+<0.01%) ⬆️
e2e go 32.53% <89.47%> (-0.02%) ⬇️
e2e node 28.34% <89.47%> (-0.02%) ⬇️
e2e python 32.90% <89.47%> (-0.02%) ⬇️
e2e quarkus 28.46% <89.47%> (-0.05%) ⬇️
e2e rust 27.90% <89.47%> (-0.02%) ⬇️
e2e springboot 26.36% <89.47%> (-0.03%) ⬇️
e2e typescript 28.43% <89.47%> (-0.05%) ⬇️
e2e-config-ci 18.12% <89.47%> (-0.03%) ⬇️
integration 17.41% <0.00%> (-0.03%) ⬇️
unit macos-14 43.45% <78.94%> (+0.08%) ⬆️
unit macos-latest 43.45% <78.94%> (+0.08%) ⬆️
unit ubuntu-24.04-arm 43.65% <83.33%> (+0.08%) ⬆️
unit ubuntu-latest 44.33% <78.94%> (+0.08%) ⬆️
unit windows-latest 43.47% <78.94%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- 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
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

cc @gauron99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Cleanup needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up func version output format

2 participants