fix prerelease channel normalisation
This commit is contained in:
parent
00f30708ac
commit
bbd06db2df
3 changed files with 16 additions and 4 deletions
5
cmd.go
5
cmd.go
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"forge.lthn.ai/core/cli/pkg/cli"
|
"forge.lthn.ai/core/cli/pkg/cli"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -46,7 +45,7 @@ Examples:
|
||||||
RunE: runUpdate,
|
RunE: runUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCmd.PersistentFlags().StringVar(&updateChannel, "channel", "stable", "Release channel: stable, beta, alpha, or dev")
|
updateCmd.PersistentFlags().StringVar(&updateChannel, "channel", "stable", "Release channel: stable, beta, alpha, prerelease, or dev")
|
||||||
updateCmd.PersistentFlags().BoolVar(&updateForce, "force", false, "Force update even if already on latest version")
|
updateCmd.PersistentFlags().BoolVar(&updateForce, "force", false, "Force update even if already on latest version")
|
||||||
updateCmd.Flags().BoolVar(&updateCheck, "check", false, "Only check for updates, do not apply")
|
updateCmd.Flags().BoolVar(&updateCheck, "check", false, "Only check for updates, do not apply")
|
||||||
updateCmd.Flags().IntVar(&updateWatchPID, "watch-pid", 0, "Internal: watch for parent PID to die then restart")
|
updateCmd.Flags().IntVar(&updateWatchPID, "watch-pid", 0, "Internal: watch for parent PID to die then restart")
|
||||||
|
|
@ -73,7 +72,7 @@ func runUpdate(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentVersion := cli.AppVersion
|
currentVersion := cli.AppVersion
|
||||||
normalizedChannel := strings.TrimSpace(strings.ToLower(updateChannel))
|
normalizedChannel := normaliseGitHubChannel(updateChannel)
|
||||||
|
|
||||||
cli.Print("%s %s\n", cli.DimStyle.Render("Current version:"), cli.ValueStyle.Render(currentVersion))
|
cli.Print("%s %s\n", cli.DimStyle.Render("Current version:"), cli.ValueStyle.Render(currentVersion))
|
||||||
cli.Print("%s %s/%s\n", cli.DimStyle.Render("Platform:"), runtime.GOOS, runtime.GOARCH)
|
cli.Print("%s %s/%s\n", cli.DimStyle.Render("Platform:"), runtime.GOOS, runtime.GOARCH)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ type UpdateServiceConfig struct {
|
||||||
// repository URL (e.g., "https://github.com/owner/repo") or a base URL
|
// repository URL (e.g., "https://github.com/owner/repo") or a base URL
|
||||||
// for a generic HTTP update server.
|
// for a generic HTTP update server.
|
||||||
RepoURL string
|
RepoURL string
|
||||||
// Channel specifies the release channel to track (e.g., "stable", "prerelease").
|
// Channel specifies the release channel to track (e.g., "stable", "beta", or "prerelease").
|
||||||
|
// "prerelease" is normalised to "beta" to match the GitHub release filter.
|
||||||
// This is only used for GitHub-based updates.
|
// This is only used for GitHub-based updates.
|
||||||
Channel string
|
Channel string
|
||||||
// CheckOnStartup determines the update behavior when the service starts.
|
// CheckOnStartup determines the update behavior when the service starts.
|
||||||
|
|
@ -134,5 +135,8 @@ func normaliseGitHubChannel(channel string) string {
|
||||||
if channel == "" {
|
if channel == "" {
|
||||||
return "stable"
|
return "stable"
|
||||||
}
|
}
|
||||||
|
if channel == "prerelease" {
|
||||||
|
return "beta"
|
||||||
|
}
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,15 @@ func TestNewUpdateService(t *testing.T) {
|
||||||
isGitHub: true,
|
isGitHub: true,
|
||||||
wantChannel: "beta",
|
wantChannel: "beta",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "GitHub prerelease channel maps to beta",
|
||||||
|
config: UpdateServiceConfig{
|
||||||
|
RepoURL: "https://github.com/owner/repo",
|
||||||
|
Channel: " prerelease ",
|
||||||
|
},
|
||||||
|
isGitHub: true,
|
||||||
|
wantChannel: "beta",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid GitHub URL",
|
name: "Invalid GitHub URL",
|
||||||
config: UpdateServiceConfig{
|
config: UpdateServiceConfig{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue