Skip to content

Commit 859cd8a

Browse files
author
Bruce Hill
committed
Ensure that stl builds create gives a nonzero exit status when builds
fail.
1 parent b0e2f60 commit 859cd8a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

pkg/cmd/build.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,21 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
479479
targetPaths := parseTargetPaths(cc.workspaceConfig)
480480
buildGroup := Info("Creating build...")
481481
params := stainless.BuildNewParams{}
482-
res, err := cc.client.Builds.New(
482+
build, err := cc.client.Builds.New(
483483
ctx,
484484
params,
485485
option.WithMiddleware(cc.AsMiddleware()),
486486
)
487487
if err != nil {
488488
return err
489489
}
490-
491-
buildGroup.Property("build_id", res.ID)
490+
491+
buildGroup.Property("build_id", build.ID)
492492

493493
if cmd.Bool("wait") {
494494
waitGroup := Info("Waiting for latest build to complete...")
495495

496-
res, err = waitForBuildCompletion(context.TODO(), cc.client, res, &waitGroup)
496+
build, err = waitForBuildCompletion(context.TODO(), cc.client, build, &waitGroup)
497497
if err != nil {
498498
return err
499499
}
@@ -503,18 +503,31 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
503503

504504
if shouldPull {
505505
pullGroup := Info("Downloading build outputs...")
506-
if err := pullBuildOutputs(context.TODO(), cc.client, *res, targetPaths, &pullGroup); err != nil {
506+
if err := pullBuildOutputs(context.TODO(), cc.client, *build, targetPaths, &pullGroup); err != nil {
507507
pullGroup.Error("Failed to download outputs: %v", err)
508508
} else {
509509
pullGroup.Success("Successfully downloaded all outputs")
510510
}
511511
}
512512
}
513513

514-
data := gjson.Parse(string(res.RawJSON()))
514+
data := gjson.Parse(string(build.RawJSON()))
515515
format := cmd.Root().String("format")
516516
transform := cmd.Root().String("transform")
517-
return ShowJSON("builds create", data, format, transform)
517+
if err := ShowJSON("builds create", data, format, transform); err != nil {
518+
return err
519+
}
520+
521+
for _, target := range data.Get("targets.@values").Array() {
522+
if target.Get("status").String() == "not_started" ||
523+
target.Get("commit.completed.conclusion").String() == "error" ||
524+
target.Get("lint.completed.conclusion").String() == "error" ||
525+
target.Get("test.completed.conclusion").String() == "error" {
526+
os.Exit(1)
527+
}
528+
}
529+
530+
return nil
518531
}
519532

520533
func handleBuildsRetrieve(ctx context.Context, cmd *cli.Command) error {

0 commit comments

Comments
 (0)