Skip to content

Commit 63ff5a2

Browse files
authored
Ensure workflow status failure if command fails in backendless mode (#1760)
Fixes #1658 Error handling in backendless mode was incorrect, resulting in the workflow exit status to be success even if the command execution failed. This patch addresses this issue. The following are some additional notes of this fix: - When `allAppliesSuccessful` is false, we need to call `ReportErrorAndExit()` to ensure that the workflow fails with a non-zero exit status. - Since `ReportErrorAndExit()` invokes `os.Exit()` immediately, it should be called after setting the status of the pull request. - Contrary to intuition, `atLeastOneApply` is counted even if plan command, so we need to use `scheduler.IsPlanJobs()` to determine if the current workflow is plan or apply.
1 parent bc9d12f commit 63ff5a2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

cli/pkg/github/github.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,14 @@ func GitHubCI(lock core_locking.Lock, policyCheckerProvider core_policy.PolicyCh
276276
jobs = digger.SortedCommandsByDependency(jobs, &dependencyGraph)
277277

278278
allAppliesSuccessful, atLeastOneApply, err := digger.RunJobs(jobs, &githubPrService, &githubPrService, lock, reporter, planStorage, policyChecker, comment_updater.NoopCommentUpdater{}, backendApi, "", false, false, "0", currentDir)
279-
if err != nil {
280-
usage.ReportErrorAndExit(githubActor, fmt.Sprintf("Failed to run commands. %s", err), 8)
279+
if !allAppliesSuccessful || err != nil {
281280
// aggregate status checks: failure
282-
if allAppliesSuccessful {
283-
if atLeastOneApply {
284-
githubPrService.SetStatus(prNumber, "failure", "digger/apply")
285-
} else {
286-
githubPrService.SetStatus(prNumber, "failure", "digger/plan")
287-
}
281+
if scheduler.IsPlanJobs(jobs) {
282+
githubPrService.SetStatus(prNumber, "failure", "digger/plan")
283+
} else {
284+
githubPrService.SetStatus(prNumber, "failure", "digger/apply")
288285
}
286+
usage.ReportErrorAndExit(githubActor, fmt.Sprintf("Failed to run commands. %s", err), 8)
289287
}
290288

291289
if diggerConfig.AutoMerge && allAppliesSuccessful && atLeastOneApply && coversAllImpactedProjects {
@@ -295,10 +293,10 @@ func GitHubCI(lock core_locking.Lock, policyCheckerProvider core_policy.PolicyCh
295293

296294
if allAppliesSuccessful {
297295
// aggreate status checks: success
298-
if atLeastOneApply {
299-
githubPrService.SetStatus(prNumber, "success", "digger/apply")
300-
} else {
296+
if scheduler.IsPlanJobs(jobs) {
301297
githubPrService.SetStatus(prNumber, "success", "digger/plan")
298+
} else {
299+
githubPrService.SetStatus(prNumber, "success", "digger/apply")
302300
}
303301
}
304302

0 commit comments

Comments
 (0)