main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strconv"
  6. "strings"
  7. "github.com/sagernet/sing-box/cmd/internal/build_shared"
  8. "github.com/sagernet/sing-box/log"
  9. "github.com/sagernet/sing/common"
  10. )
  11. func main() {
  12. newVersion := common.Must1(build_shared.ReadTagVersion())
  13. androidPath, err := filepath.Abs("../sing-box-for-android")
  14. if err != nil {
  15. log.Fatal(err)
  16. }
  17. common.Must(os.Chdir(androidPath))
  18. localProps := common.Must1(os.ReadFile("local.properties"))
  19. var propsList [][]string
  20. for _, propLine := range strings.Split(string(localProps), "\n") {
  21. propsList = append(propsList, strings.Split(propLine, "="))
  22. }
  23. for _, propPair := range propsList {
  24. if propPair[0] == "VERSION_NAME" {
  25. if propPair[1] == newVersion.String() {
  26. log.Info("version not changed")
  27. return
  28. }
  29. propPair[1] = newVersion.String()
  30. log.Info("updated version to ", newVersion.String())
  31. }
  32. }
  33. for _, propPair := range propsList {
  34. switch propPair[0] {
  35. case "VERSION_CODE":
  36. versionCode := common.Must1(strconv.ParseInt(propPair[1], 10, 64))
  37. propPair[1] = strconv.Itoa(int(versionCode + 1))
  38. log.Info("updated version code to ", propPair[1])
  39. case "RELEASE_NOTES":
  40. propPair[1] = "sing-box " + newVersion.String()
  41. }
  42. }
  43. var newProps []string
  44. for _, propPair := range propsList {
  45. newProps = append(newProps, strings.Join(propPair, "="))
  46. }
  47. common.Must(os.WriteFile("local.properties", []byte(strings.Join(newProps, "\n")), 0o644))
  48. }