Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 8ce4699

Browse files
author
Jacek Hojczak
committed
Return code 0 with flag 'ignore-no-changes'.
1 parent 3e65564 commit 8ce4699

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

command/deploy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ func (c *DeployCommand) Run(args []string) int {
181181
Template: config.Template,
182182
}
183183

184-
planSuccess := levant.TriggerPlan(&p)
184+
planSuccess, changes := levant.TriggerPlan(&p)
185185
if !planSuccess {
186186
return 1
187+
} else if !changes && p.Plan.IgnoreNoChanges {
188+
return 0
187189
}
188190

189191
success := levant.TriggerDeployment(config, nil)

command/plan.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ func (c *PlanCommand) Run(args []string) int {
131131
return 1
132132
}
133133

134-
success := levant.TriggerPlan(config)
134+
success, changes := levant.TriggerPlan(config)
135135
if !success {
136136
return 1
137+
} else if !changes && config.Plan.IgnoreNoChanges {
138+
return 0
137139
}
138140

139141
return 0

levant/plan.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ func newPlan(config *PlanConfig) (*levantPlan, error) {
4343
}
4444

4545
// TriggerPlan initiates a Levant plan run.
46-
func TriggerPlan(config *PlanConfig) bool {
46+
func TriggerPlan(config *PlanConfig) (bool, bool) {
4747

4848
lp, err := newPlan(config)
4949
if err != nil {
5050
log.Error().Err(err).Msg("levant/plan: unable to setup Levant plan")
51-
return false
51+
return false, false
5252
}
5353

5454
changes, err := lp.plan()
5555
if err != nil {
5656
log.Error().Err(err).Msg("levant/plan: error when running plan")
57-
return false
57+
return false, changes
5858
}
5959

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

67-
return true
67+
return true, changes
6868
}
6969

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

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

98-
// If there are changes, run the planDiff function which is responsible for
99-
// iterating through the plan and logging all the planned changes.
98+
// If there are changes, run the planDiff function which is responsible for
99+
// iterating through the plan and logging all the planned changes.
100100
case diffTypeEdited:
101101
planDiff(resp.Diff)
102102
}

0 commit comments

Comments
 (0)