Skip to content

Commit

Permalink
Stream dotnet publish output (#293)
Browse files Browse the repository at this point in the history
* upgrade to packit v2

* stream output of dotnet publish
  • Loading branch information
Frankie G-J authored Mar 4, 2022
1 parent 62a20e6 commit 8eaf301
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 90 deletions.
8 changes: 4 additions & 4 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"path/filepath"

"github.com/Masterminds/semver"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/paketo-buildpacks/packit/v2/servicebindings"
)

//go:generate faux --interface SymlinkManager --output fakes/symlink_manager.go
Expand Down
8 changes: 4 additions & 4 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

dotnetpublish "github.com/paketo-buildpacks/dotnet-publish"
"github.com/paketo-buildpacks/dotnet-publish/fakes"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/paketo-buildpacks/packit/v2/servicebindings"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/v2"
)

type BuildPlanMetadata struct {
Expand Down
2 changes: 1 addition & 1 deletion detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

dotnetpublish "github.com/paketo-buildpacks/dotnet-publish"
"github.com/paketo-buildpacks/dotnet-publish/fakes"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/v2"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
Expand Down
14 changes: 5 additions & 9 deletions dotnet_publish_process.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package dotnetpublish

import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/pexec"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/packit/v2/scribe"
)

type Executable interface {
Expand All @@ -31,7 +30,6 @@ func NewDotnetPublishProcess(executable Executable, logger scribe.Logger, clock
}

func (p DotnetPublishProcess) Execute(workingDir, root, nugetCachePath, projectPath, outputPath string, flags []string) error {
buffer := bytes.NewBuffer(nil)
args := []string{
"publish", filepath.Join(workingDir, projectPath), // change to workingDir plus project path
}
Expand Down Expand Up @@ -61,15 +59,13 @@ func (p DotnetPublishProcess) Execute(workingDir, root, nugetCachePath, projectP
Args: args,
Dir: workingDir,
Env: append(os.Environ(), fmt.Sprintf("PATH=%s:%s", root, os.Getenv("PATH")), fmt.Sprintf("NUGET_PACKAGES=%s", nugetCachePath)),
Stdout: buffer,
Stderr: buffer,
Stdout: p.logger.ActionWriter,
Stderr: p.logger.ActionWriter,
})
})

if err != nil {
p.logger.Action("Failed after %s", duration)
p.logger.Detail(buffer.String())

return fmt.Errorf("failed to execute 'dotnet publish': %w", err)
}

Expand Down
32 changes: 23 additions & 9 deletions dotnet_publish_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"testing"
"time"

"github.com/ForestEckhardt/freezer/fakes"
dotnetpublish "github.com/paketo-buildpacks/dotnet-publish"
"github.com/paketo-buildpacks/packit/cargo/fakes"
"github.com/paketo-buildpacks/packit/chronos"
"github.com/paketo-buildpacks/packit/pexec"
"github.com/paketo-buildpacks/packit/scribe"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func testDotnetPublishProcess(t *testing.T, context spec.G, it spec.S) {
Expand Down Expand Up @@ -52,6 +53,13 @@ func testDotnetPublishProcess(t *testing.T, context spec.G, it spec.S) {
return t
})

executable.ExecuteCall.Stub = func(execution pexec.Execution) error {
fmt.Fprintln(execution.Stdout, "stdout-output")
fmt.Fprintln(execution.Stderr, "stderr-output")

return nil
}

process = dotnetpublish.NewDotnetPublishProcess(executable, logger, clock)
})

Expand All @@ -78,8 +86,12 @@ func testDotnetPublishProcess(t *testing.T, context spec.G, it spec.S) {
Expect(executable.ExecuteCall.Receives.Execution.Env).To(ContainElement("PATH=some-dotnet-root-dir:some-path"))
Expect(executable.ExecuteCall.Receives.Execution.Env).To(ContainElement("NUGET_PACKAGES=some/nuget/cache/path"))

Expect(buffer.String()).To(ContainSubstring(fmt.Sprintf("Running 'dotnet %s'", strings.Join(args, " "))))
Expect(buffer.String()).To(ContainSubstring("Completed in 1s"))
Expect(buffer.String()).To(ContainLines(
fmt.Sprintf(" Running 'dotnet %s'", strings.Join(args, " ")),
" stdout-output",
" stderr-output",
" Completed in 1s",
))
})

