Skip to content

Add hooks to observe walking the deploy directories. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const (
)

type DeployObserver interface {
OnSetupWalk() error
OnSuccessfulStep(*FileBundle) error
OnSuccessfulWalk(*models.DeployFiles) error
OnFailedWalk()

OnSetupDelta(*models.DeployFiles) error
OnSuccessfulDelta(*models.DeployFiles, *models.Deploy) error
OnFailedDelta(*models.DeployFiles)
Expand Down Expand Up @@ -159,14 +164,26 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
return nil, fmt.Errorf("%s is not a directory", options.Dir)
}

files, err := walk(options.Dir)
if options.Observer != nil {
if err := options.Observer.OnSetupWalk(); err != nil {
return nil, err
}
}

files, err := walk(options.Dir, options.Observer)
if err != nil {
if options.Observer != nil {
options.Observer.OnFailedWalk()
}
return nil, err
}
options.files = files

functions, err := bundle(options.FunctionsDir)
functions, err := bundle(options.FunctionsDir, options.Observer)
if err != nil {
if options.Observer != nil {
options.Observer.OnFailedWalk()
}
return nil, err
}
options.functions = functions
Expand All @@ -180,6 +197,12 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
deployFiles.Functions = options.functions.Sums
}

if options.Observer != nil {
if err := options.Observer.OnSuccessfulWalk(deployFiles); err != nil {
return nil, err
}
}

l := context.GetLogger(ctx)
l.WithFields(logrus.Fields{
"site_id": options.SiteID,
Expand Down Expand Up @@ -417,7 +440,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
}
}

func walk(dir string) (*deployFiles, error) {
func walk(dir string, observer DeployObserver) (*deployFiles, error) {
files := newDeployFiles()

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -452,14 +475,20 @@ func walk(dir string) (*deployFiles, error) {
o.Seek(0, 0)
file.Buffer = o
files.Add(rel, file)

if observer != nil {
if err := observer.OnSuccessfulStep(file); err != nil {
return err
}
}
}

return nil
})
return files, err
}

func bundle(functionDir string) (*deployFiles, error) {
func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
if functionDir == "" {
return nil, nil
}
Expand Down Expand Up @@ -506,6 +535,12 @@ func bundle(functionDir string) (*deployFiles, error) {
fileEntry.Seek(0, 0)
file.Buffer = bytes.NewReader(fileBuffer.Bytes())
functions.Add(file.Name, file)

if observer != nil {
if err := observer.OnSuccessfulStep(file); err != nil {
return nil, err
}
}
default:
// Ignore this file
}
Expand Down