Skip to content

Commit b81b109

Browse files
authored
Feat(cicd_bot): Improve output of 'PR Environment Synced' and 'Prod Plan Preview' steps (#4872)
1 parent fcfbe8f commit b81b109

File tree

5 files changed

+909
-374
lines changed

5 files changed

+909
-374
lines changed

sqlmesh/core/console.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,8 +3224,9 @@ def _print_models_with_threshold(
32243224
)
32253225
else:
32263226
for snapshot_table_info in models:
3227+
category_str = SNAPSHOT_CHANGE_CATEGORY_STR[snapshot_table_info.change_category]
32273228
self._print(
3228-
f"- `{snapshot_table_info.display_name(environment_naming_info, default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect)}`"
3229+
f"- `{snapshot_table_info.display_name(environment_naming_info, default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect)}` ({category_str})"
32293230
)
32303231

32313232
def _print_modified_models(
@@ -3237,7 +3238,7 @@ def _print_modified_models(
32373238
no_diff: bool = True,
32383239
) -> None:
32393240
directly_modified = []
3240-
indirectly_modified = []
3241+
indirectly_modified: t.List[Snapshot] = []
32413242
metadata_modified = []
32423243
for snapshot in modified_snapshots:
32433244
if context_diff.directly_modified(snapshot.name):
@@ -3249,11 +3250,40 @@ def _print_modified_models(
32493250
if directly_modified:
32503251
self._print("\n**Directly Modified:**")
32513252
for snapshot in sorted(directly_modified):
3253+
category_str = SNAPSHOT_CHANGE_CATEGORY_STR[snapshot.change_category]
32523254
self._print(
3253-
f"- `{snapshot.display_name(environment_naming_info, default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect)}`"
3255+
f"* `{snapshot.display_name(environment_naming_info, default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect)}` ({category_str})"
3256+
)
3257+
3258+
indirectly_modified_children = sorted(
3259+
[s for s in indirectly_modified if snapshot.snapshot_id in s.parents]
32543260
)
3261+
32553262
if not no_diff:
3256-
self._print(f"```diff\n{context_diff.text_diff(snapshot.name)}\n```")
3263+
diff_text = context_diff.text_diff(snapshot.name)
3264+
# sometimes there is no text_diff, like on a seed model where the data has been updated
3265+
if diff_text:
3266+
diff_text = f"\n```diff\n{diff_text}\n```"
3267+
# these are part of a Markdown list, so indent them by 2 spaces to relate them to the current list item
3268+
diff_text_indented = "\n".join(
3269+
[f" {line}" for line in diff_text.splitlines()]
3270+
)
3271+
self._print(diff_text_indented)
3272+
else:
3273+
if indirectly_modified_children:
3274+
self._print("\n")
3275+
3276+
if indirectly_modified_children:
3277+
self._print(" Indirectly Modified Children:")
3278+
for child_snapshot in indirectly_modified_children:
3279+
child_category_str = SNAPSHOT_CHANGE_CATEGORY_STR[
3280+
child_snapshot.change_category
3281+
]
3282+
self._print(
3283+
f" - `{child_snapshot.display_name(environment_naming_info, default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect)}` ({child_category_str})"
3284+
)
3285+
self._print("\n")
3286+
32573287
if indirectly_modified:
32583288
self._print("\n**Indirectly Modified:**")
32593289
self._print_models_with_threshold(

sqlmesh/integrations/github/cicd/command.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ def _update_pr_environment(controller: GithubController) -> bool:
115115
conclusion = controller.update_pr_environment_check(status=GithubCheckStatus.COMPLETED)
116116
return conclusion is not None and conclusion.is_success
117117
except Exception as e:
118+
logger.exception("Error occurred when updating PR environment")
118119
conclusion = controller.update_pr_environment_check(
119-
status=GithubCheckStatus.COMPLETED, exception=e, plan=controller.pr_plan_or_none
120+
status=GithubCheckStatus.COMPLETED,
121+
exception=e,
122+
plan=controller.pr_plan_or_none,
123+
plan_flags=controller.pr_plan_flags,
120124
)
121125
return (
122126
conclusion is not None
@@ -147,6 +151,7 @@ def _gen_prod_plan(controller: GithubController) -> bool:
147151
)
148152
return bool(plan_summary)
149153
except Exception as e:
154+
logger.exception("Error occurred generating prod plan")
150155
controller.update_prod_plan_preview_check(
151156
status=GithubCheckStatus.COMPLETED,
152157
conclusion=GithubCheckConclusion.FAILURE,
@@ -211,6 +216,8 @@ def deploy_production(ctx: click.Context) -> None:
211216

212217

213218
def _run_all(controller: GithubController) -> None:
219+
click.echo(f"SQLMesh Version: {controller.version_info}")
220+
214221
has_required_approval = False
215222
is_auto_deploying_prod = (
216223
controller.deploy_command_enabled or controller.do_required_approval_check

0 commit comments

Comments
 (0)