From 2675aff98afb2ba46e15339d400915c20e599d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 7 Aug 2023 20:08:11 +0800 Subject: [PATCH] Fix tag detect --- cmd/internal/build_shared/tag.go | 11 +++++++++-- common/badversion/version.go | 20 +++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/internal/build_shared/tag.go b/cmd/internal/build_shared/tag.go index 9a376385..b1fecab4 100644 --- a/cmd/internal/build_shared/tag.go +++ b/cmd/internal/build_shared/tag.go @@ -1,6 +1,9 @@ package build_shared -import "github.com/sagernet/sing/common/shell" +import ( + "github.com/sagernet/sing-box/common/badversion" + "github.com/sagernet/sing/common/shell" +) func ReadTag() (string, error) { currentTag, err := shell.Exec("git", "describe", "--tags").ReadOutput() @@ -12,5 +15,9 @@ func ReadTag() (string, error) { return currentTag[1:], nil } shortCommit, _ := shell.Exec("git", "rev-parse", "--short", "HEAD").ReadOutput() - return currentTagRev[1:] + "-" + shortCommit, nil + version := badversion.Parse(currentTagRev[1:]) + if version.PreReleaseIdentifier == "" { + version.Patch++ + } + return version.String() + "-" + shortCommit, nil } diff --git a/common/badversion/version.go b/common/badversion/version.go index faf292fe..23168eca 100644 --- a/common/badversion/version.go +++ b/common/badversion/version.go @@ -11,6 +11,7 @@ type Version struct { Major int Minor int Patch int + Commit string PreReleaseIdentifier string PreReleaseVersion int } @@ -37,16 +38,21 @@ func (v Version) After(anotherVersion Version) bool { return false } if v.PreReleaseIdentifier != "" && anotherVersion.PreReleaseIdentifier != "" { - if v.PreReleaseIdentifier == "beta" && anotherVersion.PreReleaseIdentifier == "alpha" { + if v.PreReleaseIdentifier == anotherVersion.PreReleaseIdentifier { + if v.PreReleaseVersion > anotherVersion.PreReleaseVersion { + return true + } else if v.PreReleaseVersion < anotherVersion.PreReleaseVersion { + return false + } + } else if v.PreReleaseIdentifier == "rc" && anotherVersion.PreReleaseIdentifier == "beta" { + return true + } else if v.PreReleaseIdentifier == "beta" && anotherVersion.PreReleaseIdentifier == "rc" { + return false + } else if v.PreReleaseIdentifier == "beta" && anotherVersion.PreReleaseIdentifier == "alpha" { return true } else if v.PreReleaseIdentifier == "alpha" && anotherVersion.PreReleaseIdentifier == "beta" { return false } - if v.PreReleaseVersion > anotherVersion.PreReleaseVersion { - return true - } else if v.PreReleaseVersion < anotherVersion.PreReleaseVersion { - return false - } } return false } @@ -95,7 +101,7 @@ func Parse(versionName string) (version Version) { version.PreReleaseIdentifier = "beta" version.PreReleaseVersion, _ = strconv.Atoi(identifier[4:]) } else { - version.PreReleaseIdentifier = identifier + version.Commit = identifier } } }