From ea3731162b840f5c945fcd2847a89c8a0d43a572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 30 Aug 2023 17:35:40 +0800 Subject: [PATCH] Update Makefile --- Makefile | 10 +++++++++- cmd/internal/build_shared/tag.go | 16 ++++++++++------ cmd/internal/update_android_version/main.go | 10 +++++----- cmd/internal/update_apple_version/main.go | 13 ++++++++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 5533ed90..36e11345 100644 --- a/Makefile +++ b/Makefile @@ -69,13 +69,17 @@ release_install: go install -v github.com/goreleaser/goreleaser@latest go install -v github.com/tcnksm/ghr@latest -upload_android: +update_android_version: go run ./cmd/internal/update_android_version + +upload_android: cd ../sing-box-for-android && ./gradlew :app:assembleRelease mkdir dist/release_android cp ../sing-box-for-android/app/build/outputs/apk/release/*.apk dist/release_android ghr --replace --draft --prerelease -p 3 "v${VERSION}" dist/release_android +release_android: lib_android update_android_version upload_android + publish_android: cd ../sing-box-for-android && ./gradlew :app:appCenterAssembleAndUploadRelease @@ -140,6 +144,10 @@ update_apple_version: release_apple: update_apple_version release_ios release_macos release_macos_independent release_tvos +build_apple_beta: update_apple_version build_ios build_macos build_tvos + +upload_apple_beta: upload_ios_app_store upload_macos_app_store upload_tvos_app_store + test: @go test -v ./... && \ cd test && \ diff --git a/cmd/internal/build_shared/tag.go b/cmd/internal/build_shared/tag.go index 089713bc..8a5840ac 100644 --- a/cmd/internal/build_shared/tag.go +++ b/cmd/internal/build_shared/tag.go @@ -2,6 +2,7 @@ package build_shared import ( "github.com/sagernet/sing-box/common/badversion" + "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/shell" ) @@ -22,11 +23,14 @@ func ReadTag() (string, error) { return version.String() + "-" + shortCommit, nil } -func ReadTagVersion() (string, error) { - currentTagRev, err := shell.Exec("git", "describe", "--tags", "--abbrev=0").ReadOutput() - if err != nil { - return "", err - } +func ReadTagVersion() (badversion.Version, error) { + currentTag := common.Must1(shell.Exec("git", "describe", "--tags").ReadOutput()) + currentTagRev := common.Must1(shell.Exec("git", "describe", "--tags", "--abbrev=0").ReadOutput()) version := badversion.Parse(currentTagRev[1:]) - return version.VersionString(), nil + if currentTagRev != currentTag { + if version.PreReleaseIdentifier == "" { + version.Patch++ + } + } + return version, nil } diff --git a/cmd/internal/update_android_version/main.go b/cmd/internal/update_android_version/main.go index b93e2ff8..ce380b98 100644 --- a/cmd/internal/update_android_version/main.go +++ b/cmd/internal/update_android_version/main.go @@ -12,7 +12,7 @@ import ( ) func main() { - newTag := common.Must1(build_shared.ReadTag()) + newVersion := common.Must1(build_shared.ReadTagVersion()) androidPath, err := filepath.Abs("../sing-box-for-android") if err != nil { log.Fatal(err) @@ -25,12 +25,12 @@ func main() { } for _, propPair := range propsList { if propPair[0] == "VERSION_NAME" { - if propPair[1] == newTag { + if propPair[1] == newVersion.String() { log.Info("version not changed") return } - propPair[1] = newTag - log.Info("updated version to ", newTag) + propPair[1] = newVersion.String() + log.Info("updated version to ", newVersion.String()) } } for _, propPair := range propsList { @@ -40,7 +40,7 @@ func main() { propPair[1] = strconv.Itoa(int(versionCode + 1)) log.Info("updated version code to ", propPair[1]) case "RELEASE_NOTES": - propPair[1] = "sing-box " + newTag + propPair[1] = "sing-box " + newVersion.String() } } var newProps []string diff --git a/cmd/internal/update_apple_version/main.go b/cmd/internal/update_apple_version/main.go index b77f02cf..dba81f83 100644 --- a/cmd/internal/update_apple_version/main.go +++ b/cmd/internal/update_apple_version/main.go @@ -15,7 +15,6 @@ import ( func main() { newVersion := common.Must1(build_shared.ReadTagVersion()) - newTag := common.Must1(build_shared.ReadTag()) applePath, err := filepath.Abs("../sing-box-for-apple") if err != nil { log.Fatal(err) @@ -27,10 +26,10 @@ func main() { common.Must(decoder.Decode(&project)) objectsMap := project["objects"].(map[string]any) projectContent := string(common.Must1(os.ReadFile("sing-box.xcodeproj/project.pbxproj"))) - newContent, updated0 := findAndReplace(objectsMap, projectContent, []string{"io.nekohasekai.sfa"}, newVersion) - newContent, updated1 := findAndReplace(objectsMap, newContent, []string{"io.nekohasekai.sfa.independent", "io.nekohasekai.sfa.system"}, newTag) + newContent, updated0 := findAndReplace(objectsMap, projectContent, []string{"io.nekohasekai.sfa"}, newVersion.VersionString()) + newContent, updated1 := findAndReplace(objectsMap, newContent, []string{"io.nekohasekai.sfa.independent", "io.nekohasekai.sfa.system"}, newVersion.String()) if updated0 || updated1 { - log.Info("updated version to ", newTag) + log.Info("updated version to ", newVersion.VersionString()) common.Must(os.WriteFile("sing-box.xcodeproj/project.pbxproj.bak", []byte(projectContent), 0o644)) common.Must(os.WriteFile("sing-box.xcodeproj/project.pbxproj", []byte(newContent), 0o644)) } else { @@ -44,6 +43,10 @@ func findAndReplace(objectsMap map[string]any, projectContent string, bundleIDLi for _, objectKey := range objectKeyList { matchRegexp := common.Must1(regexp.Compile(objectKey + ".*= \\{")) indexes := matchRegexp.FindStringIndex(projectContent) + if len(indexes) < 2 { + println(projectContent) + log.Fatal("failed to find object key ", objectKey, ": ", strings.Index(projectContent, objectKey)) + } indexStart := indexes[1] indexEnd := indexStart + strings.Index(projectContent[indexStart:], "}") versionStart := indexStart + strings.Index(projectContent[indexStart:indexEnd], "MARKETING_VERSION = ") + 20 @@ -53,7 +56,7 @@ func findAndReplace(objectsMap map[string]any, projectContent string, bundleIDLi continue } updated = true - projectContent = projectContent[indexStart:versionStart] + newVersion + projectContent[versionEnd:indexEnd] + projectContent = projectContent[:versionStart] + newVersion + projectContent[versionEnd:] } return projectContent, updated }