diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 530acbc6b..43a77a992 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "io/ioutil" "path/filepath" "strings" "text/template" @@ -111,14 +112,23 @@ func doRun(ctx *context.Context, client client.Client) error { if len(archives) > 1 { return ErrTooManyDarwin64Builds } - var path = filepath.Join(ctx.Config.Brew.Folder, ctx.Config.ProjectName+".rb") - log.WithField("formula", path). - WithField("repo", ctx.Config.Brew.GitHub.String()). - Info("pushing") + content, err := buildFormula(ctx, client, archives[0]) if err != nil { return err } + + var filename = ctx.Config.ProjectName + ".rb" + var path = filepath.Join(ctx.Config.Dist, filename) + log.WithField("formula", path).Info("writing") + if err := ioutil.WriteFile(path, content.Bytes(), 0644); err != nil { + return err + } + + path = filepath.Join(ctx.Config.Brew.Folder, filename) + log.WithField("formula", path). + WithField("repo", ctx.Config.Brew.GitHub.String()). + Info("pushing") return client.CreateFile(ctx, content, path) } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index ece88eba4..f0dfc568b 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -145,6 +145,8 @@ func TestRunPipe(t *testing.T) { _, err = os.Create(path) assert.NoError(t, err) + var distFile = filepath.Join(folder, "run-pipe.rb") + t.Run("default git url", func(tt *testing.T) { assert.NoError(tt, doRun(ctx, client)) assert.True(tt, client.CreatedFile) @@ -155,6 +157,10 @@ func TestRunPipe(t *testing.T) { bts, err := ioutil.ReadFile(golden) assert.NoError(tt, err) assert.Equal(tt, string(bts), client.Content) + + distBts, err := ioutil.ReadFile(distFile) + assert.NoError(tt, err) + assert.Equal(tt, string(bts), string(distBts)) }) t.Run("github enterprise url", func(tt *testing.T) { @@ -168,6 +174,10 @@ func TestRunPipe(t *testing.T) { bts, err := ioutil.ReadFile(golden) assert.NoError(tt, err) assert.Equal(tt, string(bts), client.Content) + + distBts, err := ioutil.ReadFile(distFile) + assert.NoError(tt, err) + assert.Equal(tt, string(bts), string(distBts)) }) }