Skip to content

Commit

Permalink
Fix selective checks when only pyproject.toml changes (apache#43088)
Browse files Browse the repository at this point in the history
In case only pyproject.toml changes we should automatically build
CI image as we need to run full set of static checks - including
mypy and other tools.

This change triggers ci-image for such case and it also fixes
a subtle bug where "pyproject_toml_changed" was always set
to true (but nothing depended on it, because we are checking if
build dependencies changed in pyproject.toml to trigger full build
as most of the build logic and dependencies is in hatch_build.py

The change first now attempts to see if the pyprject.toml
changed at all (i.e. if pyprooject.toml is in the list of files
that are changed in the commit) and only then reads the content
of old and new version of pyproject.toml to compare them. This
will make selective checks a bit faster as it won't run two git
commands when pyproject.toml has not changed.

Also tests_common are now added to "all sources" group which
should trigger tests when only tests_common change.
  • Loading branch information
potiuk authored Oct 16, 2024
1 parent b7007e2 commit 4cdbc38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def __hash__(self):
r"^task_sdk/src/",
r"^task_sdk/tests/",
r"^tests",
r"^tests_common",
r"^kubernetes_tests",
],
FileGroupForCi.SYSTEM_TEST_FILES: [
Expand Down Expand Up @@ -732,11 +733,21 @@ def needs_helm_tests(self) -> bool:

@cached_property
def run_tests(self) -> bool:
# we should run all test
return self._should_be_run(FileGroupForCi.ALL_SOURCE_FILES)

@cached_property
def ci_image_build(self) -> bool:
return self.run_tests or self.docs_build or self.run_kubernetes_tests or self.needs_helm_tests
# in case pyproject.toml changed, CI image should be built - even if no build dependencies
# changes because some of our tests - those that need CI image might need to be run depending on
# changed rules for static checks that are part of the pyproject.toml file
return (
self.run_tests
or self.docs_build
or self.run_kubernetes_tests
or self.needs_helm_tests
or self.pyproject_toml_changed
)

@cached_property
def prod_image_build(self) -> bool:
Expand Down Expand Up @@ -937,6 +948,8 @@ def pyproject_toml_changed(self) -> bool:
if not self._commit_ref:
get_console().print("[warning]Cannot determine pyproject.toml changes as commit is missing[/]")
return False
if "pyproject.toml" not in self._files:
return False
new_result = run_command(
["git", "show", f"{self._commit_ref}:pyproject.toml"],
capture_output=True,
Expand Down
9 changes: 9 additions & 0 deletions dev/breeze/tests/test_selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ def assert_outputs_are_printed(expected_outputs: dict[str, str], stderr: str):
id="No tests on simple change",
)
),
(
pytest.param(
("pyproject.toml",),
{
"ci-image-build": "true",
},
id="CI image build and when pyproject.toml change",
)
),
(
pytest.param(
("airflow/api/file.py",),
Expand Down

0 comments on commit 4cdbc38

Please sign in to comment.