-
Notifications
You must be signed in to change notification settings - Fork 210
mcp: use build-time version instead of hardcoded "0.1.0" #3832
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
Open
Ankitsinghsisodya
wants to merge
6
commits into
knative:main
Choose a base branch
from
Ankitsinghsisodya:fix/mcp-hardcoded-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8499fd1
Update MCP version handling to use version from pkg/version
Ankitsinghsisodya 851e84d
Refactor version handling to utilize new version package
Ankitsinghsisodya 8b0920f
Update go.mod to include Masterminds/semver/v3 v3.4.0 as a direct dep…
Ankitsinghsisodya 2a9aac5
Update healthcheckHandler to retrieve version using version.Get().Str…
Ankitsinghsisodya 566407e
Refactor MCP version handling to use computed version from Server struct
Ankitsinghsisodya f7c7f8d
Update go.mod to add indirect dependency on Masterminds/semver/v3 v3.4.0
Ankitsinghsisodya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,28 @@ | ||
| package version | ||
|
|
||
| import "github.com/Masterminds/semver/v3" | ||
|
|
||
| var Vers, Kver, Hash string | ||
|
|
||
| // DefaultVers is the fallback version used when no build-time version was | ||
| // injected (e.g. source builds that bypass the Makefile). | ||
| const DefaultVers = "v0.0.0+source" | ||
|
|
||
| // Get returns the parsed semver for this binary. When no build-time version | ||
| // was injected via ldflags, DefaultVers is used. If the injected string is | ||
| // unparseable, DefaultVers is used as a safe fallback. | ||
| // String() returns a clean semver without the leading "v" (e.g. "0.0.0+source"), | ||
| // suitable for machine-readable consumers such as the MCP server. | ||
| // Original() round-trips the injected string verbatim, preserving the leading | ||
| // "v" preferred by human-readable output. | ||
| func Get() *semver.Version { | ||
| s := Vers | ||
| if s == "" { | ||
| s = DefaultVers | ||
| } | ||
| v, err := semver.NewVersion(s) // permissive: accepts leading 'v' | ||
| if err != nil { | ||
| v, _ = semver.NewVersion(DefaultVers) | ||
| } | ||
|
Ankitsinghsisodya marked this conversation as resolved.
Outdated
|
||
| return v | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package version_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "knative.dev/func/pkg/version" | ||
| ) | ||
|
|
||
| // TestGet_Empty verifies that Get returns the DefaultVers fallback when no | ||
| // build-time version has been injected (Vers == ""). | ||
| func TestGet_Empty(t *testing.T) { | ||
| orig := version.Vers | ||
| version.Vers = "" | ||
| defer func() { version.Vers = orig }() | ||
|
|
||
| v := version.Get() | ||
| if v == nil { | ||
| t.Fatal("expected non-nil *semver.Version") | ||
| } | ||
| // String() must be clean semver without a leading 'v' | ||
| if got := v.String(); got != "0.0.0+source" { | ||
| t.Errorf("String() = %q; want %q", got, "0.0.0+source") | ||
| } | ||
| // Original() must round-trip the full default string including 'v' | ||
| if got := v.Original(); got != "v0.0.0+source" { | ||
| t.Errorf("Original() = %q; want %q", got, "v0.0.0+source") | ||
| } | ||
| } | ||
|
|
||
| // TestGet_InjectedVersion verifies that a build-time version is parsed and | ||
| // exposed correctly. | ||
| func TestGet_InjectedVersion(t *testing.T) { | ||
| orig := version.Vers | ||
| version.Vers = "v1.2.3" | ||
| defer func() { version.Vers = orig }() | ||
|
|
||
| v := version.Get() | ||
| if v == nil { | ||
| t.Fatal("expected non-nil *semver.Version") | ||
| } | ||
| if got := v.String(); got != "1.2.3" { | ||
| t.Errorf("String() = %q; want %q", got, "1.2.3") | ||
| } | ||
| if got := v.Original(); got != "v1.2.3" { | ||
| t.Errorf("Original() = %q; want %q", got, "v1.2.3") | ||
| } | ||
| } | ||
|
|
||
| // TestGet_InvalidFallsBack verifies that an unparseable injected version does | ||
| // not panic and falls back to DefaultVers. | ||
| func TestGet_InvalidFallsBack(t *testing.T) { | ||
| orig := version.Vers | ||
| version.Vers = "not-a-semver!!!" | ||
| defer func() { version.Vers = orig }() | ||
|
|
||
| v := version.Get() | ||
| if v == nil { | ||
| t.Fatal("expected non-nil *semver.Version even for invalid input") | ||
| } | ||
| if got := v.String(); got != "0.0.0+source" { | ||
| t.Errorf("String() = %q; want %q on invalid input", got, "0.0.0+source") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.