@@ -100,11 +100,32 @@ findVersion:
100100}
101101
102102func publishTestflight (ctx context.Context ) error {
103+ if len (os .Args ) < 3 {
104+ return E .New ("platform required: ios, macos, or tvos" )
105+ }
106+ var platform asc.Platform
107+ switch os .Args [2 ] {
108+ case "ios" :
109+ platform = asc .PlatformIOS
110+ case "macos" :
111+ platform = asc .PlatformMACOS
112+ case "tvos" :
113+ platform = asc .PlatformTVOS
114+ default :
115+ return E .New ("unknown platform: " , os .Args [2 ])
116+ }
117+
103118 tagVersion , err := build_shared .ReadTagVersion ()
104119 if err != nil {
105120 return err
106121 }
107122 tag := tagVersion .VersionString ()
123+
124+ releaseNotes := F .ToString ("sing-box " , tagVersion .String ())
125+ if len (os .Args ) >= 4 {
126+ releaseNotes = strings .Join (os .Args [3 :], " " )
127+ }
128+
108129 client := createClient (20 * time .Minute )
109130
110131 log .Info (tag , " list build IDs" )
@@ -115,97 +136,75 @@ func publishTestflight(ctx context.Context) error {
115136 buildIDs := common .Map (buildIDsResponse .Data , func (it asc.RelationshipData ) string {
116137 return it .ID
117138 })
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 ])
139+
140+ waitingForProcess := false
141+ log .Info (string (platform ), " list builds" )
142+ for {
143+ builds , _ , err := client .Builds .ListBuilds (ctx , & asc.ListBuildsQuery {
144+ FilterApp : []string {appID },
145+ FilterPreReleaseVersionPlatform : []string {string (platform )},
146+ })
147+ if err != nil {
148+ return err
129149 }
130- } else {
131- platforms = []asc. Platform {
132- asc . PlatformIOS ,
133- asc . PlatformMACOS ,
134- asc . PlatformTVOS ,
150+ build := builds . Data [ 0 ]
151+ if ! waitingForProcess && ( common . Contains ( buildIDs , build . ID ) || time . Since ( build . Attributes . UploadedDate . Time ) > 30 * time . Minute ) {
152+ log . Info ( string ( platform ), " " , tag , " waiting for process" )
153+ time . Sleep ( 15 * time . Second )
154+ continue
135155 }
136- }
137- waitingForProcess := false
138- for _ , platform := range platforms {
139- log .Info (string (platform ), " list builds" )
140- for {
141- builds , _ , err := client .Builds .ListBuilds (ctx , & asc.ListBuildsQuery {
142- FilterApp : []string {appID },
143- FilterPreReleaseVersionPlatform : []string {string (platform )},
144- })
156+ if * build .Attributes .ProcessingState != "VALID" {
157+ waitingForProcess = true
158+ log .Info (string (platform ), " " , tag , " waiting for process: " , * build .Attributes .ProcessingState )
159+ time .Sleep (15 * time .Second )
160+ continue
161+ }
162+ log .Info (string (platform ), " " , tag , " list localizations" )
163+ localizations , _ , err := client .TestFlight .ListBetaBuildLocalizationsForBuild (ctx , build .ID , nil )
164+ if err != nil {
165+ return err
166+ }
167+ localization := common .Find (localizations .Data , func (it asc.BetaBuildLocalization ) bool {
168+ return * it .Attributes .Locale == "en-US"
169+ })
170+ if localization .ID == "" {
171+ log .Fatal (string (platform ), " " , tag , " no en-US localization found" )
172+ }
173+ if localization .Attributes == nil || localization .Attributes .WhatsNew == nil || * localization .Attributes .WhatsNew == "" {
174+ log .Info (string (platform ), " " , tag , " update localization" )
175+ _ , _ , err = client .TestFlight .UpdateBetaBuildLocalization (ctx , localization .ID , common .Ptr (releaseNotes ))
145176 if err != nil {
146177 return err
147178 }
148- build := builds .Data [0 ]
149- if ! waitingForProcess && (common .Contains (buildIDs , build .ID ) || time .Since (build .Attributes .UploadedDate .Time ) > 30 * time .Minute ) {
150- log .Info (string (platform ), " " , tag , " waiting for process" )
151- time .Sleep (15 * time .Second )
152- continue
153- }
154- if * build .Attributes .ProcessingState != "VALID" {
155- waitingForProcess = true
156- log .Info (string (platform ), " " , tag , " waiting for process: " , * build .Attributes .ProcessingState )
157- time .Sleep (15 * time .Second )
158- continue
159- }
160- log .Info (string (platform ), " " , tag , " list localizations" )
161- localizations , _ , err := client .TestFlight .ListBetaBuildLocalizationsForBuild (ctx , build .ID , nil )
179+ }
180+ log .Info (string (platform ), " " , tag , " publish" )
181+ response , err := client .TestFlight .AddBuildsToBetaGroup (ctx , groupID , []string {build .ID })
182+ if response != nil && (response .StatusCode == http .StatusUnprocessableEntity || response .StatusCode == http .StatusNotFound ) {
183+ log .Info ("waiting for process" )
184+ time .Sleep (15 * time .Second )
185+ continue
186+ } else if err != nil {
187+ return err
188+ }
189+ log .Info (string (platform ), " " , tag , " list submissions" )
190+ betaSubmissions , _ , err := client .TestFlight .ListBetaAppReviewSubmissions (ctx , & asc.ListBetaAppReviewSubmissionsQuery {
191+ FilterBuild : []string {build .ID },
192+ })
193+ if err != nil {
194+ return err
195+ }
196+ if len (betaSubmissions .Data ) == 0 {
197+ log .Info (string (platform ), " " , tag , " create submission" )
198+ _ , _ , err = client .TestFlight .CreateBetaAppReviewSubmission (ctx , build .ID )
162199 if err != nil {
163- return err
164- }
165- localization := common .Find (localizations .Data , func (it asc.BetaBuildLocalization ) bool {
166- return * it .Attributes .Locale == "en-US"
167- })
168- if localization .ID == "" {
169- log .Fatal (string (platform ), " " , tag , " no en-US localization found" )
170- }
171- if localization .Attributes == nil || localization .Attributes .WhatsNew == nil || * localization .Attributes .WhatsNew == "" {
172- log .Info (string (platform ), " " , tag , " update localization" )
173- _ , _ , err = client .TestFlight .UpdateBetaBuildLocalization (ctx , localization .ID , common .Ptr (
174- F .ToString ("sing-box " , tagVersion .String ()),
175- ))
176- if err != nil {
177- return err
200+ if strings .Contains (err .Error (), "ANOTHER_BUILD_IN_REVIEW" ) {
201+ log .Error (err )
202+ break
178203 }
179- }
180- log .Info (string (platform ), " " , tag , " publish" )
181- response , err := client .TestFlight .AddBuildsToBetaGroup (ctx , groupID , []string {build .ID })
182- if response != nil && (response .StatusCode == http .StatusUnprocessableEntity || response .StatusCode == http .StatusNotFound ) {
183- log .Info ("waiting for process" )
184- time .Sleep (15 * time .Second )
185- continue
186- } else if err != nil {
187204 return err
188205 }
189- log .Info (string (platform ), " " , tag , " list submissions" )
190- betaSubmissions , _ , err := client .TestFlight .ListBetaAppReviewSubmissions (ctx , & asc.ListBetaAppReviewSubmissionsQuery {
191- FilterBuild : []string {build .ID },
192- })
193- if err != nil {
194- return err
195- }
196- if len (betaSubmissions .Data ) == 0 {
197- log .Info (string (platform ), " " , tag , " create submission" )
198- _ , _ , err = client .TestFlight .CreateBetaAppReviewSubmission (ctx , build .ID )
199- if err != nil {
200- if strings .Contains (err .Error (), "ANOTHER_BUILD_IN_REVIEW" ) {
201- log .Error (err )
202- break
203- }
204- return err
205- }
206- }
207- break
208206 }
207+ break
209208 }
210209 return nil
211210}
0 commit comments