From 252c171dfeafabf513edc649c4d8d10be0520dd8 Mon Sep 17 00:00:00 2001 From: Brian Crant <17074379+bcrant@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:36:42 -0800 Subject: [PATCH 1/3] Prevent CI/CD bot from deploying then erroring before merging if PR missing CODEOWNERS approval, this is breaking synchronous deployments. --- sqlmesh/integrations/github/cicd/controller.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sqlmesh/integrations/github/cicd/controller.py b/sqlmesh/integrations/github/cicd/controller.py index dd5ee70e76..5c2c0e4881 100644 --- a/sqlmesh/integrations/github/cicd/controller.py +++ b/sqlmesh/integrations/github/cicd/controller.py @@ -773,6 +773,11 @@ def deploy_to_prod(self) -> None: "PR is already merged and this event was triggered prior to the merge." ) merge_status = self._get_merge_state_status() + if merge_status.is_blocked: + raise CICDBotError( + "Merge commit cannot be cleanly created. Likely missing CODEOWNERS approval. " + "Please check PR and resolve any issues." + ) if merge_status.is_dirty: raise CICDBotError( "Merge commit cannot be cleanly created. Likely from a merge conflict. " From 2665c7166557fdbe7716b11e3fbac753a75b3410 Mon Sep 17 00:00:00 2001 From: Brian Crant <17074379+bcrant@users.noreply.github.com> Date: Tue, 11 Nov 2025 15:51:37 -0800 Subject: [PATCH 2/3] Add test. --- .../github/cicd/test_github_controller.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/integrations/github/cicd/test_github_controller.py b/tests/integrations/github/cicd/test_github_controller.py index 8242d697b6..6ae81e8c36 100644 --- a/tests/integrations/github/cicd/test_github_controller.py +++ b/tests/integrations/github/cicd/test_github_controller.py @@ -460,6 +460,21 @@ def test_deploy_to_prod_merge_error(github_client, make_controller): controller.deploy_to_prod() +def test_deploy_to_prod_blocked_pr(github_client, make_controller): + mock_pull_request = github_client.get_repo().get_pull() + mock_pull_request.merged = False + controller = make_controller( + "tests/fixtures/github/pull_request_synchronized.json", + github_client, + merge_state_status=MergeStateStatus.BLOCKED, + ) + with pytest.raises( + Exception, + match=r"^Merge commit cannot be cleanly created. Likely missing CODEOWNERS approval.*", + ): + controller.deploy_to_prod() + + def test_deploy_to_prod_dirty_pr(github_client, make_controller): mock_pull_request = github_client.get_repo().get_pull() mock_pull_request.merged = False @@ -468,7 +483,10 @@ def test_deploy_to_prod_dirty_pr(github_client, make_controller): github_client, merge_state_status=MergeStateStatus.DIRTY, ) - with pytest.raises(Exception, match=r"^Merge commit cannot be cleanly created.*"): + with pytest.raises( + Exception, + match=r"^Merge commit cannot be cleanly created. Likely from a merge conflict.*", + ): controller.deploy_to_prod() From cb25da169b11a7567ac3fb002a1d98d58e4a9cb5 Mon Sep 17 00:00:00 2001 From: Brian Crant <17074379+bcrant@users.noreply.github.com> Date: Tue, 2 Dec 2025 23:40:16 -0800 Subject: [PATCH 3/3] Update exception message and corresponding test. --- sqlmesh/integrations/github/cicd/controller.py | 2 +- tests/integrations/github/cicd/test_github_controller.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlmesh/integrations/github/cicd/controller.py b/sqlmesh/integrations/github/cicd/controller.py index 5c2c0e4881..d7a9ef8eb8 100644 --- a/sqlmesh/integrations/github/cicd/controller.py +++ b/sqlmesh/integrations/github/cicd/controller.py @@ -775,7 +775,7 @@ def deploy_to_prod(self) -> None: merge_status = self._get_merge_state_status() if merge_status.is_blocked: raise CICDBotError( - "Merge commit cannot be cleanly created. Likely missing CODEOWNERS approval. " + "Branch protection or ruleset requirement is likely not satisfied, e.g. missing CODEOWNERS approval. " "Please check PR and resolve any issues." ) if merge_status.is_dirty: diff --git a/tests/integrations/github/cicd/test_github_controller.py b/tests/integrations/github/cicd/test_github_controller.py index 6ae81e8c36..1e114171a3 100644 --- a/tests/integrations/github/cicd/test_github_controller.py +++ b/tests/integrations/github/cicd/test_github_controller.py @@ -470,7 +470,7 @@ def test_deploy_to_prod_blocked_pr(github_client, make_controller): ) with pytest.raises( Exception, - match=r"^Merge commit cannot be cleanly created. Likely missing CODEOWNERS approval.*", + match=r"^Branch protection or ruleset requirement is likely not satisfied, e.g. missing CODEOWNERS approval.*", ): controller.deploy_to_prod()