context("when the user passes flags that the buildpack sets by default", func() {
Expand Down Expand Up @@ -141,9 +153,11 @@ func testDotnetPublishProcess(t *testing.T, context spec.G, it spec.S) {
err := process.Execute("some-working-dir", "some-dotnet-root-dir", "some/nuget/cache/path", "", "some-output-dir", []string{})
Expect(err).To(HaveOccurred())

Expect(buffer.String()).To(ContainSubstring(" Failed after 1s"))
Expect(buffer.String()).To(ContainSubstring(" stdout-output"))
Expect(buffer.String()).To(ContainSubstring(" stderr-output"))
Expect(buffer.String()).To(ContainLines(
" stdout-output",
" stderr-output",
" Failed after 1s",
))
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion dotnet_source_remover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

"github.com/paketo-buildpacks/packit/fs"
"github.com/paketo-buildpacks/packit/v2/fs"
)

type DotnetSourceRemover struct{}
Expand Down
8 changes: 4 additions & 4 deletions fakes/binding_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package fakes
import (
"sync"

"github.com/paketo-buildpacks/packit/servicebindings"
"github.com/paketo-buildpacks/packit/v2/servicebindings"
)

type BindingResolver struct {
ResolveCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Typ string
Expand All @@ -24,8 +24,8 @@ type BindingResolver struct {
}

func (f *BindingResolver) Resolve(param1 string, param2 string, param3 string) ([]servicebindings.Binding, error) {
f.ResolveCall.Lock()
defer f.ResolveCall.Unlock()
f.ResolveCall.mutex.Lock()
defer f.ResolveCall.mutex.Unlock()
f.ResolveCall.CallCount++
f.ResolveCall.Receives.Typ = param1
f.ResolveCall.Receives.Provider = param2
Expand Down
6 changes: 3 additions & 3 deletions fakes/buildpack_yml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type BuildpackYMLParser struct {
ParseProjectPathCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -18,8 +18,8 @@ type BuildpackYMLParser struct {
}

func (f *BuildpackYMLParser) ParseProjectPath(param1 string) (string, error) {
f.ParseProjectPathCall.Lock()
defer f.ParseProjectPathCall.Unlock()
f.ParseProjectPathCall.mutex.Lock()
defer f.ParseProjectPathCall.mutex.Unlock()
f.ParseProjectPathCall.CallCount++
f.ParseProjectPathCall.Receives.Path = param1
if f.ParseProjectPathCall.Stub != nil {
Expand Down
6 changes: 3 additions & 3 deletions fakes/command_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type CommandConfigParser struct {
ParseFlagsFromEnvVarCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
EnvVar string
Expand All @@ -18,8 +18,8 @@ type CommandConfigParser struct {
}

func (f *CommandConfigParser) ParseFlagsFromEnvVar(param1 string) ([]string, error) {
f.ParseFlagsFromEnvVarCall.Lock()
defer f.ParseFlagsFromEnvVarCall.Unlock()
f.ParseFlagsFromEnvVarCall.mutex.Lock()
defer f.ParseFlagsFromEnvVarCall.mutex.Unlock()
f.ParseFlagsFromEnvVarCall.CallCount++
f.ParseFlagsFromEnvVarCall.Receives.EnvVar = param1
if f.ParseFlagsFromEnvVarCall.Stub != nil {
Expand Down
24 changes: 12 additions & 12 deletions fakes/project_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type ProjectParser struct {
ASPNetIsRequiredCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -16,7 +16,7 @@ type ProjectParser struct {
Stub func(string) (bool, error)
}
FindProjectFileCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Root string
Expand All @@ -28,7 +28,7 @@ type ProjectParser struct {
Stub func(string) (string, error)
}
NPMIsRequiredCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -40,7 +40,7 @@ type ProjectParser struct {
Stub func(string) (bool, error)
}
NodeIsRequiredCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -54,8 +54,8 @@ type ProjectParser struct {
}

func (f *ProjectParser) ASPNetIsRequired(param1 string) (bool, error) {
f.ASPNetIsRequiredCall.Lock()
defer f.ASPNetIsRequiredCall.Unlock()
f.ASPNetIsRequiredCall.mutex.Lock()
defer f.ASPNetIsRequiredCall.mutex.Unlock()
f.ASPNetIsRequiredCall.CallCount++
f.ASPNetIsRequiredCall.Receives.Path = param1
if f.ASPNetIsRequiredCall.Stub != nil {
Expand All @@ -64,8 +64,8 @@ func (f *ProjectParser) ASPNetIsRequired(param1 string) (bool, error) {
return f.ASPNetIsRequiredCall.Returns.Bool, f.ASPNetIsRequiredCall.Returns.Error
}
func (f *ProjectParser) FindProjectFile(param1 string) (string, error) {
f.FindProjectFileCall.Lock()
defer f.FindProjectFileCall.Unlock()
f.FindProjectFileCall.mutex.Lock()
defer f.FindProjectFileCall.mutex.Unlock()
f.FindProjectFileCall.CallCount++
f.FindProjectFileCall.Receives.Root = param1
if f.FindProjectFileCall.Stub != nil {
Expand All @@ -74,8 +74,8 @@ func (f *ProjectParser) FindProjectFile(param1 string) (string, error) {
return f.FindProjectFileCall.Returns.String, f.FindProjectFileCall.Returns.Error
}
func (f *ProjectParser) NPMIsRequired(param1 string) (bool, error) {
f.NPMIsRequiredCall.Lock()
defer f.NPMIsRequiredCall.Unlock()
f.NPMIsRequiredCall.mutex.Lock()
defer f.NPMIsRequiredCall.mutex.Unlock()
f.NPMIsRequiredCall.CallCount++
f.NPMIsRequiredCall.Receives.Path = param1
if f.NPMIsRequiredCall.Stub != nil {
Expand All @@ -84,8 +84,8 @@ func (f *ProjectParser) NPMIsRequired(param1 string) (bool, error) {
return f.NPMIsRequiredCall.Returns.Bool, f.NPMIsRequiredCall.Returns.Error
}
func (f *ProjectParser) NodeIsRequired(param1 string) (bool, error) {
f.NodeIsRequiredCall.Lock()
defer f.NodeIsRequiredCall.Unlock()
f.NodeIsRequiredCall.mutex.Lock()
defer f.NodeIsRequiredCall.mutex.Unlock()
f.NodeIsRequiredCall.CallCount++
f.NodeIsRequiredCall.Receives.Path = param1
if f.NodeIsRequiredCall.Stub != nil {
Expand Down
6 changes: 3 additions & 3 deletions fakes/publish_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type PublishProcess struct {
ExecuteCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
WorkingDir string
Expand All @@ -22,8 +22,8 @@ type PublishProcess struct {
}

func (f *PublishProcess) Execute(param1 string, param2 string, param3 string, param4 string, param5 string, param6 []string) error {
f.ExecuteCall.Lock()
defer f.ExecuteCall.Unlock()
f.ExecuteCall.mutex.Lock()
defer f.ExecuteCall.mutex.Unlock()
f.ExecuteCall.CallCount++
f.ExecuteCall.Receives.WorkingDir = param1
f.ExecuteCall.Receives.RootDir = param2
Expand Down
6 changes: 3 additions & 3 deletions fakes/source_remover.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type SourceRemover struct {
RemoveCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
WorkingDir string
Expand All @@ -19,8 +19,8 @@ type SourceRemover struct {
}

func (f *SourceRemover) Remove(param1 string, param2 string, param3 ...string) error {
f.RemoveCall.Lock()
defer f.RemoveCall.Unlock()
f.RemoveCall.mutex.Lock()
defer f.RemoveCall.mutex.Unlock()
f.RemoveCall.CallCount++
f.RemoveCall.Receives.WorkingDir = param1
f.RemoveCall.Receives.PublishOutputDir = param2
Expand Down
12 changes: 6 additions & 6 deletions fakes/symlink_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type SymlinkManager struct {
LinkCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Oldname string
Expand All @@ -16,7 +16,7 @@ type SymlinkManager struct {
Stub func(string, string) error
}
UnlinkCall struct {
sync.Mutex
mutex sync.Mutex
CallCount int
Receives struct {
Path string
Expand All @@ -29,8 +29,8 @@ type SymlinkManager struct {
}

func (f *SymlinkManager) Link(param1 string, param2 string) error {
f.LinkCall.Lock()
defer f.LinkCall.Unlock()
f.LinkCall.mutex.Lock()
defer f.LinkCall.mutex.Unlock()
f.LinkCall.CallCount++
f.LinkCall.Receives.Oldname = param1
f.LinkCall.Receives.Newname = param2
Expand All @@ -40,8 +40,8 @@ func (f *SymlinkManager) Link(param1 string, param2 string) error {
return f.LinkCall.Returns.Error
}
func (f *SymlinkManager) Unlink(param1 string) error {
f.UnlinkCall.Lock()
defer f.UnlinkCall.Unlock()
f.UnlinkCall.mutex.Lock()
defer f.UnlinkCall.mutex.Unlock()
f.UnlinkCall.CallCount++
f.UnlinkCall.Receives.Path = param1
if f.UnlinkCall.Stub != nil {
Expand Down
Loading

0 comments on commit 8eaf301

Please sign in to comment.