@@ -172,47 +172,48 @@ func isTargetCompleted(status stainless.BuildTargetStatus) bool {
172172}
173173
174174// waitForBuildCompletion polls a build until completion and shows progress updates
175- func waitForBuildCompletion (ctx context.Context , client stainless.Client , buildID string , waitGroup * Group ) (* stainless.BuildObject , error ) {
175+ func waitForBuildCompletion (ctx context.Context , client stainless.Client , build * stainless. BuildObject , waitGroup * Group ) (* stainless.BuildObject , error ) {
176176 ticker := time .NewTicker (3 * time .Second )
177177 defer ticker .Stop ()
178178
179179 targetProgress := make (map [string ]string )
180180
181181 for {
182- select {
183- case <- ticker .C :
184- buildRes , err := client .Builds .Get (ctx , buildID )
185- if err != nil {
186- waitGroup .Error ("Error polling build status: %v" , err )
187- return nil , fmt .Errorf ("build polling failed: %v" , err )
188- }
189-
190- targets := getBuildTargetInfo (* buildRes )
191- allCompleted := true
182+ targets := getBuildTargetInfo (* build )
183+ allCompleted := true
192184
193- for _ , target := range targets {
194- prevStatus := targetProgress [target .name ]
185+ for _ , target := range targets {
186+ prevStatus := targetProgress [target .name ]
195187
196- if string (target .status ) != prevStatus {
197- targetProgress [target .name ] = string (target .status )
188+ if string (target .status ) != prevStatus {
189+ targetProgress [target .name ] = string (target .status )
198190
199- if isTargetCompleted (target .status ) {
200- waitGroup .Success ("%s: %s" , target .name , "completed" )
201- } else if target .status == "failed" {
202- waitGroup .Error ("%s: %s" , target .name , string (target .status ))
203- }
191+ if isTargetCompleted (target .status ) {
192+ waitGroup .Success ("%s: %s" , target .name , "completed" )
193+ } else if target .status == "failed" {
194+ waitGroup .Error ("%s: %s" , target .name , string (target .status ))
204195 }
196+ }
205197
206- if ! isTargetCompleted (target .status ) && target .status != "failed" {
207- allCompleted = false
208- }
198+ if ! isTargetCompleted (target .status ) && target .status != "failed" {
199+ allCompleted = false
209200 }
201+ }
210202
211- if allCompleted && len (targets ) > 0 {
212- if allCompleted {
213- waitGroup .Success ("Build completed successfully" )
214- return buildRes , nil
215- }
203+ if allCompleted && len (targets ) > 0 {
204+ if allCompleted {
205+ waitGroup .Success ("Build completed successfully" )
206+ return build , nil
207+ }
208+ }
209+
210+ select {
211+ case <- ticker .C :
212+ var err error
213+ build , err = client .Builds .Get (ctx , build .ID )
214+ if err != nil {
215+ waitGroup .Error ("Error polling build status: %v" , err )
216+ return nil , fmt .Errorf ("build polling failed: %v" , err )
216217 }
217218
218219 case <- ctx .Done ():
@@ -462,9 +463,9 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
462463 buildGroup .Property ("build_id" , res .ID )
463464
464465 if cmd .Bool ("wait" ) {
465- waitGroup := Info ("Waiting for build to complete..." )
466+ waitGroup := Info ("Waiting for latest build to complete..." )
466467
467- res , err = waitForBuildCompletion (context .TODO (), cc .client , res . ID , & waitGroup )
468+ res , err = waitForBuildCompletion (context .TODO (), cc .client , res , & waitGroup )
468469 if err != nil {
469470 return err
470471 }
0 commit comments