Skip to content
Permalink
Browse files

add deploy --no-build flag for skipping build hooks. Closes #730

  • Loading branch information...
tj committed Dec 6, 2018
1 parent e8e8529 commit 8cb822934250c5f047b79ae492ea873521c5d7ef
Showing with 23 additions and 10 deletions.
  1. +1 −1 internal/cli/build/build.go
  2. +6 −2 internal/cli/deploy/deploy.go
  3. +1 −0 platform.go
  4. +15 −7 up.go
@@ -42,7 +42,7 @@ func init() {
return errors.Wrap(err, "initializing")
}

if err := p.Build(); err != nil {
if err := p.Build(true); err != nil {
return errors.Wrap(err, "building")
}

@@ -20,15 +20,18 @@ import (
func init() {
cmd := root.Command("deploy", "Deploy the project.").Default()
stage := cmd.Arg("stage", "Target stage name.").Default("staging").String()
noBuild := cmd.Flag("no-build", "Disable build related hooks.").Bool()

cmd.Example(`up deploy`, "Deploy to the staging environment.")
cmd.Example(`up deploy production`, "Deploy to the production environment.")
cmd.Example(`up deploy --no-build`, "Skip build hooks, useful in CI when a separate build step is used.")

cmd.Action(func(_ *kingpin.ParseContext) error {
return deploy(*stage)
return deploy(*stage, !*noBuild)
})
}

func deploy(stage string) error {
func deploy(stage string, build bool) error {
retry:
c, p, err := root.Init()

@@ -85,6 +88,7 @@ retry:
Stage: stage,
Commit: util.StripLerna(commit.Describe()),
Author: commit.Author.Name,
Build: build,
}); err != nil {
return err
}
@@ -48,6 +48,7 @@ type Deploy struct {
Stage string
Commit string
Author string
Build bool
}

// Platform is the interface for platform integration,
22 up.go
@@ -89,18 +89,24 @@ func (p *Project) RunHooks(names ...string) error {
}

// Build the project.
func (p *Project) Build() error {
func (p *Project) Build(hooks bool) error {
defer p.events.Time("platform.build", nil)()

if err := p.RunHooks("prebuild", "build"); err != nil {
return err
if hooks {
if err := p.RunHooks("prebuild", "build"); err != nil {
return err
}
}

if err := p.Platform.Build(); err != nil {
return errors.Wrap(err, "building")
}

return p.RunHooks("postbuild")
if hooks {
return p.RunHooks("postbuild")
}

return nil
}

// Deploy the project.
@@ -110,16 +116,18 @@ func (p *Project) Deploy(d Deploy) error {
"stage": d.Stage,
})()

if err := p.Build(); err != nil {
if err := p.Build(d.Build); err != nil {
return errors.Wrap(err, "building")
}

if err := p.deploy(d); err != nil {
return errors.Wrap(err, "deploying")
}

if err := p.RunHook("clean"); err != nil {
return errors.Wrap(err, "clean hook")
if d.Build {
if err := p.RunHook("clean"); err != nil {
return errors.Wrap(err, "clean hook")
}
}

return nil

0 comments on commit 8cb8229

Please sign in to comment.
You can’t perform that action at this time.