main.go 1.9 KB

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