From 8ce4699b12eb23147044444c77d709552a9808a9 Mon Sep 17 00:00:00 2001 From: Jacek Hojczak Date: Thu, 27 Dec 2018 14:03:42 +0100 Subject: [PATCH] Return code 0 with flag 'ignore-no-changes'. --- command/deploy.go | 4 +++- command/plan.go | 4 +++- levant/plan.go | 18 +++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/command/deploy.go b/command/deploy.go index 6584e70c..06db7505 100644 --- a/command/deploy.go +++ b/command/deploy.go @@ -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) diff --git a/command/plan.go b/command/plan.go index 0567447e..4099fcef 100644 --- a/command/plan.go +++ b/command/plan.go @@ -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 diff --git a/levant/plan.go b/levant/plan.go index 202777d6..7c4dd191 100644 --- a/levant/plan.go +++ b/levant/plan.go @@ -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 @@ -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) }