Skip to content

Commit

Permalink
Only run mypy/flake static tests for providers in main branch (#27608)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9345953)
  • Loading branch information
potiuk authored and ephraimbuddy committed Nov 11, 2022
1 parent 7477854 commit 1d22d31
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ ${{ hashFiles('.pre-commit-config.yaml') }}"
SKIP: ${{ needs.build-info.outputs.skip-pre-commits }}
COLUMNS: "250"
SKIP_GROUP_OUTPUT: "true"
DEFAULT_BRANCH: ${{ needs.build-info.outputs.default-branch }}
- name: "Fix ownership"
run: breeze ci fix-ownership
if: always()
Expand Down
8 changes: 8 additions & 0 deletions scripts/ci/pre_commit/common_precommit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
AIRFLOW_SOURCES_ROOT = Path(__file__).parents[3].resolve()


def filter_out_providers_on_non_main_branch(files: list[str]) -> list[str]:
"""When running build on non-main branch do not take providers into account"""
default_branch = os.environ.get("DEFAULT_BRANCH")
if not default_branch or default_branch == "main":
return files
return [file for file in files if not file.startswith(f"airflow{os.sep}providers")]


def insert_documentation(file_path: Path, content: list[str], header: str, footer: str):
text = file_path.read_text().splitlines(keepends=True)
replacing = False
Expand Down
11 changes: 9 additions & 2 deletions scripts/ci/pre_commit/pre_commit_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@
DRY_RUN = os.environ.get('DRY_RUN', "false")[0].lower() == "t"
os.environ['SKIP_GROUP_OUTPUT'] = "true"

if __name__ == '__main__':
if __name__ == "__main__":
sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported
from common_precommit_utils import filter_out_providers_on_non_main_branch

sys.path.insert(0, str(AIRFLOW_SOURCES / "dev" / "breeze" / "src"))
from airflow_breeze.global_constants import MOUNT_SELECTED
from airflow_breeze.utils.docker_command_utils import get_extra_docker_flags
from airflow_breeze.utils.run_utils import get_ci_image_for_pre_commits, run_command

files_to_test = filter_out_providers_on_non_main_branch(sys.argv[1:])
if not files_to_test:
print("No files to tests. Quitting")
sys.exit(0)
airflow_image = get_ci_image_for_pre_commits(verbose=VERBOSE, dry_run=DRY_RUN)
cmd_result = run_command(
[
Expand All @@ -55,7 +62,7 @@
"never",
airflow_image,
"/opt/airflow/scripts/in_container/run_flake8.sh",
*sys.argv[1:],
*files_to_test,
],
check=False,
verbose=VERBOSE,
Expand Down
11 changes: 9 additions & 2 deletions scripts/ci/pre_commit/pre_commit_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@
DRY_RUN = os.environ.get('DRY_RUN', "false")[0].lower() == "t"
os.environ['SKIP_GROUP_OUTPUT'] = "true"

if __name__ == '__main__':
if __name__ == "__main__":
sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported
from common_precommit_utils import filter_out_providers_on_non_main_branch

sys.path.insert(0, str(AIRFLOW_SOURCES / "dev" / "breeze" / "src"))
from airflow_breeze.global_constants import MOUNT_SELECTED
from airflow_breeze.utils.docker_command_utils import get_extra_docker_flags
from airflow_breeze.utils.path_utils import create_mypy_volume_if_needed
from airflow_breeze.utils.run_utils import get_ci_image_for_pre_commits, run_command

files_to_test = filter_out_providers_on_non_main_branch(sys.argv[1:])
if files_to_test == ["--namespace-packages"]:
print("No files to tests. Quitting")
sys.exit(0)
airflow_image = get_ci_image_for_pre_commits(verbose=VERBOSE, dry_run=DRY_RUN)
create_mypy_volume_if_needed()
cmd_result = run_command(
Expand All @@ -58,7 +65,7 @@
"never",
airflow_image,
"/opt/airflow/scripts/in_container/run_mypy.sh",
*sys.argv[1:],
*files_to_test,
],
check=False,
verbose=VERBOSE,
Expand Down

0 comments on commit 1d22d31

Please sign in to comment.