Skip to content

Commit

Permalink
Return code 0 with flag 'ignore-no-changes'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Hojczak committed Dec 27, 2018
1 parent 3e65564 commit 8ce4699
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ func (c *DeployCommand) Run(args []string) int {
Template: config.Template,
}

planSuccess := levant.TriggerPlan(&p)
planSuccess, changes := levant.TriggerPlan(&p)
if !planSuccess {
return 1
} else if !changes && p.Plan.IgnoreNoChanges {
return 0
}

success := levant.TriggerDeployment(config, nil)
Expand Down
4 changes: 3 additions & 1 deletion command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ func (c *PlanCommand) Run(args []string) int {
return 1
}

success := levant.TriggerPlan(config)
success, changes := levant.TriggerPlan(config)
if !success {
return 1
} else if !changes && config.Plan.IgnoreNoChanges {
return 0
}

return 0
Expand Down
18 changes: 9 additions & 9 deletions levant/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ func newPlan(config *PlanConfig) (*levantPlan, error) {
}

// TriggerPlan initiates a Levant plan run.
func TriggerPlan(config *PlanConfig) bool {
func TriggerPlan(config *PlanConfig) (bool, bool) {

lp, err := newPlan(config)
if err != nil {
log.Error().Err(err).Msg("levant/plan: unable to setup Levant plan")
return false
return false, false
}

changes, err := lp.plan()
if err != nil {
log.Error().Err(err).Msg("levant/plan: error when running plan")
return false
return false, changes
}

if !changes && lp.config.Plan.IgnoreNoChanges {
log.Info().Msg("levant/plan: no changes found in job but ignore-changes flag set to true")
} else if !changes && !lp.config.Plan.IgnoreNoChanges {
log.Info().Msg("levant/plan: no changes found in job")
return false
return false, changes
}

return true
return true, changes
}

// plan is the entry point into running the Levant plan function which logs all
Expand All @@ -89,14 +89,14 @@ func (lp *levantPlan) plan() (bool, error) {
log.Info().Msg("levant/plan: job is a new addition to the cluster")
return true, nil

// If there are no changes, then log an error so the user can see this and
// exit the deployment.
// If there are no changes, then log an error so the user can see this and
// exit the deployment.
case diffTypeNone:
log.Error().Msg("levant/plan: no changes detected for job")
return false, nil

// If there are changes, run the planDiff function which is responsible for
// iterating through the plan and logging all the planned changes.
// If there are changes, run the planDiff function which is responsible for
// iterating through the plan and logging all the planned changes.
case diffTypeEdited:
planDiff(resp.Diff)
}
Expand Down

0 comments on commit 8ce4699

Please sign in to comment.