Skip to content

Commit 9cbbfe8

Browse files
committed
Chore!: Update ci/cd bot default behaviour to match CLI behaviour
1 parent 61455f2 commit 9cbbfe8

File tree

6 files changed

+71
-15
lines changed

6 files changed

+71
-15
lines changed

docs/integrations/github.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ Below is an example of how to define the default config for the bot in either YA
293293
| `enable_deploy_command` | Indicates if the `/deploy` command should be enabled in order to allowed synchronized deploys to production. Default: `False` | bool | N |
294294
| `command_namespace` | The namespace to use for SQLMesh commands. For example if you provide `#SQLMesh` as a value then commands will be expected in the format of `#SQLMesh/<command>`. Default: `None` meaning no namespace is used. | string | N |
295295
| `auto_categorize_changes` | Auto categorization behavior to use for the bot. If not provided then the project-wide categorization behavior is used. See [Auto-categorize model changes](https://sqlmesh.readthedocs.io/en/stable/guides/configuration/#auto-categorize-model-changes) for details. | dict | N |
296-
| `default_pr_start` | Default start when creating PR environment plans. If running in a mode where the bot automatically backfills models (based on `auto_categorize_changes` behavior) then this can be used to limit the amount of data backfilled. Defaults to `None` meaning the start date is set to the earliest model's start or to 1 day ago if [data previews](../concepts/plans.md#data-preview) need to be computed. | str | N |
297-
| `skip_pr_backfill` | Indicates if the bot should skip backfilling models in the PR environment. Default: `True` | bool | N |
296+
| `default_pr_start` | Default start when creating PR environment plans. If running in a mode where the bot automatically backfills models (based on `auto_categorize_changes` behavior) then this can be used to limit the amount of data backfilled. Defaults to `None` meaning the start date is set to the earliest model's start or to 1 day ago if [data previews](../concepts/plans.md#data-preview) need to be computed.| str | N |
297+
| `skip_pr_backfill` | Indicates if the bot should skip backfilling models in the PR environment. Default: `False` | bool | N |
298298
| `pr_include_unmodified` | Indicates whether to include unmodified models in the PR environment. Default to the project's config value (which defaults to `False`) | bool | N |
299299
| `run_on_deploy_to_prod` | Indicates whether to run latest intervals when deploying to prod. If set to false, the deployment will backfill only the changed models up to the existing latest interval in production, ignoring any missing intervals beyond this point. Default: `False` | bool | N |
300300
| `pr_environment_name` | The name of the PR environment to create for which a PR number will be appended to. Defaults to the repo name if not provided. Note: The name will be normalized to alphanumeric + underscore and lowercase. | str | N |
301-
| `prod_branch_name` | The name of the git branch associated with production. Ex: `prod`. Default: `main` or `master` is considered prod | str | N |
301+
| `prod_branch_name` | The name of the git branch associated with production. Ex: `prod`. Default: `main` or `master` is considered prod | str | N |
302302

303303
Example with all properties defined:
304304

sqlmesh/core/config/root.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ def _normalize_identifiers(key: str) -> None:
260260

261261
return self
262262

263+
@model_validator(mode="after")
264+
def _inherit_project_config_in_cicd_bot(self) -> Self:
265+
if self.cicd_bot:
266+
# inherit the project-level settings into the CICD bot if they have not been explicitly overridden
267+
if self.cicd_bot.auto_categorize_changes_ is None:
268+
self.cicd_bot.auto_categorize_changes_ = self.plan.auto_categorize_changes
269+
270+
if self.cicd_bot.pr_include_unmodified_ is None:
271+
self.cicd_bot.pr_include_unmodified_ = self.plan.include_unmodified
272+
273+
return self
274+
263275
def get_default_test_connection(
264276
self,
265277
default_catalog: t.Optional[str] = None,

sqlmesh/integrations/github/cicd/config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ class GithubCICDBotConfig(BaseConfig):
2222
enable_deploy_command: bool = False
2323
merge_method: t.Optional[MergeMethod] = None
2424
command_namespace: t.Optional[str] = None
25-
auto_categorize_changes: CategorizerConfig = CategorizerConfig.all_off()
25+
auto_categorize_changes_: t.Optional[CategorizerConfig] = Field(
26+
default=None, alias="auto_categorize_changes"
27+
)
2628
default_pr_start: t.Optional[TimeLike] = None
27-
skip_pr_backfill: bool = True
28-
pr_include_unmodified: t.Optional[bool] = None
29+
skip_pr_backfill: bool = False # to align with the CLI default
30+
pr_include_unmodified_: t.Optional[bool] = Field(default=None, alias="pr_include_unmodified")
2931
run_on_deploy_to_prod: bool = False
3032
pr_environment_name: t.Optional[str] = None
3133
prod_branch_names_: t.Optional[str] = Field(default=None, alias="prod_branch_name")
@@ -49,6 +51,14 @@ def prod_branch_names(self) -> t.List[str]:
4951
return [self.prod_branch_names_]
5052
return ["main", "master"]
5153

54+
@property
55+
def auto_categorize_changes(self) -> CategorizerConfig:
56+
return self.auto_categorize_changes_ or CategorizerConfig.all_off()
57+
58+
@property
59+
def pr_include_unmodified(self) -> bool:
60+
return self.pr_include_unmodified_ or False
61+
5262
FIELDS_FOR_ANALYTICS: t.ClassVar[t.Set[str]] = {
5363
"invalidate_environment_after_deploy",
5464
"enable_deploy_command",

tests/core/analytics/test_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_on_cicd_command(collector: AnalyticsCollector, mocker: MockerFixture):
145145
{
146146
"seq_num": 1,
147147
"event_type": "CICD_COMMAND",
148-
"event": '{"command_name": "test_cicd", "command_args": ["arg_1", "arg_2"], "parent_command_names": ["parent_a", "parent_b"], "cicd_bot_config": {"invalidate_environment_after_deploy": true, "enable_deploy_command": false, "auto_categorize_changes": {"external": "off", "python": "off", "sql": "off", "seed": "off"}, "skip_pr_backfill": true, "run_on_deploy_to_prod": false}}',
148+
"event": '{"command_name": "test_cicd", "command_args": ["arg_1", "arg_2"], "parent_command_names": ["parent_a", "parent_b"], "cicd_bot_config": {"invalidate_environment_after_deploy": true, "enable_deploy_command": false, "skip_pr_backfill": false, "run_on_deploy_to_prod": false}}',
149149
**common_fields,
150150
}
151151
),

tests/integrations/github/cicd/test_config.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def test_load_yaml_config_default(tmp_path):
3434
assert config.cicd_bot.invalidate_environment_after_deploy
3535
assert config.cicd_bot.merge_method is None
3636
assert config.cicd_bot.command_namespace is None
37-
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
37+
assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes
3838
assert config.cicd_bot.default_pr_start is None
3939
assert not config.cicd_bot.enable_deploy_command
40-
assert config.cicd_bot.skip_pr_backfill
41-
assert config.cicd_bot.pr_include_unmodified is None
40+
assert not config.cicd_bot.skip_pr_backfill
41+
assert not config.cicd_bot.pr_include_unmodified
4242
assert config.cicd_bot.pr_environment_name is None
4343
assert config.cicd_bot.prod_branch_names == ["main", "master"]
4444

@@ -112,11 +112,11 @@ def test_load_python_config_defaults(tmp_path):
112112
assert config.cicd_bot.invalidate_environment_after_deploy
113113
assert config.cicd_bot.merge_method is None
114114
assert config.cicd_bot.command_namespace is None
115-
assert config.cicd_bot.auto_categorize_changes == CategorizerConfig.all_off()
115+
assert config.cicd_bot.auto_categorize_changes == config.plan.auto_categorize_changes
116116
assert config.cicd_bot.default_pr_start is None
117117
assert not config.cicd_bot.enable_deploy_command
118-
assert config.cicd_bot.skip_pr_backfill
119-
assert config.cicd_bot.pr_include_unmodified is None
118+
assert not config.cicd_bot.skip_pr_backfill
119+
assert not config.cicd_bot.pr_include_unmodified
120120
assert config.cicd_bot.pr_environment_name is None
121121
assert config.cicd_bot.prod_branch_names == ["main", "master"]
122122

@@ -252,3 +252,35 @@ def test_ttl_in_past(tmp_path):
252252
match="TTL '1 week' is in the past. Please specify a relative time in the future. Ex: `in 1 week` instead of `1 week`.",
253253
):
254254
load_config_from_paths(Config, project_paths=[tmp_path / "config.yaml"])
255+
256+
257+
def test_properties_inherit_from_project_config(tmp_path):
258+
(tmp_path / "config.yaml").write_text("""
259+
plan:
260+
auto_categorize_changes:
261+
external: off
262+
python: full
263+
sql: off
264+
seed: full
265+
include_unmodified: true
266+
267+
cicd_bot:
268+
type: github
269+
270+
model_defaults:
271+
dialect: duckdb
272+
""")
273+
274+
config = load_config_from_paths(Config, [tmp_path / "config.yaml"])
275+
276+
assert (
277+
config.cicd_bot.auto_categorize_changes
278+
== config.plan.auto_categorize_changes
279+
== CategorizerConfig(
280+
external=AutoCategorizationMode.OFF,
281+
python=AutoCategorizationMode.FULL,
282+
sql=AutoCategorizationMode.OFF,
283+
seed=AutoCategorizationMode.FULL,
284+
)
285+
)
286+
assert config.cicd_bot.pr_include_unmodified == config.plan.include_unmodified == True

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_pr_plan(github_client, make_controller):
223223
"tests/fixtures/github/pull_request_synchronized.json", github_client
224224
)
225225
assert controller.pr_plan.environment.name == "hello_world_2"
226-
assert controller.pr_plan.skip_backfill
226+
assert not controller.pr_plan.skip_backfill
227227
assert not controller.pr_plan.no_gaps
228228
assert not controller._context.apply.called
229229
assert controller._context._run_plan_tests.call_args == call(skip_tests=True)
@@ -241,7 +241,9 @@ def test_pr_plan_auto_categorization(github_client, make_controller):
241241
"tests/fixtures/github/pull_request_synchronized.json",
242242
github_client,
243243
bot_config=GithubCICDBotConfig(
244-
auto_categorize_changes=custom_categorizer_config, default_pr_start=default_start
244+
auto_categorize_changes=custom_categorizer_config,
245+
default_pr_start=default_start,
246+
skip_pr_backfill=True,
245247
),
246248
)
247249
assert controller.pr_plan.environment.name == "hello_world_2"

0 commit comments

Comments
 (0)