From 5bd4fe06e078f799181ecaa45e8d44c5dce93866 Mon Sep 17 00:00:00 2001 From: chaZz Date: Tue, 25 Aug 2026 16:33:49 +0200 Subject: [PATCH] fix: stop showing an update notice on the latest release newerVersion compares the raw strings, so any difference reports an update. The latest version comes from the GitHub API tag_name and keeps its leading "v", while release binaries are built with -X cmd.Version={{.Version}}, which goreleaser expands without that prefix. On v5.3.0 the comparison is therefore "v5.3.0" != "5.3.0" and the UI advertises the very version the user is already running, on every release build. Trim the prefix on both sides before comparing. Dev builds are unaffected: Check still short-circuits on "v0.0.0" before reaching this comparison. The existing tests missed this because they pass a current version that keeps the "v", which release binaries never do. Co-Authored-By: Claude Opus 5 (1M context) --- internal/updater/updater.go | 7 +++++-- internal/updater/updater_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/updater/updater.go b/internal/updater/updater.go index e009fcf..a712fa7 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -3,6 +3,7 @@ package updater import ( "encoding/json" "net/http" + "strings" "time" "github.com/achannarasappa/ticker/v5/internal/cache" @@ -45,9 +46,11 @@ func Check(currentVersion, releasesURL, cacheFilePath string, fs afero.Fs) strin } // newerVersion returns latest when it differs from currentVersion, otherwise an -// empty string. +// empty string. The leading "v" is ignored on both sides: release binaries are +// built with a version stripped of that prefix while the GitHub tag keeps it, +// so comparing the raw strings would report an update on every release. func newerVersion(latest, currentVersion string) string { - if latest != currentVersion { + if strings.TrimPrefix(latest, "v") != strings.TrimPrefix(currentVersion, "v") { return latest } diff --git a/internal/updater/updater_test.go b/internal/updater/updater_test.go index fa8b033..3877faf 100644 --- a/internal/updater/updater_test.go +++ b/internal/updater/updater_test.go @@ -2,6 +2,7 @@ package updater_test import ( "net/http" + "strings" "time" . "github.com/onsi/ginkgo/v2" @@ -116,4 +117,23 @@ var _ = Describe("Check", func() { Expect(output).To(BeEmpty()) }) }) + + When("the current version is a release build without the v prefix", func() { + // Release binaries are built with the version stripped of its leading + // "v" while the GitHub tag keeps it, so the two must still compare equal. + It("should return empty when the latest version only differs by that prefix", func() { + server.SetHandler(0, + ghttp.CombineHandlers( + ghttp.RespondWithJSONEncoded(http.StatusOK, map[string]string{"tag_name": currentVersion}), + ), + ) + output := updater.Check(strings.TrimPrefix(currentVersion, "v"), server.URL()+"/releases/latest", cacheFilePath, fs) + Expect(output).To(BeEmpty()) + }) + + It("should still return the latest version when a newer one is available", func() { + output := updater.Check(strings.TrimPrefix(currentVersion, "v"), server.URL()+"/releases/latest", cacheFilePath, fs) + Expect(output).To(Equal(latestVersion)) + }) + }) })