fix(34): CR-01 never move a pseudo-version install back to its base release
plugin:update dropped a go.mod require that was not a strict vX.Y.Z and treated it as v0.0.0, so a module at a commit after v0.4.0 (v0.4.1-0.<ts>-<hash>) was moved back to v0.4.0. kiosk.Newer now places a release against a release, a git describe string or a pseudo-version (by the tag it builds on, in Go's version order); plugin:update and the admin Plugins screen badge share it. A pseudo-version with no tag before its commit is left alone with a note naming go get <module>@<tag>.
This commit is contained in:
@@ -9,6 +9,10 @@ var (
|
||||
validVersionRe = regexp.MustCompile(`^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
|
||||
describeRe = regexp.MustCompile(`^(v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))(?:-[0-9]+-g[0-9a-f]+)?$`)
|
||||
pseudoBaseRe = regexp.MustCompile(`^(v[0-9]+\.[0-9]+\.[0-9]+)-`)
|
||||
// pseudoNoBaseRe is a pseudo-version with no tag before its commit:
|
||||
// vX.0.0-<timestamp>-<hash>, without the "0." or "<pre>.0." of one
|
||||
// that builds on a release or a pre-release.
|
||||
pseudoNoBaseRe = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+-[0-9]{14}-[0-9a-f]{12}$`)
|
||||
)
|
||||
|
||||
// ValidVersion reports whether v is a release version in the strict form
|
||||
@@ -65,6 +69,47 @@ func BaseVersion(describe string) string {
|
||||
return m[1]
|
||||
}
|
||||
|
||||
// Newer reports whether release is an upgrade for a plugin installed at
|
||||
// installed, so moving to it never goes back. installed may be a release
|
||||
// vX.Y.Z (newer: above it), a git describe string vX.Y.Z-N-g<hash>, a
|
||||
// commit after vX.Y.Z (newer: above vX.Y.Z), or a Go pseudo-version, a
|
||||
// commit after the tag it builds on: vX.Y.(Z+1)-0.<timestamp>-<hash>
|
||||
// after the release vX.Y.Z, vX.Y.Z-<pre>.0.<timestamp>-<hash> after the
|
||||
// pre-release vX.Y.Z-<pre>; newer is at or above vX.Y.(Z+1) and vX.Y.Z,
|
||||
// Go's own version order. Nothing is newer than an installed version
|
||||
// Comparable refuses (a pseudo-version with no tag before its commit, a
|
||||
// bare commit hash, a pre-release, ""). release must be a valid release.
|
||||
func Newer(release, installed string) bool {
|
||||
if !ValidVersion(release) {
|
||||
return false
|
||||
}
|
||||
if base := BaseVersion(installed); base != "" {
|
||||
return CompareVersions(release, base) > 0
|
||||
}
|
||||
if !isPseudoVersion(installed) || pseudoNoBaseRe.MatchString(installed) {
|
||||
return false
|
||||
}
|
||||
core := pseudoBaseRe.FindStringSubmatch(installed)
|
||||
if core == nil || !ValidVersion(core[1]) {
|
||||
return false
|
||||
}
|
||||
return CompareVersions(release, core[1]) >= 0
|
||||
}
|
||||
|
||||
// Comparable reports whether Newer can place installed among releases: a
|
||||
// release, a git describe string, or a pseudo-version that builds on a
|
||||
// release or a pre-release.
|
||||
func Comparable(installed string) bool {
|
||||
if BaseVersion(installed) != "" {
|
||||
return true
|
||||
}
|
||||
if !isPseudoVersion(installed) || pseudoNoBaseRe.MatchString(installed) {
|
||||
return false
|
||||
}
|
||||
core := pseudoBaseRe.FindStringSubmatch(installed)
|
||||
return core != nil && ValidVersion(core[1])
|
||||
}
|
||||
|
||||
// Satisfies reports whether the release have meets the minimum min. An
|
||||
// empty minimum is always met. A pseudo-version minimum such as
|
||||
// vX.Y.Z-0.<timestamp>-<hash> sorts just below vX.Y.Z, so it is met by
|
||||
|
||||
Reference in New Issue
Block a user