Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run mypy/flake static tests for providers in main branch #27608

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ jobs:
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
9 changes: 8 additions & 1 deletion scripts/ci/pre_commit/pre_commit_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@
os.environ["SKIP_GROUP_OUTPUT"] = "true"

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()
cmd_result = run_command(
[
Expand All @@ -52,7 +59,7 @@
"never",
airflow_image,
"/opt/airflow/scripts/in_container/run_flake8.sh",
*sys.argv[1:],
*files_to_test,
],
check=False,
)
Expand Down
9 changes: 8 additions & 1 deletion scripts/ci/pre_commit/pre_commit_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@
os.environ["SKIP_GROUP_OUTPUT"] = "true"

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()
create_mypy_volume_if_needed()
cmd_result = run_command(
Expand All @@ -55,7 +62,7 @@
"never",
airflow_image,
"/opt/airflow/scripts/in_container/run_mypy.sh",
*sys.argv[1:],
*files_to_test,
],
check=False,
)
Expand Down