-
-
Notifications
You must be signed in to change notification settings - Fork 38
fix: Dispatcher updates now show the installed version #1422
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "dispatcherVersion": "3.0.1-beta.2", | ||
| "dispatcherVersion": "3.0.1-beta.3", | ||
| "dispatcherContractVersion": 1 | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "io" | ||
| "os" | ||
| "os/exec" | ||
| ) | ||
|
|
||
| var dispatcherReadInstalledVersion = readInstalledDispatcherVersion | ||
|
|
||
| type dispatcherVersionPayload struct { | ||
| DispatcherVersion string | ||
| } | ||
|
|
||
| func readInstalledDispatcherVersion(ctx context.Context) (string, error) { | ||
| executablePath, err := os.Executable() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| command := exec.CommandContext(ctx, executablePath, "--version", "--json") | ||
| output, err := command.Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| payload := dispatcherVersionPayload{} | ||
| if err := json.Unmarshal(output, &payload); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| updatedVersion := normalizeDispatcherVersion(payload.DispatcherVersion) | ||
| if updatedVersion == "" { | ||
| return "", errors.New("updated dispatcher version is empty") | ||
| } | ||
| if err := validateDispatcherCLIVersion(updatedVersion); err != nil { | ||
| return "", err | ||
| } | ||
| return updatedVersion, nil | ||
| } | ||
|
|
||
| func dispatcherInstalledVersionOrEmpty(ctx context.Context) string { | ||
| updatedVersion, err := dispatcherReadInstalledVersion(ctx) | ||
| if err != nil { | ||
| return "" | ||
| } | ||
| return updatedVersion | ||
| } | ||
|
|
||
| func dispatcherVersionChanged(fromVersion string, toVersion string) bool { | ||
| _, _, changed := normalizedDispatcherUpdateVersions(fromVersion, toVersion) | ||
| return changed | ||
| } | ||
|
|
||
| func normalizedDispatcherUpdateVersions(fromVersion string, toVersion string) (string, string, bool) { | ||
| normalizedFromVersion := normalizeDispatcherVersion(fromVersion) | ||
| normalizedToVersion := normalizeDispatcherVersion(toVersion) | ||
| changed := normalizedFromVersion != "" && normalizedToVersion != "" && normalizedFromVersion != normalizedToVersion | ||
| return normalizedFromVersion, normalizedToVersion, changed | ||
| } | ||
|
|
||
| func writeOptionalDispatcherUpdateCompletion(stderr io.Writer, fromVersion string, toVersion string) { | ||
| normalizedFromVersion, normalizedToVersion, changed := normalizedDispatcherUpdateVersions(fromVersion, toVersion) | ||
| if !changed { | ||
| return | ||
| } | ||
| writeFormat( | ||
| stderr, | ||
| "uloop: dispatcher updated from %s to %s. Future uloop commands will use the updated launcher.\n", | ||
| normalizedFromVersion, | ||
| normalizedToVersion) | ||
| } | ||
|
|
||
| func writeManualDispatcherUpdateCompletion(stdout io.Writer, fromVersion string, toVersion string) { | ||
| if toVersion == "" { | ||
| writeLine(stdout, "uloop launcher update completed.") | ||
| return | ||
| } | ||
| normalizedFromVersion, normalizedToVersion, changed := normalizedDispatcherUpdateVersions(fromVersion, toVersion) | ||
| if !changed { | ||
| writeLine(stdout, "uloop launcher is already up to date at "+normalizedToVersion+".") | ||
| return | ||
| } | ||
| writeLine(stdout, "uloop launcher updated from "+normalizedFromVersion+" to "+normalizedToVersion+".") | ||
| } | ||
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,25 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestDispatcherVersionChangedNormalizesVersionPrefix(t *testing.T) { | ||
| // Verifies v-prefixed and unprefixed dispatcher versions are treated as the same release. | ||
| if dispatcherVersionChanged("v3.0.1-beta.3", "3.0.1-beta.3") { | ||
| t.Fatal("expected equivalent dispatcher versions to be unchanged") | ||
| } | ||
| } | ||
|
|
||
| func TestWriteOptionalDispatcherUpdateCompletionReportsNormalizedVersions(t *testing.T) { | ||
| // Verifies dispatcher update messages report canonical versions after prefix normalization. | ||
| var stderr bytes.Buffer | ||
|
|
||
| writeOptionalDispatcherUpdateCompletion(&stderr, "v3.0.1-beta.2", "3.0.1-beta.3") | ||
|
|
||
| expected := "uloop: dispatcher updated from 3.0.1-beta.2 to 3.0.1-beta.3" | ||
| if !bytes.Contains(stderr.Bytes(), []byte(expected)) { | ||
| t.Fatalf("update output mismatch: %s", stderr.String()) | ||
| } | ||
| } |
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
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.