Skip to content

Commit a9be02d

Browse files
committed
feat: fix spacing between waiting for build and pulling outputs
1 parent 1b10a24 commit a9be02d

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

pkg/cmd/init.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

pkg/cmd/workspace.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,18 @@ func handleWorkspaceInit(ctx context.Context, cmd *cli.Command) error {
197197
}
198198
}
199199

200-
Spacer()
201-
202200
if config.Targets != nil && len(config.Targets) > 0 {
203-
if err := waitAndPullBuild(ctx, cc.client, projectName, config); err != nil {
204-
return fmt.Errorf("build and target download failed: %v", err)
201+
Spacer()
202+
203+
build, err := waitForLatestBuild(ctx, cc.client, projectName)
204+
if err != nil {
205+
return fmt.Errorf("build wait failed: %v", err)
206+
}
207+
208+
Spacer()
209+
210+
if err := pullConfiguredTargets(ctx, cc.client, *build, config); err != nil {
211+
return fmt.Errorf("target download failed: %v", err)
205212
}
206213
}
207214

0 commit comments

Comments
 (0)