@@ -295,8 +295,17 @@ exit:
295295 Spacer ()
296296
297297 // Wait for build and pull outputs if workspace is configured
298- if err := waitAndPullBuild (ctx , cc .client , slug , config ); err != nil {
299- return fmt .Errorf ("build and pull failed: %v" , err )
298+ build , err := waitForLatestBuild (ctx , cc .client , slug )
299+ if err != nil {
300+ return fmt .Errorf ("build wait failed: %v" , err )
301+ }
302+
303+ if len (config .Targets ) > 0 {
304+ Spacer ()
305+
306+ if err := pullConfiguredTargets (ctx , cc .client , * build , config ); err != nil {
307+ return fmt .Errorf ("pull targets failed: %v" , err )
308+ }
300309 }
301310
302311 Spacer ()
@@ -482,34 +491,42 @@ func configureTargets(slug string, selectedTargets []string, config *WorkspaceCo
482491 return nil
483492}
484493
485- // waitAndPullBuild waits for the latest build to complete and pulls configured targets
486- func waitAndPullBuild (ctx context.Context , client stainless.Client , slug string , config WorkspaceConfig ) error {
494+ // waitForLatestBuild waits for the latest build to complete
495+ func waitForLatestBuild (ctx context.Context , client stainless.Client , slug string ) ( * stainless. BuildObject , error ) {
487496 waitGroup := Info ("Waiting for build to complete..." )
488497
489498 // Try to get the latest build for this project (which should have been created automatically)
490499 build , err := getLatestBuild (ctx , client , slug , "main" )
491500 if err != nil {
492- return fmt .Errorf ("expected build to exist after project creation, but none found: %v" , err )
501+ return nil , fmt .Errorf ("expected build to exist after project creation, but none found: %v" , err )
493502 }
494503
495504 waitGroup .Property ("build_id" , build .ID )
496505 build , err = waitForBuildCompletion (ctx , client , build .ID , & waitGroup )
497506 if err != nil {
498- return err
507+ return nil , err
499508 }
500509
501- if config . Targets != nil && len ( config . Targets ) > 0 {
502- pullGroup := Info ( "Pulling build outputs..." )
510+ return build , nil
511+ }
503512
504- // Create target paths map from workspace config
505- targetPaths := make ( map [ string ] string )
506- for targetName , targetConfig := range config .Targets {
507- targetPaths [ targetName ] = targetConfig . OutputPath
508- }
513+ // pullConfiguredTargets pulls build outputs for configured targets
514+ func pullConfiguredTargets ( ctx context. Context , client stainless. Client , build stainless. BuildObject , config WorkspaceConfig ) error {
515+ if config . Targets == nil || len ( config .Targets ) == 0 {
516+ return nil
517+ }
509518
510- if err := pullBuildOutputs (ctx , client , * build , targetPaths , & pullGroup ); err != nil {
511- pullGroup .Error ("Failed to pull outputs: %v" , err )
512- }
519+ pullGroup := Info ("Pulling build outputs..." )
520+
521+ // Create target paths map from workspace config
522+ targetPaths := make (map [string ]string )
523+ for targetName , targetConfig := range config .Targets {
524+ targetPaths [targetName ] = targetConfig .OutputPath
525+ }
526+
527+ if err := pullBuildOutputs (ctx , client , build , targetPaths , & pullGroup ); err != nil {
528+ pullGroup .Error ("Failed to pull outputs: %v" , err )
529+ return err
513530 }
514531
515532 return nil
0 commit comments