release: Update macOS project version atomically

This commit is contained in:
世界 2024-12-12 09:34:57 +08:00
parent 5cdf5c1d9e
commit dd9de694f8
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 167 additions and 62 deletions

View file

@ -0,0 +1,108 @@
package main
import (
"context"
"os"
"strconv"
"time"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
"github.com/cidertool/asc-go/asc"
)
func main() {
switch os.Args[1] {
case "publish_testflight":
err := publishTestflight(context.Background())
if err != nil {
log.Fatal(err)
}
case "next_macos_project_version":
err := fetchMacOSVersion(context.Background())
if err != nil {
log.Fatal(err)
}
default:
log.Fatal("unknown action: ", os.Args[1])
}
}
const (
appID = "6673731168"
groupID = "5c5f3b78-b7a0-40c0-bcad-e6ef87bbefda"
)
func createClient() *asc.Client {
privateKey, err := os.ReadFile(os.Getenv("ASC_KEY_PATH"))
if err != nil {
log.Fatal(err)
}
tokenConfig, err := asc.NewTokenConfig(os.Getenv("ASC_KEY_ID"), os.Getenv("ASC_KEY_ISSUER_ID"), time.Minute, privateKey)
if err != nil {
log.Fatal(err)
}
return asc.NewClient(tokenConfig.Client())
}
func publishTestflight(ctx context.Context) error {
client := createClient()
var buildsToPublish []asc.Build
for _, platform := range []string{
"IOS",
"MAC_OS",
"TV_OS",
} {
builds, _, err := client.Builds.ListBuilds(ctx, &asc.ListBuildsQuery{
FilterApp: []string{appID},
FilterPreReleaseVersionPlatform: []string{platform},
})
if err != nil {
return err
}
buildsToPublish = append(buildsToPublish, builds.Data[0])
}
_, err := client.TestFlight.AddBuildsToBetaGroup(ctx, groupID, common.Map(buildsToPublish, func(it asc.Build) string {
return it.ID
}))
if err != nil {
return err
}
return nil
}
func fetchMacOSVersion(ctx context.Context) error {
client := createClient()
versions, _, err := client.Apps.ListAppStoreVersionsForApp(ctx, appID, &asc.ListAppStoreVersionsQuery{
FilterPlatform: []string{"MAC_OS"},
})
if err != nil {
return err
}
var versionID string
findVersion:
for _, version := range versions.Data {
switch *version.Attributes.AppStoreState {
case asc.AppStoreVersionStateReadyForSale,
asc.AppStoreVersionStatePendingDeveloperRelease:
versionID = version.ID
break findVersion
}
}
if versionID == "" {
return E.New("no version found")
}
latestBuild, _, err := client.Builds.GetBuildForAppStoreVersion(ctx, versionID, &asc.GetBuildForAppStoreVersionQuery{})
if err != nil {
return err
}
versionInt, err := strconv.Atoi(*latestBuild.Data.Attributes.Version)
if err != nil {
return E.Cause(err, "parse version code")
}
os.Stdout.WriteString(F.ToString(versionInt+1, "\n"))
return nil
}

View file

@ -18,11 +18,13 @@ import (
var (
debugEnabled bool
target string
platform string
)
func init() {
flag.BoolVar(&debugEnabled, "debug", false, "enable debug")
flag.StringVar(&target, "target", "android", "target platform")
flag.StringVar(&platform, "platform", "", "specify platform")
}
func main() {
@ -33,8 +35,8 @@ func main() {
switch target {
case "android":
buildAndroid()
case "ios":
buildiOS()
case "apple":
buildApple()
}
}
@ -81,7 +83,9 @@ func buildAndroid() {
}
var bindTarget string
if debugEnabled {
if platform != "" {
bindTarget = platform
} else if debugEnabled {
bindTarget = "android/arm64"
} else {
bindTarget = "android"
@ -129,12 +133,14 @@ func buildAndroid() {
}
}
func buildiOS() {
func buildApple() {
var bindTarget string
if debugEnabled {
if platform != "" {
bindTarget = platform
} else if debugEnabled {
bindTarget = "ios"
} else {
bindTarget = "ios,iossimulator,tvos,tvossimulator,macos"
bindTarget = "ios,tvos,macos"
}
args := []string{