chore(release): 版本发布 - 准备 v1.5.7.1 预览版

This commit is contained in:
ddCat
2026-09-22 09:23:18 +08:00
parent e0e6be450b
commit b2a1bcc8d9
9 changed files with 55 additions and 32 deletions

View File

@@ -6,8 +6,8 @@ import (
)
type versionPart struct {
major, minor, patch int
pre []string
core []int
pre []string
}
func IsReleaseVersion(raw string) bool {
@@ -32,11 +32,18 @@ func CompareVersions(left, right string) int {
}
func compareParsedVersions(a, b versionPart) int {
for _, pair := range [][2]int{{a.major, b.major}, {a.minor, b.minor}, {a.patch, b.patch}} {
if pair[0] < pair[1] {
for index := 0; index < len(a.core) || index < len(b.core); index++ {
left, right := 0, 0
if index < len(a.core) {
left = a.core[index]
}
if index < len(b.core) {
right = b.core[index]
}
if left < right {
return -1
}
if pair[0] > pair[1] {
if left > right {
return 1
}
}
@@ -78,16 +85,18 @@ func parseVersion(raw string) (versionPart, bool) {
value = strings.SplitN(value, "+", 2)[0]
parts := strings.SplitN(value, "-", 2)
core := strings.Split(parts[0], ".")
if len(core) != 3 {
if len(core) < 3 {
return versionPart{}, false
}
major, err1 := strconv.Atoi(core[0])
minor, err2 := strconv.Atoi(core[1])
patch, err3 := strconv.Atoi(core[2])
if err1 != nil || err2 != nil || err3 != nil {
return versionPart{}, false
coreNumbers := make([]int, len(core))
for index, value := range core {
number, err := strconv.Atoi(value)
if err != nil {
return versionPart{}, false
}
coreNumbers[index] = number
}
parsed := versionPart{major: major, minor: minor, patch: patch}
parsed := versionPart{core: coreNumbers}
if len(parts) == 2 && parts[1] != "" {
parsed.pre = strings.FieldsFunc(parts[1], func(r rune) bool { return r == '.' || r == '-' })
}

View File

@@ -11,6 +11,8 @@ func TestCompareVersions(t *testing.T) {
{"v1.2.0-preview.10", "v1.2.0-preview.3", 1},
{"v1.2.0-preview.3", "v1.2.0", -1},
{"v1.2.1", "v1.2.0", 1},
{"v1.5.7.1", "v1.5.7", 1},
{"v1.5.7.1", "v1.5.7.2", -1},
{"v1.2.0", "v1.2.0", 0},
{"vsha-5509b17", "v1.5.0", -1},
{"sha-5509b17", "v1.5.0", -1},