Skip to content

Commit

Permalink
Fix handling of GitHub Event types for new selective checks (#24665)
Browse files Browse the repository at this point in the history
One more finding after merging the selective checks in Python
- I missed a case of "pull_request_target".

Fixed and added more tests.
  • Loading branch information
potiuk authored Jun 26, 2022
1 parent e83e7c8 commit 37ab8fc
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/commands/ci_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def selective_check(
from airflow_breeze.utils.selective_checks import SelectiveChecks

github_event = GithubEvents(github_event_name)
if github_event == GithubEvents.PULL_REQUEST:
if commit_ref is not None:
changed_files = get_changed_files(commit_ref=commit_ref, dry_run=dry_run, verbose=verbose)
else:
changed_files = ()
Expand Down
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/global_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class GithubEvents(Enum):
PULL_REQUEST = "pull_request"
PULL_REQUEST_REVIEW = "pull_request_review"
PULL_REQUEST_TARGET = "pull_request_target"
PULL_REQUEST_WORKFLOW = "pull_request_workflow"
PUSH = "push"
SCHEDULE = "schedule"
WORKFLOW_RUN = "workflow_run"
Expand Down
90 changes: 86 additions & 4 deletions dev/breeze/tests/test_selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_expected_output_full_tests_needed(
"upgrade-to-newer-dependencies": "false",
"test-types": "",
},
id="Everything should run when full tests are needed even if no files are changed",
id="Nothing should run if only non-important files changed",
),
pytest.param(
(
Expand Down Expand Up @@ -371,6 +371,76 @@ def test_expected_output_pull_request_v2_3(
assert_outputs_are_printed(expected_outputs, str(sc))


@pytest.mark.parametrize(
"files, expected_outputs,",
[
pytest.param(
("INTHEWILD.md",),
{
"all-python-versions": "['3.7']",
"all-python-versions-list-as-string": "3.7",
"image-build": "false",
"needs-helm-tests": "false",
"run-tests": "false",
"docs-build": "false",
"upgrade-to-newer-dependencies": "false",
"test-types": "",
},
id="Nothing should run if only non-important files changed",
),
pytest.param(
(
"airflow/cli/test.py",
"chart/aaaa.txt",
"tests/providers/google/file.py",
),
{
"all-python-versions": "['3.7']",
"all-python-versions-list-as-string": "3.7",
"image-build": "true",
"needs-helm-tests": "true",
"run-tests": "true",
"docs-build": "true",
"run-kubernetes-tests": "true",
"upgrade-to-newer-dependencies": "false",
"test-types": "Always CLI",
},
id="CLI tests and Kubernetes tests should run if cli/chart files changed",
),
pytest.param(
(
"airflow/file.py",
"tests/providers/google/file.py",
),
{
"all-python-versions": "['3.7']",
"all-python-versions-list-as-string": "3.7",
"image-build": "true",
"needs-helm-tests": "false",
"run-tests": "true",
"docs-build": "true",
"run-kubernetes-tests": "false",
"upgrade-to-newer-dependencies": "false",
"test-types": "API Always CLI Core Integration Other Providers WWW",
},
id="All tests except should run if core file changed",
),
],
)
def test_expected_output_pull_request_target(
files: Tuple[str, ...],
expected_outputs: Dict[str, str],
):
sc = SelectiveChecks(
files=files,
commit_ref="HEAD",
github_event=GithubEvents.PULL_REQUEST_TARGET,
pr_labels=(),
default_branch="main",
)
assert_outputs_are_printed(expected_outputs, str(sc))


@pytest.mark.parametrize(
"files, pr_labels, default_branch, expected_outputs,",
[
Expand Down Expand Up @@ -441,11 +511,21 @@ def test_expected_output_push(
assert_outputs_are_printed(expected_outputs, str(sc))


def test_no_commit_provided():
@pytest.mark.parametrize(
"github_event",
[
GithubEvents.PUSH,
GithubEvents.PULL_REQUEST,
GithubEvents.PULL_REQUEST_TARGET,
GithubEvents.PULL_REQUEST_WORKFLOW,
GithubEvents.SCHEDULE,
],
)
def test_no_commit_provided_trigger_full_build_for_any_event_type(github_event):
sc = SelectiveChecks(
files=(),
commit_ref="",
github_event=GithubEvents.PULL_REQUEST,
github_event=github_event,
pr_labels=(),
default_branch="main",
)
Expand All @@ -457,7 +537,9 @@ def test_no_commit_provided():
"needs-helm-tests": "true",
"run-tests": "true",
"docs-build": "true",
"upgrade-to-newer-dependencies": "false",
"upgrade-to-newer-dependencies": "true"
if github_event in [GithubEvents.PUSH, GithubEvents.SCHEDULE]
else "false",
"test-types": "API Always CLI Core Integration Other Providers WWW",
},
str(sc),
Expand Down
2 changes: 1 addition & 1 deletion images/breeze/output-commands-hash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# This file is automatically generated by pre-commit. If you have a conflict with this file
# Please do not solve it but run `breeze regenerate-command-images`.
# This command should fix the conflict and regenerate help images that you have conflict with.
b669c8a210166579c58f904d9984d739
db93ba3ceb45327f208f9ebb6e5d3644
Loading

0 comments on commit 37ab8fc

Please sign in to comment.