github.com/sagernet/sing-box@v1.9.0-rc.20/cmd/internal/update_android_version/main.go (about) 1 package main 2 3 import ( 4 "os" 5 "path/filepath" 6 "runtime" 7 "strconv" 8 "strings" 9 10 "github.com/sagernet/sing-box/cmd/internal/build_shared" 11 "github.com/sagernet/sing-box/log" 12 "github.com/sagernet/sing/common" 13 ) 14 15 func main() { 16 newVersion := common.Must1(build_shared.ReadTagVersion()) 17 androidPath, err := filepath.Abs("../sing-box-for-android") 18 if err != nil { 19 log.Fatal(err) 20 } 21 common.Must(os.Chdir(androidPath)) 22 localProps := common.Must1(os.ReadFile("version.properties")) 23 var propsList [][]string 24 for _, propLine := range strings.Split(string(localProps), "\n") { 25 propsList = append(propsList, strings.Split(propLine, "=")) 26 } 27 var ( 28 versionUpdated bool 29 goVersionUpdated bool 30 ) 31 for _, propPair := range propsList { 32 switch propPair[0] { 33 case "VERSION_NAME": 34 if propPair[1] != newVersion.String() { 35 versionUpdated = true 36 propPair[1] = newVersion.String() 37 log.Info("updated version to ", newVersion.String()) 38 } 39 case "GO_VERSION": 40 if propPair[1] != runtime.Version() { 41 goVersionUpdated = true 42 propPair[1] = runtime.Version() 43 log.Info("updated Go version to ", runtime.Version()) 44 } 45 } 46 } 47 if !(versionUpdated || goVersionUpdated) { 48 log.Info("version not changed") 49 return 50 } 51 for _, propPair := range propsList { 52 switch propPair[0] { 53 case "VERSION_CODE": 54 versionCode := common.Must1(strconv.ParseInt(propPair[1], 10, 64)) 55 propPair[1] = strconv.Itoa(int(versionCode + 1)) 56 log.Info("updated version code to ", propPair[1]) 57 } 58 } 59 var newProps []string 60 for _, propPair := range propsList { 61 newProps = append(newProps, strings.Join(propPair, "=")) 62 } 63 common.Must(os.WriteFile("version.properties", []byte(strings.Join(newProps, "\n")), 0o644)) 64 }