diff --git a/internal/dtr/check.go b/internal/dtr/check.go index 8411119..2c22398 100644 --- a/internal/dtr/check.go +++ b/internal/dtr/check.go @@ -21,7 +21,6 @@ package dtr import ( - "fmt" "io" ) @@ -42,7 +41,8 @@ func Check(in io.Reader) (CheckResult, error) { } if len(result) == 0 { - return nil, fmt.Errorf("run command returned no output") + // Only return the incoming version to signal concourse that there is nothing new + result = append(result, config.Version) } return result, nil diff --git a/internal/dtr/check_test.go b/internal/dtr/check_test.go index 205bd0c..5ff9b80 100644 --- a/internal/dtr/check_test.go +++ b/internal/dtr/check_test.go @@ -29,7 +29,7 @@ import ( var _ = Describe("Check", func() { Context("invalid configuration", func() { - It("should fail if not run command is configured", func() { + It("should fail if no run command is configured", func() { _, err := Check(feed(Config{})) Expect(err).To(HaveOccurred()) }) @@ -46,14 +46,17 @@ var _ = Describe("Check", func() { Expect(err).To(HaveOccurred()) }) - It("should fail when no line is return by run", func() { - _, err := Check(feed(Config{ + It("should return provided version when no line is return by run", func() { + versionIn := Version{"ref": "barfoo"} + result, err := Check(feed(Config{ Source: Source{ Check: Custom{Run: "true"}, }, + Version: versionIn, })) - Expect(err).To(HaveOccurred()) + Expect(err).ToNot(HaveOccurred()) + Expect(result).To(Equal(CheckResult{versionIn})) }) It("should return two versions when two lines are returned", func() { diff --git a/internal/dtr/common.go b/internal/dtr/common.go index 20c2a2c..fbbba29 100644 --- a/internal/dtr/common.go +++ b/internal/dtr/common.go @@ -104,9 +104,15 @@ func execute(entry Custom) ([]string, error) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - before := command(ctx, entry.Env, entry.Before, os.Stderr) - if err := before.Run(); err != nil { - return nil, fmt.Errorf("failure while running before command: %w", err) + if entry.Before != "" { + before := command(ctx, entry.Env, entry.Before, os.Stderr) + if err := before.Run(); err != nil { + return nil, fmt.Errorf("failure while running before command: %w", err) + } + } + + if entry.Run == "" { + return nil, fmt.Errorf("run command not specified. Bailing out") } var outStream bytes.Buffer