From 3bb60ee188dc2e16bc2cb5e8b0eeb374450c7c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Dessureault?= <6100619+JeffDess@users.noreply.github.com> Date: Mon, 2 Feb 2026 06:55:02 -0500 Subject: [PATCH] Check for version update only if current version is semver Previously only checked for "dev" or empty, but some builds could show other valid versions, such a Nix which will show "unstable" as it builds the latest commit instead of a version. --- cmd/utilities/version.go | 13 +++++++++---- cmd/utilities/version_test.go | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/utilities/version.go b/cmd/utilities/version.go index 16a1b0c..3c8920e 100644 --- a/cmd/utilities/version.go +++ b/cmd/utilities/version.go @@ -17,6 +17,8 @@ var ( Date = "unknown" ) +var releaseVersionRegex = regexp.MustCompile(`^v?\d+\.\d+\.\d+(-[\w.]+)?$`) + func VersionCmd() *cobra.Command { cmd := &cobra.Command{ Use: "version", @@ -54,8 +56,7 @@ func GetFormattedDate(inputDate string) string { func GetChangelogUrl(version string) string { path := "https://github.com/DylanDevelops/tmpo" - r := regexp.MustCompile(`^v?\d+\.\d+\.\d+(-[\w.]+)?$`) - if !r.MatchString(version) { + if !isReleaseVersion(version) { return fmt.Sprintf("%s/releases/latest", path) } @@ -63,8 +64,8 @@ func GetChangelogUrl(version string) string { } func checkForUpdates() { - // Only check if we have a valid version (not "dev" or empty) - if Version == "" || Version == "dev" { + // Only check for released semantic versions. + if !isReleaseVersion(Version) { return } @@ -79,3 +80,7 @@ func checkForUpdates() { fmt.Printf("%s\n\n", ui.Muted(updateInfo.UpdateURL)) } } + +func isReleaseVersion(version string) bool { + return releaseVersionRegex.MatchString(version) +} diff --git a/cmd/utilities/version_test.go b/cmd/utilities/version_test.go index b340e32..6759cf6 100644 --- a/cmd/utilities/version_test.go +++ b/cmd/utilities/version_test.go @@ -78,6 +78,11 @@ func TestGetChangelogUrl(t *testing.T) { version: "dev", expected: "https://github.com/DylanDevelops/tmpo/releases/latest", }, + { + name: "unstable version returns latest", + version: "unstable", + expected: "https://github.com/DylanDevelops/tmpo/releases/latest", + }, { name: "empty version returns latest", version: "",