@@ -54,20 +54,20 @@ const (
5454 groupID = "5c5f3b78-b7a0-40c0-bcad-e6ef87bbefda"
5555)
5656
57- func createClient () * Client {
57+ func createClient (expireDuration time. Duration ) * Client {
5858 privateKey , err := os .ReadFile (os .Getenv ("ASC_KEY_PATH" ))
5959 if err != nil {
6060 log .Fatal (err )
6161 }
62- tokenConfig , err := asc .NewTokenConfig (os .Getenv ("ASC_KEY_ID" ), os .Getenv ("ASC_KEY_ISSUER_ID" ), time . Minute , privateKey )
62+ tokenConfig , err := asc .NewTokenConfig (os .Getenv ("ASC_KEY_ID" ), os .Getenv ("ASC_KEY_ISSUER_ID" ), expireDuration , privateKey )
6363 if err != nil {
6464 log .Fatal (err )
6565 }
6666 return & Client {asc .NewClient (tokenConfig .Client ())}
6767}
6868
6969func fetchMacOSVersion (ctx context.Context ) error {
70- client := createClient ()
70+ client := createClient (time . Minute )
7171 versions , _ , err := client .Apps .ListAppStoreVersionsForApp (ctx , appID , & asc.ListAppStoreVersionsQuery {
7272 FilterPlatform : []string {"MAC_OS" },
7373 })
@@ -105,71 +105,101 @@ func publishTestflight(ctx context.Context) error {
105105 return err
106106 }
107107 tag := tagVersion .VersionString ()
108- client := createClient ()
108+ client := createClient (10 * time . Minute )
109109
110+ log .Info (tag , " list build IDs" )
110111 buildIDsResponse , _ , err := client .TestFlight .ListBuildIDsForBetaGroup (ctx , groupID , nil )
111112 if err != nil {
112113 return err
113114 }
114- buildIDS := common .Map (buildIDsResponse .Data , func (it asc.RelationshipData ) string {
115+ buildIDs := common .Map (buildIDsResponse .Data , func (it asc.RelationshipData ) string {
115116 return it .ID
116117 })
117- for _ , platform := range []asc.Platform {
118- asc .PlatformIOS ,
119- asc .PlatformMACOS ,
120- asc .PlatformTVOS ,
121- } {
122- log .Info (string (platform ), " list builds" )
123- builds , _ , err := client .Builds .ListBuilds (ctx , & asc.ListBuildsQuery {
124- FilterApp : []string {appID },
125- FilterPreReleaseVersionPlatform : []string {string (platform )},
126- })
127- if err != nil {
128- return err
129- }
130- log .Info (string (platform ), " " , tag , " list localizations" )
131- localizations , _ , err := client .TestFlight .ListBetaBuildLocalizationsForBuild (ctx , builds .Data [0 ].ID , nil )
132- if err != nil {
133- return err
118+ var platforms []asc.Platform
119+ if len (os .Args ) == 3 {
120+ switch os .Args [2 ] {
121+ case "ios" :
122+ platforms = []asc.Platform {asc .PlatformIOS }
123+ case "macos" :
124+ platforms = []asc.Platform {asc .PlatformMACOS }
125+ case "tvos" :
126+ platforms = []asc.Platform {asc .PlatformTVOS }
127+ default :
128+ return E .New ("unknown platform: " , os .Args [2 ])
134129 }
135- localization := common . Find ( localizations . Data , func ( it asc. BetaBuildLocalization ) bool {
136- return * it . Attributes . Locale == "en-US"
137- })
138- if localization . ID == "" {
139- log . Fatal ( string ( platform ), " " , tag , " no en-US localization found" )
130+ } else {
131+ platforms = []asc. Platform {
132+ asc . PlatformIOS ,
133+ asc . PlatformMACOS ,
134+ asc . PlatformTVOS ,
140135 }
141- if localization .Attributes == nil || localization .Attributes .WhatsNew == nil || * localization .Attributes .WhatsNew == "" {
142- log .Info (string (platform ), " " , tag , " update localization" )
143- _ , _ , err = client .TestFlight .UpdateBetaBuildLocalization (ctx , localization .ID , common .Ptr (
144- F .ToString ("sing-box " , tag ),
145- ))
136+ }
137+ for _ , platform := range platforms {
138+ log .Info (string (platform ), " list builds" )
139+ for {
140+ builds , _ , err := client .Builds .ListBuilds (ctx , & asc.ListBuildsQuery {
141+ FilterApp : []string {appID },
142+ FilterPreReleaseVersionPlatform : []string {string (platform )},
143+ })
146144 if err != nil {
147145 return err
148146 }
149- }
150- if ! common .Contains (buildIDS , builds .Data [0 ].ID ) {
151- log .Info (string (platform ), " " , tag , " publish" )
152- _ , err = client .TestFlight .AddBuildsToBetaGroup (ctx , groupID , []string {builds .Data [0 ].ID })
147+ build := builds .Data [0 ]
148+ if common .Contains (buildIDs , build .ID ) || time .Since (build .Attributes .UploadedDate .Time ) > 5 * time .Minute {
149+ log .Info (string (platform ), " " , tag , " waiting for process" )
150+ time .Sleep (15 * time .Second )
151+ continue
152+ }
153+ if * build .Attributes .ProcessingState != "VALID" {
154+ log .Info (string (platform ), " " , tag , " waiting for process: " , * build .Attributes .ProcessingState )
155+ time .Sleep (15 * time .Second )
156+ continue
157+ }
158+ log .Info (string (platform ), " " , tag , " list localizations" )
159+ localizations , _ , err := client .TestFlight .ListBetaBuildLocalizationsForBuild (ctx , build .ID , nil )
153160 if err != nil {
154161 return err
155162 }
156- }
157- log .Info (string (platform ), " " , tag , " list submissions" )
158- betaSubmissions , _ , err := client .TestFlight .ListBetaAppReviewSubmissions (ctx , & asc.ListBetaAppReviewSubmissionsQuery {
159- FilterBuild : []string {builds .Data [0 ].ID },
160- })
161- if err != nil {
162- return err
163- }
164- if len (betaSubmissions .Data ) == 0 {
165- log .Info (string (platform ), " " , tag , " create submission" )
166- _ , _ , err = client .TestFlight .CreateBetaAppReviewSubmission (ctx , builds .Data [0 ].ID )
163+ localization := common .Find (localizations .Data , func (it asc.BetaBuildLocalization ) bool {
164+ return * it .Attributes .Locale == "en-US"
165+ })
166+ if localization .ID == "" {
167+ log .Fatal (string (platform ), " " , tag , " no en-US localization found" )
168+ }
169+ if localization .Attributes == nil || localization .Attributes .WhatsNew == nil || * localization .Attributes .WhatsNew == "" {
170+ log .Info (string (platform ), " " , tag , " update localization" )
171+ _ , _ , err = client .TestFlight .UpdateBetaBuildLocalization (ctx , localization .ID , common .Ptr (
172+ F .ToString ("sing-box " , tag ),
173+ ))
174+ if err != nil {
175+ return err
176+ }
177+ }
178+ log .Info (string (platform ), " " , tag , " publish" )
179+ response , err := client .TestFlight .AddBuildsToBetaGroup (ctx , groupID , []string {build .ID })
180+ if response != nil && response .StatusCode == http .StatusUnprocessableEntity {
181+ log .Info ("waiting for process" )
182+ time .Sleep (15 * time .Second )
183+ continue
184+ } else if err != nil {
185+ return err
186+ }
187+ log .Info (string (platform ), " " , tag , " list submissions" )
188+ betaSubmissions , _ , err := client .TestFlight .ListBetaAppReviewSubmissions (ctx , & asc.ListBetaAppReviewSubmissionsQuery {
189+ FilterBuild : []string {build .ID },
190+ })
167191 if err != nil {
168192 return err
169193 }
170- continue
194+ if len (betaSubmissions .Data ) == 0 {
195+ log .Info (string (platform ), " " , tag , " create submission" )
196+ _ , _ , err = client .TestFlight .CreateBetaAppReviewSubmission (ctx , build .ID )
197+ if err != nil {
198+ return err
199+ }
200+ }
201+ break
171202 }
172-
173203 }
174204 return nil
175205}
@@ -187,7 +217,7 @@ func cancelAppStore(ctx context.Context, platform string) error {
187217 if err != nil {
188218 return err
189219 }
190- client := createClient ()
220+ client := createClient (time . Minute )
191221 log .Info (platform , " list versions" )
192222 versions , _ , err := client .Apps .ListAppStoreVersionsForApp (ctx , appID , & asc.ListAppStoreVersionsQuery {
193223 FilterPlatform : []string {string (platform )},
@@ -222,7 +252,7 @@ func prepareAppStore(ctx context.Context) error {
222252 if err != nil {
223253 return err
224254 }
225- client := createClient ()
255+ client := createClient (time . Minute )
226256 for _ , platform := range []asc.Platform {
227257 asc .PlatformIOS ,
228258 asc .PlatformMACOS ,
@@ -364,7 +394,7 @@ func publishAppStore(ctx context.Context) error {
364394 if err != nil {
365395 return err
366396 }
367- client := createClient ()
397+ client := createClient (time . Minute )
368398 for _ , platform := range []asc.Platform {
369399 asc .PlatformIOS ,
370400 asc .PlatformMACOS ,
0 commit comments