github.com/sagernet/sing-box@v1.9.0-rc.20/cmd/internal/build_shared/tag.go (about) 1 package build_shared 2 3 import ( 4 "github.com/sagernet/sing-box/common/badversion" 5 "github.com/sagernet/sing/common" 6 "github.com/sagernet/sing/common/shell" 7 ) 8 9 func ReadTag() (string, error) { 10 currentTag, err := shell.Exec("git", "describe", "--tags").ReadOutput() 11 if err != nil { 12 return currentTag, err 13 } 14 currentTagRev, _ := shell.Exec("git", "describe", "--tags", "--abbrev=0").ReadOutput() 15 if currentTagRev == currentTag { 16 return currentTag[1:], nil 17 } 18 shortCommit, _ := shell.Exec("git", "rev-parse", "--short", "HEAD").ReadOutput() 19 version := badversion.Parse(currentTagRev[1:]) 20 return version.String() + "-" + shortCommit, nil 21 } 22 23 func ReadTagVersion() (badversion.Version, error) { 24 currentTag := common.Must1(shell.Exec("git", "describe", "--tags").ReadOutput()) 25 currentTagRev := common.Must1(shell.Exec("git", "describe", "--tags", "--abbrev=0").ReadOutput()) 26 version := badversion.Parse(currentTagRev[1:]) 27 if currentTagRev != currentTag { 28 if version.PreReleaseIdentifier == "" { 29 version.Patch++ 30 } 31 } 32 return version, nil 33 }