sing-box/cmd/internal/update_android_version/main.go

65 lines
1.7 KiB
Go
Raw Normal View History

2023-08-27 13:14:10 +00:00
package main
import (
"os"
"path/filepath"
2024-02-16 05:28:58 +00:00
"runtime"
2023-08-27 13:14:10 +00:00
"strconv"
"strings"
"github.com/sagernet/sing-box/cmd/internal/build_shared"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing/common"
)
func main() {
2023-08-30 09:35:40 +00:00
newVersion := common.Must1(build_shared.ReadTagVersion())
2023-08-27 13:14:10 +00:00
androidPath, err := filepath.Abs("../sing-box-for-android")
if err != nil {
log.Fatal(err)
}
common.Must(os.Chdir(androidPath))
2024-02-16 05:28:58 +00:00
localProps := common.Must1(os.ReadFile("version.properties"))
2023-08-27 13:14:10 +00:00
var propsList [][]string
for _, propLine := range strings.Split(string(localProps), "\n") {
propsList = append(propsList, strings.Split(propLine, "="))
}
2024-02-16 05:28:58 +00:00
var (
versionUpdated bool
goVersionUpdated bool
)
2023-08-27 13:14:10 +00:00
for _, propPair := range propsList {
2024-02-16 05:28:58 +00:00
switch propPair[0] {
case "VERSION_NAME":
if propPair[1] != newVersion.String() {
versionUpdated = true
propPair[1] = newVersion.String()
log.Info("updated version to ", newVersion.String())
}
case "GO_VERSION":
if propPair[1] != runtime.Version() {
goVersionUpdated = true
propPair[1] = runtime.Version()
log.Info("updated Go version to ", runtime.Version())
2023-08-27 13:14:10 +00:00
}
}
}
2024-02-16 05:28:58 +00:00
if !(versionUpdated || goVersionUpdated) {
log.Info("version not changed")
return
}
2023-08-27 13:14:10 +00:00
for _, propPair := range propsList {
switch propPair[0] {
case "VERSION_CODE":
versionCode := common.Must1(strconv.ParseInt(propPair[1], 10, 64))
propPair[1] = strconv.Itoa(int(versionCode + 1))
log.Info("updated version code to ", propPair[1])
}
}
var newProps []string
for _, propPair := range propsList {
newProps = append(newProps, strings.Join(propPair, "="))
}
2024-02-16 05:28:58 +00:00
common.Must(os.WriteFile("version.properties", []byte(strings.Join(newProps, "\n")), 0o644))
2023-08-27 13:14:10 +00:00
}