Skip to content

Commit ad10221

Browse files
committed
skip version checks on prerelease versions
1 parent ba1db7a commit ad10221

2 files changed

Lines changed: 8 additions & 80 deletions

File tree

cmd/entire/cli/versioncheck/versioncheck.go

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ func parseGitHubRelease(body []byte) (string, error) {
223223
// isOutdated compares current and latest versions using semantic versioning.
224224
// Returns true if current < latest.
225225
func isOutdated(current, latest string) bool {
226-
// Strip git describe suffix (e.g., "v0.4.4-76-g230b49bf-dirty" → "v0.4.4").
227-
// git describe appends "-N-gHASH" (and optionally "-dirty") to the tag,
228-
// which semver misinterprets as a prerelease (sorting before the release).
229-
current = stripGitDescribeSuffix(current)
230-
231226
// Ensure versions have "v" prefix for semver package
232227
if !strings.HasPrefix(current, "v") {
233228
current = "v" + current
@@ -236,56 +231,16 @@ func isOutdated(current, latest string) bool {
236231
latest = "v" + latest
237232
}
238233

234+
// Skip notification for prerelease versions (development builds).
235+
// We don't publish prerelease versions, so these are development builds and shouldn't trigger update notifications.
236+
if semver.Prerelease(current) != "" {
237+
return false
238+
}
239+
239240
// semver.Compare returns -1 if current < latest
240241
return semver.Compare(current, latest) < 0
241242
}
242243

243-
// stripGitDescribeSuffix removes the git describe suffix from a version string.
244-
// "v0.4.4-76-g230b49bf-dirty" → "v0.4.4"
245-
// "v0.4.4-76-g230b49bf" → "v0.4.4"
246-
// "v0.4.4" → "v0.4.4" (no change)
247-
func stripGitDescribeSuffix(version string) string {
248-
// git describe format: <tag>-<N>-g<hash>[-dirty]
249-
// The "-g" prefix on the hash is the distinguishing marker.
250-
// Look for "-<number>-g<hex>" pattern.
251-
v := version
252-
if strings.HasSuffix(v, "-dirty") {
253-
v = strings.TrimSuffix(v, "-dirty")
254-
}
255-
// Find the last "-g<hex>" segment
256-
lastG := strings.LastIndex(v, "-g")
257-
if lastG < 0 {
258-
return version
259-
}
260-
// Verify the part after "-g" is hex characters (git hash)
261-
hash := v[lastG+2:]
262-
if len(hash) == 0 {
263-
return version
264-
}
265-
for _, c := range hash {
266-
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
267-
return version
268-
}
269-
}
270-
// Now strip the "-<N>-g<hash>" part: find the dash before the commit count
271-
prefix := v[:lastG]
272-
lastDash := strings.LastIndex(prefix, "-")
273-
if lastDash < 0 {
274-
return version
275-
}
276-
// Verify the part between the dashes is a number (commit count)
277-
count := prefix[lastDash+1:]
278-
if len(count) == 0 {
279-
return version
280-
}
281-
for _, c := range count {
282-
if c < '0' || c > '9' {
283-
return version
284-
}
285-
}
286-
return prefix[:lastDash]
287-
}
288-
289244
// updateCommand returns the appropriate update instruction based on how the binary was installed.
290245
func updateCommand() string {
291246
execPath, err := os.Executable()

cmd/entire/cli/versioncheck/versioncheck_test.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func TestIsOutdated(t *testing.T) {
3535
{"1.0.0", "v1.0.1", true, "mixed v prefix reversed"},
3636

3737
// Pre-release versions (semver uses hyphen)
38-
{"1.0.0-rc1", "1.0.0", true, "prerelease in current"},
38+
{"1.0.0-rc1", "1.0.0", false, "prerelease in current"},
3939
{"1.0.0", "1.0.1-rc1", true, "prerelease in latest is still newer"},
4040

4141
// Git describe format (should strip suffix before comparing)
4242
{"v0.4.4-76-g230b49bf-dirty", "v0.4.4", false, "git describe dirty build is not outdated"},
4343
{"v0.4.4-76-g230b49bf", "v0.4.4", false, "git describe build is not outdated"},
44-
{"v0.4.4-76-g230b49bf-dirty", "v0.4.5", true, "git describe build outdated by newer release"},
44+
{"v0.4.4-76-g230b49bf-dirty", "v0.4.5", false, "git describe build outdated by newer release"},
4545
{"v0.4.4-1-gabcdef0", "v0.4.4", false, "git describe 1 commit ahead"},
4646
{"v1.0.0-100-g1234567890ab-dirty", "v1.0.0", false, "git describe long hash dirty"},
4747
}
@@ -56,33 +56,6 @@ func TestIsOutdated(t *testing.T) {
5656
}
5757
}
5858

59-
func TestStripGitDescribeSuffix(t *testing.T) {
60-
tests := []struct {
61-
input string
62-
want string
63-
}{
64-
{"v0.4.4-76-g230b49bf-dirty", "v0.4.4"},
65-
{"v0.4.4-76-g230b49bf", "v0.4.4"},
66-
{"v0.4.4-1-gabcdef0", "v0.4.4"},
67-
{"v1.0.0-100-g1234567890ab-dirty", "v1.0.0"},
68-
{"v0.4.4", "v0.4.4"},
69-
{"1.0.0", "1.0.0"},
70-
{"v1.0.0-rc1", "v1.0.0-rc1"}, // real prerelease, not git describe
71-
{"v1.0.0-beta.1", "v1.0.0-beta.1"}, // real prerelease with dots
72-
{"v1.0.0-dirty", "v1.0.0-dirty"}, // just dirty without commit info
73-
{"v1.0.0-1-gXYZ", "v1.0.0-1-gXYZ"}, // non-hex hash, keep as-is
74-
}
75-
76-
for _, tt := range tests {
77-
t.Run(tt.input, func(t *testing.T) {
78-
got := stripGitDescribeSuffix(tt.input)
79-
if got != tt.want {
80-
t.Errorf("stripGitDescribeSuffix(%q) = %q, want %q", tt.input, got, tt.want)
81-
}
82-
})
83-
}
84-
}
85-
8659
func TestCacheReadWrite(t *testing.T) {
8760
// Create a temporary directory for the test
8861
tmpDir := t.TempDir()

0 commit comments

Comments
 (0)