Skip to content

Commit 9ef11de

Browse files
eakmanrqizeigerman
authored andcommitted
fix: cicd bot correctly surface plan errors (#4646)
1 parent b950bb3 commit 9ef11de

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

sqlmesh/integrations/github/cicd/command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ def _deploy_production(controller: GithubController) -> bool:
185185
skip_reason=str(e),
186186
)
187187
return False
188-
except PlanError:
188+
except PlanError as e:
189189
controller.update_prod_environment_check(
190-
status=GithubCheckStatus.COMPLETED, conclusion=GithubCheckConclusion.ACTION_REQUIRED
190+
status=GithubCheckStatus.COMPLETED,
191+
conclusion=GithubCheckConclusion.ACTION_REQUIRED,
192+
plan_error=e,
191193
)
192194
return False
193195
except Exception:

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ def update_prod_environment_check(
977977
status: GithubCheckStatus,
978978
conclusion: t.Optional[GithubCheckConclusion] = None,
979979
skip_reason: t.Optional[str] = None,
980+
plan_error: t.Optional[PlanError] = None,
980981
) -> None:
981982
"""
982983
Updates the status of the merge commit for the prod environment.
@@ -990,6 +991,7 @@ def conclusion_handler(
990991
GithubCheckConclusion.CANCELLED: "Cancelled deploying to prod",
991992
GithubCheckConclusion.SKIPPED: skip_reason,
992993
GithubCheckConclusion.FAILURE: "Failed to deploy to prod",
994+
GithubCheckConclusion.ACTION_REQUIRED: "Failed due to error applying plan",
993995
}
994996
title = (
995997
conclusion_to_title.get(conclusion)
@@ -1002,6 +1004,11 @@ def conclusion_handler(
10021004
summary = (
10031005
captured_errors or f"{title}\n\n**Error:**\n```\n{traceback.format_exc()}\n```"
10041006
)
1007+
elif conclusion.is_action_required:
1008+
if plan_error:
1009+
summary = f"**Plan error:**\n```\n{plan_error}\n```"
1010+
else:
1011+
summary = "Got an action required conclusion but no plan error was provided. This is unexpected."
10051012
else:
10061013
summary = "**Generated Prod Plan**\n" + self.get_plan_summary(self.prod_plan)
10071014
return conclusion, title, summary

tests/integrations/github/cicd/test_github_commands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,15 @@ def raise_on_prod_plan(plan: Plan):
884884
assert GithubCheckStatus(prod_checks_runs[1]["status"]).is_in_progress
885885
assert GithubCheckStatus(prod_checks_runs[2]["status"]).is_completed
886886
assert GithubCheckConclusion(prod_checks_runs[2]["conclusion"]) == expect_prod_sync_conclusion
887+
if expect_prod_sync_conclusion.is_action_required:
888+
assert prod_checks_runs[2]["output"]["title"] == "Failed due to error applying plan"
889+
assert (
890+
prod_checks_runs[2]["output"]["summary"]
891+
== f"""**Plan error:**
892+
```
893+
{to_raise_on_prod_plan}
894+
```"""
895+
)
887896

888897
assert "SQLMesh - Run Unit Tests" in controller._check_run_mapping
889898
test_checks_runs = controller._check_run_mapping["SQLMesh - Run Unit Tests"].all_kwargs

0 commit comments

Comments
 (0)