Skip to content

Commit 4f3cf81

Browse files
Fix runner type assignment in selective checks (apache#57254)
* Fix runner type assignment in selective checks * Update notification workflow
1 parent d750022 commit 4f3cf81

File tree

4 files changed

+76
-10
lines changed

4 files changed

+76
-10
lines changed

.github/workflows/ci-notification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
matrix:
3939
branch: ["v3-1-test"]
40-
workflow-id: ["ci-amd.yml", "ci-arm.yml"]
40+
workflow-id: ["ci-amd-arm.yml"]
4141
runs-on: ubuntu-latest
4242
steps:
4343
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"

dev/breeze/src/airflow_breeze/global_constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
PUBLIC_AMD_RUNNERS = '["ubuntu-22.04"]'
4141
PUBLIC_ARM_RUNNERS = '["ubuntu-22.04-arm"]'
4242

43-
RUNNERS_TYPE_MAPPING = {
44-
"ubuntu-22.04": '["ubuntu-22.04"]',
45-
"ubuntu-22.04-arm": '["ubuntu-22.04-arm"]',
43+
# The runner type cross-mapping is intentional — if the previous scheduled build used AMD, the current scheduled build should run with ARM.
44+
RUNNERS_TYPE_CROSS_MAPPING = {
45+
"ubuntu-22.04": '["ubuntu-22.04-arm"]',
46+
"ubuntu-22.04-arm": '["ubuntu-22.04"]',
4647
}
4748

4849
ANSWER = ""

dev/breeze/src/airflow_breeze/utils/selective_checks.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
PROVIDERS_COMPATIBILITY_TESTS_MATRIX,
4949
PUBLIC_AMD_RUNNERS,
5050
PUBLIC_ARM_RUNNERS,
51-
RUNNERS_TYPE_MAPPING,
51+
RUNNERS_TYPE_CROSS_MAPPING,
5252
TESTABLE_CORE_INTEGRATIONS,
5353
TESTABLE_PROVIDERS_INTEGRATIONS,
5454
GithubEvents,
@@ -1318,7 +1318,6 @@ def get_job_label(self, event_type: str, branch: str):
13181318
if response.status_code != 200:
13191319
get_console().print(f"[red]Error while listing workflow runs error: {response.json()}.\n")
13201320
return None
1321-
get_console().print(f"[blue]Response received for workflow run {response.json()}.\n")
13221321
runs = response.json().get("workflow_runs", [])
13231322
if not runs:
13241323
get_console().print(
@@ -1344,9 +1343,8 @@ def runner_type(self):
13441343
if self._github_event in [GithubEvents.SCHEDULE, GithubEvents.PUSH]:
13451344
branch = self._github_context_dict.get("ref_name", "main")
13461345
label = self.get_job_label(event_type=str(self._github_event.value), branch=branch)
1347-
if not label:
1348-
return PUBLIC_AMD_RUNNERS
1349-
return RUNNERS_TYPE_MAPPING[label]
1346+
1347+
return RUNNERS_TYPE_CROSS_MAPPING[label] if label else PUBLIC_AMD_RUNNERS
13501348

13511349
return PUBLIC_AMD_RUNNERS
13521350

dev/breeze/tests/test_selective_checks.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import json
2020
import re
2121
from typing import Any
22-
from unittest.mock import patch
22+
from unittest.mock import Mock, patch
2323

2424
import pytest
2525
from rich.console import Console
@@ -31,6 +31,7 @@
3131
DEFAULT_PYTHON_MAJOR_MINOR_VERSION,
3232
NUMBER_OF_LOW_DEP_SLICES,
3333
PROVIDERS_COMPATIBILITY_TESTS_MATRIX,
34+
PUBLIC_AMD_RUNNERS,
3435
GithubEvents,
3536
)
3637
from airflow_breeze.utils.functools_cache import clearable_cache
@@ -2478,3 +2479,69 @@ def test_ui_english_translation_changed_allowed_with_label():
24782479
default_branch="main",
24792480
)
24802481
assert selective_checks.ui_english_translation_changed is True
2482+
2483+
2484+
@patch("requests.get")
2485+
@patch.dict("os.environ", {"GITHUB_TOKEN": "test_token"})
2486+
def test_get_job_label(mock_get):
2487+
selective_checks = SelectiveChecks(
2488+
files=(),
2489+
github_event=GithubEvents.PULL_REQUEST,
2490+
github_repository="apache/airflow",
2491+
github_context_dict={},
2492+
)
2493+
2494+
workflow_response = Mock()
2495+
workflow_response.status_code = 200
2496+
workflow_response.json.return_value = {"workflow_runs": [{"jobs_url": "https://api.github.com/jobs/123"}]}
2497+
2498+
jobs_response = Mock()
2499+
jobs_response.json.return_value = {
2500+
"jobs": [
2501+
{"name": "Basic tests (ubuntu-22.04)", "labels": ["ubuntu-22.04"]},
2502+
{"name": "Other job", "labels": ["ubuntu-22.04"]},
2503+
]
2504+
}
2505+
2506+
mock_get.side_effect = [workflow_response, jobs_response]
2507+
2508+
result = selective_checks.get_job_label("push", "main")
2509+
2510+
assert result == "ubuntu-22.04"
2511+
2512+
2513+
def test_runner_type_pr():
2514+
selective_checks = SelectiveChecks(github_event=GithubEvents.PULL_REQUEST)
2515+
2516+
result = selective_checks.runner_type
2517+
2518+
assert result == PUBLIC_AMD_RUNNERS
2519+
2520+
2521+
@patch("requests.get")
2522+
@patch.dict("os.environ", {"GITHUB_TOKEN": "test_token"})
2523+
def test_runner_type_schedule(mock_get):
2524+
selective_checks = SelectiveChecks(
2525+
files=(),
2526+
github_event=GithubEvents.SCHEDULE,
2527+
github_repository="apache/airflow",
2528+
github_context_dict={},
2529+
)
2530+
2531+
workflow_response = Mock()
2532+
workflow_response.status_code = 200
2533+
workflow_response.json.return_value = {"workflow_runs": [{"jobs_url": "https://api.github.com/jobs/123"}]}
2534+
2535+
jobs_response = Mock()
2536+
jobs_response.json.return_value = {
2537+
"jobs": [
2538+
{"name": "Basic tests (ubuntu-22.04)", "labels": ["ubuntu-22.04"]},
2539+
{"name": "Other job", "labels": ["ubuntu-22.04"]},
2540+
]
2541+
}
2542+
2543+
mock_get.side_effect = [workflow_response, jobs_response]
2544+
2545+
result = selective_checks.runner_type
2546+
2547+
assert result == '["ubuntu-22.04-arm"]'

0 commit comments

Comments
 (0)