From 7b3bd1acae6a8903edcd1e43add33435957fa2c2 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Tue, 6 Oct 2020 06:51:44 -0700 Subject: [PATCH] Fix regression in build dependency error handling --- CHANGELOG.md | 11 +++++++++++ cli/build.go | 40 +++++++++++++++------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3c937b..17356394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog][], and this project adheres to [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ +## [0.3.1][] + +Version 0.3.1 fixes an issue with error handling during builds. + +[0.3.1]: https://github.com/yourbase/yb/releases/tag/v0.3.1 + +### Fixed + +- Fixed a regression where if a dependent target fails, it did not stop + the build. + ## [0.3.0][] Version 0.3 is the first release with our new release automation. diff --git a/cli/build.go b/cli/build.go index 72ca9f46..bfa48d22 100644 --- a/cli/build.go +++ b/cli/build.go @@ -11,7 +11,6 @@ import ( "io/ioutil" "os" "os/signal" - "os/user" "path/filepath" "runtime" "strings" @@ -211,15 +210,10 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ mount := fmt.Sprintf("%s:%s", targetPackage.Path, sourceMapDir) containerDef.Mounts = append(containerDef.Mounts, mount) - if false { - u, _ := user.Current() - fmt.Printf("U! %s", u.Uid) - } - // Do our build in a container - don't do the build locally - buildErr := b.BuildInsideContainer(ctx, target, containerDef, buildData, b.ExecPrefix, b.ReuseContainers) - if buildErr != nil { - log.Errorf(ctx, "Unable to build %s inside container: %v", target.Name, buildErr) + err := b.BuildInsideContainer(ctx, target, containerDef, buildData, b.ExecPrefix, b.ReuseContainers) + if err != nil { + log.Errorf(ctx, "Unable to build %s inside container: %v", target.Name, err) return subcommands.ExitFailure } @@ -243,8 +237,6 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ } } - var buildError error - startSection("BUILD") config := BuildConfiguration{ @@ -261,16 +253,17 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ log.Infof(ctx, " - %s", target.Name) } + var buildError error for _, target := range buildTargets { targetCtx, targetSpan := tracer().Start(ctx, target.Name, trace.WithAttributes( label.String("target", target.Name), )) - err := targetPackage.SetupBuildDependencies(targetCtx, target) - if err != nil { - targetSpan.SetStatus(codes.Internal, err.Error()) + buildError = targetPackage.SetupBuildDependencies(targetCtx, target) + if buildError != nil { + buildError = fmt.Errorf("setting up dependencies for target %s: %w", target.Name, buildError) + targetSpan.SetStatus(codes.Internal, buildError.Error()) targetSpan.End() - log.Infof(ctx, "Error setting up dependencies for target %s: %v", target.Name, err) - return subcommands.ExitFailure + break } if b.DependenciesOnly { @@ -280,9 +273,10 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ config.Target = target buildData.ExportEnvironmentPublicly(ctx) log.Infof(ctx, "Executing build steps...") - err = RunCommands(targetCtx, config) - if err != nil { - targetSpan.SetStatus(codes.Unknown, err.Error()) + buildError = RunCommands(targetCtx, config) + if buildError != nil { + buildError = fmt.Errorf("running commands for target %s: %w", target.Name, buildError) + targetSpan.SetStatus(codes.Unknown, buildError.Error()) } targetSpan.End() buildData.UnexportEnvironmentPublicly(ctx) @@ -290,17 +284,13 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ break } } - if b.DependenciesOnly { - log.Infof(ctx, "Only installing dependencies; done!") - return subcommands.ExitSuccess - } - if buildError != nil { span.SetStatus(codes.Unknown, buildError.Error()) } - endTime := time.Now() span.End() + endTime := time.Now() buildTime := endTime.Sub(startTime) + time.Sleep(100 * time.Millisecond) log.Infof(ctx, "")