Skip to content

Commit 2585336

Browse files
authored
feat!: run-all bot command errors if anything within it errors (#3262)
1 parent 4be73f5 commit 2585336

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

sqlmesh/integrations/github/cicd/command.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _run_all(controller: GithubController) -> None:
232232
conclusion=GithubCheckConclusion.SKIPPED,
233233
skip_reason="Unit Test(s) Failed so skipping deploying to production",
234234
)
235-
return
235+
raise CICDBotError("Failed to run tests. See check status for more information.")
236236
pr_environment_updated = _update_pr_environment(controller)
237237
prod_plan_generated = False
238238
if pr_environment_updated:
@@ -241,8 +241,9 @@ def _run_all(controller: GithubController) -> None:
241241
controller.update_prod_plan_preview_check(
242242
status=GithubCheckStatus.COMPLETED, conclusion=GithubCheckConclusion.SKIPPED
243243
)
244-
if tests_passed and has_required_approval and pr_environment_updated and prod_plan_generated:
245-
_deploy_production(controller)
244+
deployed_to_prod = False
245+
if has_required_approval and prod_plan_generated:
246+
deployed_to_prod = _deploy_production(controller)
246247
elif is_auto_deploying_prod:
247248
if not has_required_approval:
248249
skip_reason = (
@@ -263,6 +264,14 @@ def _run_all(controller: GithubController) -> None:
263264
conclusion=GithubCheckConclusion.SKIPPED,
264265
skip_reason=skip_reason,
265266
)
267+
if (
268+
not pr_environment_updated
269+
or not prod_plan_generated
270+
or (has_required_approval and not deployed_to_prod)
271+
):
272+
raise CICDBotError(
273+
"A step of the run-all check failed. See check status for more information."
274+
)
266275

267276

268277
@github.command()

tests/integrations/github/cicd/test_github_commands.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
GithubCheckConclusion,
1717
GithubCheckStatus,
1818
)
19-
from sqlmesh.utils.errors import ConflictingPlanError, PlanError, TestError
19+
from sqlmesh.utils.errors import ConflictingPlanError, PlanError, TestError, CICDBotError
2020

2121
pytest_plugins = ["tests.integrations.github.cicd.fixtures"]
2222
pytestmark = [
@@ -461,7 +461,8 @@ def test_run_all_test_failed(
461461
github_output_file = tmp_path / "github_output.txt"
462462

463463
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
464-
command._run_all(controller)
464+
with pytest.raises(CICDBotError):
465+
command._run_all(controller)
465466

466467
assert "SQLMesh - Run Unit Tests" in controller._check_run_mapping
467468
test_checks_runs = controller._check_run_mapping["SQLMesh - Run Unit Tests"].all_kwargs
@@ -593,7 +594,8 @@ def test_run_all_test_exception(
593594
github_output_file = tmp_path / "github_output.txt"
594595

595596
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
596-
command._run_all(controller)
597+
with pytest.raises(CICDBotError):
598+
command._run_all(controller)
597599

598600
assert "SQLMesh - Run Unit Tests" in controller._check_run_mapping
599601
test_checks_runs = controller._check_run_mapping["SQLMesh - Run Unit Tests"].all_kwargs
@@ -727,7 +729,8 @@ def raise_on_pr_plan(plan: Plan):
727729
github_output_file = tmp_path / "github_output.txt"
728730

729731
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
730-
command._run_all(controller)
732+
with pytest.raises(CICDBotError):
733+
command._run_all(controller)
731734

732735
assert "SQLMesh - PR Environment Synced" in controller._check_run_mapping
733736
pr_checks_runs = controller._check_run_mapping["SQLMesh - PR Environment Synced"].all_kwargs
@@ -851,7 +854,8 @@ def raise_on_prod_plan(plan: Plan):
851854
github_output_file = tmp_path / "github_output.txt"
852855

853856
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
854-
command._run_all(controller)
857+
with pytest.raises(CICDBotError):
858+
command._run_all(controller)
855859

856860
assert "SQLMesh - Prod Plan Preview" in controller._check_run_mapping
857861
prod_plan_preview_checks_runs = controller._check_run_mapping[

tests/integrations/github/cicd/test_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
GithubCheckStatus,
2424
GithubController,
2525
)
26+
from sqlmesh.utils.errors import CICDBotError
2627
from tests.integrations.github.cicd.fixtures import MockIssueComment
2728

2829
pytest_plugins = ["tests.integrations.github.cicd.fixtures"]
@@ -509,7 +510,8 @@ def test_merge_pr_has_non_breaking_change_no_categorization(
509510
github_output_file = tmp_path / "github_output.txt"
510511

511512
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
512-
command._run_all(controller)
513+
with pytest.raises(CICDBotError):
514+
command._run_all(controller)
513515

514516
assert "SQLMesh - Run Unit Tests" in controller._check_run_mapping
515517
test_checks_runs = controller._check_run_mapping["SQLMesh - Run Unit Tests"].all_kwargs
@@ -1347,7 +1349,8 @@ def test_error_msg_when_applying_plan_with_bug(
13471349
github_output_file = tmp_path / "github_output.txt"
13481350

13491351
with mock.patch.dict(os.environ, {"GITHUB_OUTPUT": str(github_output_file)}):
1350-
command._run_all(controller)
1352+
with pytest.raises(CICDBotError):
1353+
command._run_all(controller)
13511354

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

0 commit comments

Comments
 (0)