-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Expand file tree
/
Copy pathselective_checks.py
More file actions
2224 lines (2025 loc) · 95 KB
/
Copy pathselective_checks.py
File metadata and controls
2224 lines (2025 loc) · 95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations
import difflib
import itertools
import json
import os
import re
import sys
from collections import defaultdict
from enum import Enum, auto
from functools import cached_property
from pathlib import Path
from typing import Any, TypeVar
from airflow_breeze.branch_defaults import AIRFLOW_BRANCH, DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.global_constants import (
ALL_PYTHON_MAJOR_MINOR_VERSIONS,
APACHE_AIRFLOW_GITHUB_REPOSITORY,
CI_AMD_PLATFORM,
CI_ARM_PLATFORM,
COMMITTERS,
CURRENT_KUBERNETES_VERSIONS,
CURRENT_MYSQL_VERSIONS,
CURRENT_POSTGRES_VERSIONS,
CURRENT_PYTHON_MAJOR_MINOR_VERSIONS,
DEFAULT_KUBERNETES_VERSION,
DEFAULT_MYSQL_VERSION,
DEFAULT_POSTGRES_VERSION,
DEFAULT_PYTHON_MAJOR_MINOR_VERSION,
DISABLE_TESTABLE_INTEGRATIONS_FROM_ARM,
DISABLE_TESTABLE_INTEGRATIONS_FROM_CI,
HELM_VERSION,
JAVA_SDK_VERSION,
KIND_VERSION,
NUMBER_OF_CORE_SLICES,
NUMBER_OF_LOW_DEP_SLICES,
PROVIDERS_COMPATIBILITY_TESTS_MATRIX,
PUBLIC_AMD_RUNNERS,
PUBLIC_ARM_RUNNERS,
TESTABLE_CORE_INTEGRATIONS,
TESTABLE_PROVIDERS_INTEGRATION_OWNERS,
TESTABLE_PROVIDERS_INTEGRATIONS,
GithubEvents,
SelectiveAirflowCtlTestType,
SelectiveCoreTestType,
SelectiveProvidersTestType,
SelectiveTaskSdkTestType,
SelectiveTestType,
all_helm_test_packages,
all_selective_core_test_types,
providers_test_type,
)
from airflow_breeze.utils.console import console_print, get_console
from airflow_breeze.utils.exclude_from_matrix import excluded_combos
from airflow_breeze.utils.functools_cache import clearable_cache
from airflow_breeze.utils.kubernetes_utils import get_kubernetes_python_combos
from airflow_breeze.utils.packages import get_available_distributions, get_suspended_provider_ids
from airflow_breeze.utils.path_utils import (
AIRFLOW_DEVEL_COMMON_PATH,
AIRFLOW_PROVIDERS_ROOT_PATH,
AIRFLOW_ROOT_PATH,
)
from airflow_breeze.utils.provider_dependencies import get_provider_dependencies, get_related_providers
from airflow_breeze.utils.run_utils import run_command
ALL_VERSIONS_LABEL = "all versions"
CANARY_LABEL = "canary"
DEBUG_CI_RESOURCES_LABEL = "debug ci resources"
DEFAULT_VERSIONS_ONLY_LABEL = "default versions only"
DISABLE_IMAGE_CACHE_LABEL = "disable image cache"
FORCE_PIP_LABEL = "force pip"
FULL_TESTS_NEEDED_LABEL = "full tests needed"
INCLUDE_SUCCESS_OUTPUTS_LABEL = "include success outputs"
LATEST_VERSIONS_ONLY_LABEL = "latest versions only"
NON_COMMITTER_BUILD_LABEL = "non committer build"
UPGRADE_TO_NEWER_DEPENDENCIES_LABEL = "upgrade to newer dependencies"
USE_PUBLIC_RUNNERS_LABEL = "use public runners"
ALLOW_PROVIDER_DEPENDENCY_BUMP_LABEL = "allow provider dependency bump"
SKIP_COMMON_COMPAT_CHECK_LABEL = "skip common compat check"
AREA_KUBERNETES_TESTS_LABEL = "area:kubernetes-tests"
ALL_CI_SELECTIVE_TEST_TYPES = "API Always CLI Core Other Serialization"
ALL_PROVIDERS_SELECTIVE_TEST_TYPES = (
"Providers[-amazon,google,standard] Providers[amazon] Providers[google] Providers[standard]"
)
class FileGroupForCi(Enum):
ENVIRONMENT_FILES = auto()
PYTHON_PRODUCTION_FILES = auto()
JAVASCRIPT_PRODUCTION_FILES = auto()
ALWAYS_TESTS_FILES = auto()
API_FILES = auto()
GIT_PROVIDER_FILES = auto()
STANDARD_PROVIDER_FILES = auto()
API_CODEGEN_FILES = auto()
HELM_FILES = auto()
KUSTOMIZE_OVERLAYS_FILES = auto()
DEPENDENCY_FILES = auto()
DOC_FILES = auto()
TEXT_NON_DOC_FILES = auto()
UI_FILES = auto()
SYSTEM_TEST_FILES = auto()
KUBERNETES_FILES = auto()
TASK_SDK_FILES = auto()
TASK_SDK_INTEGRATION_TEST_FILES = auto()
GO_SDK_FILES = auto()
JAVA_SDK_FILES = auto()
TS_SDK_FILES = auto()
AIRFLOW_CTL_FILES = auto()
AIRFLOW_CTL_INTEGRATION_TEST_FILES = auto()
BREEZE_INTEGRATION_TEST_FILES = auto()
REMOTE_LOGGING_E2E_SHARED_FILES = auto()
REMOTE_LOGGING_E2E_S3_FILES = auto()
REMOTE_LOGGING_E2E_ELASTICSEARCH_FILES = auto()
REMOTE_LOGGING_E2E_OPENSEARCH_FILES = auto()
EVENT_DRIVEN_E2E_FILES = auto()
JAVA_SDK_E2E_FILES = auto()
GO_SDK_E2E_FILES = auto()
OPENLINEAGE_E2E_FILES = auto()
OPENLINEAGE_E2E_COMPAT_FILES = auto()
ALL_PYPROJECT_TOML_FILES = auto()
ALL_PYTHON_FILES = auto()
ALL_SOURCE_FILES = auto()
ALL_AIRFLOW_PYTHON_FILES = auto()
ALL_AIRFLOW_CTL_PYTHON_FILES = auto()
ALL_PROVIDERS_PYTHON_FILES = auto()
ALL_PROVIDERS_DISTRIBUTION_CONFIG_FILES = auto()
ALL_DEV_PYTHON_FILES = auto()
ALL_DEVEL_COMMON_PYTHON_FILES = auto()
ALL_SCRIPTS_PYTHON_FILES = auto()
ALL_HELM_TESTS_PYTHON_FILES = auto()
ALL_AIRFLOW_E2E_TESTS_PYTHON_FILES = auto()
ALL_DOCKER_TESTS_PYTHON_FILES = auto()
ALL_KUBERNETES_TESTS_PYTHON_FILES = auto()
ALL_PROVIDER_YAML_FILES = auto()
TESTS_UTILS_FILES = auto()
ASSET_FILES = auto()
UNIT_TEST_FILES = auto()
DEVEL_TOML_FILES = auto()
SCRIPTS_FILES = auto()
UV_LOCK_FILE = auto()
PREK_FILES = auto()
KERBEROS_FILES = auto()
OTEL_FILES = auto()
CELERY_FILES = auto()
class AllProvidersSentinel:
pass
ALL_PROVIDERS_SENTINEL = AllProvidersSentinel()
T = TypeVar("T", FileGroupForCi, SelectiveTestType)
class HashableDict(dict[T, list[str]]):
def __hash__(self):
return hash(frozenset(self))
CI_FILE_GROUP_MATCHES: HashableDict[FileGroupForCi] = HashableDict(
{
FileGroupForCi.ENVIRONMENT_FILES: [
# Only workflows that actually run or configure the test suite force the full
# matrix. Non-test workflows (security scans, doc publishing, notifications,
# backporting, stale/calendar bots, …) cannot affect test outcomes, so they
# are excluded here to avoid accidental full-matrix runs.
r"^\.github/workflows/(?!("
r"asf-allowlist-check|automatic-backport|backport-cli|ci-duration-monitor|ci-notification|"
r"codeql-analysis|e2e-flaky-tests-report|milestone-tag-assistant|notify-uv-lock-conflicts|"
r"publish-docs-to-s3|recheck-old-bug-report|scheduled-verify-release-calendar|stale"
r")\.yml$)",
r"^dev/breeze/src",
r"^dev/breeze/pyproject\.toml",
r"^dev/breeze/uv\.lock",
r"^dev/(?!breeze/tests/).*\.py$",
r"^Dockerfile",
r"^scripts/ci/docker-compose",
r"^scripts/ci/kubernetes",
# NOTE: scripts/ci/prek (static-check hooks) is intentionally NOT here. prek
# hooks drive static checks, not the test matrix, so they must not force the
# full matrix. They still build the CI image via FileGroupForCi.PREK_FILES
# below (so mypy-scripts and all static checks still run).
r"^scripts/docker",
r"^scripts/in_container",
],
FileGroupForCi.BREEZE_INTEGRATION_TEST_FILES: [
r"^dev/breeze/src/.*",
r"^dev/breeze/tests/.*_integration\.py",
r"^dev/breeze/pyproject\.toml",
r"^dev/breeze/uv\.lock",
],
FileGroupForCi.REMOTE_LOGGING_E2E_SHARED_FILES: [
r"^airflow-core/src/airflow/config_templates/airflow_local_settings\.py$",
r"^airflow-core/src/airflow/logging/.*",
r"^airflow-core/src/airflow/logging_config\.py$",
r"^airflow-core/src/airflow/api_fastapi/core_api/routes/public/log\.py$",
r"^airflow-core/src/airflow/api_fastapi/core_api/datamodels/log\.py$",
r"^airflow-core/src/airflow/utils/log/.*",
r"^airflow-e2e-tests/.*",
r"^shared/logging/.*",
],
FileGroupForCi.REMOTE_LOGGING_E2E_S3_FILES: [
r"^airflow-e2e-tests/tests/airflow_e2e_tests/remote_log_tests/.*",
r"^providers/amazon/src/airflow/providers/amazon/aws/log/s3_task_handler\.py$",
],
FileGroupForCi.REMOTE_LOGGING_E2E_ELASTICSEARCH_FILES: [
r"^airflow-e2e-tests/tests/airflow_e2e_tests/remote_log_elasticsearch_tests/.*",
r"^providers/elasticsearch/.*",
],
FileGroupForCi.REMOTE_LOGGING_E2E_OPENSEARCH_FILES: [
r"^airflow-e2e-tests/tests/airflow_e2e_tests/remote_log_opensearch_tests/.*",
r"^providers/opensearch/.*",
],
FileGroupForCi.EVENT_DRIVEN_E2E_FILES: [
r"^airflow-e2e-tests/tests/airflow_e2e_tests/event_driven_tests/.*",
r"^airflow-e2e-tests/tests/airflow_e2e_tests/dags/example_event_driven\.py$",
r"^airflow-e2e-tests/docker/kafka/.*",
r"^airflow-e2e-tests/docker/kafka\.yml$",
r"^providers/apache/kafka/.*",
r"^providers/common/messaging/.*",
],
FileGroupForCi.JAVA_SDK_E2E_FILES: [
# `.md` excluded — doc-only edits do not affect the Gradle build.
r"^java-sdk/(?!.*\.md$).*",
r"^airflow-e2e-tests/tests/airflow_e2e_tests/java_sdk_tests/.*",
r"^airflow-e2e-tests/docker/java\.yml$",
r"^airflow-e2e-tests/docker/Dockerfile\.java$",
r"^task-sdk/src/airflow/sdk/coordinators/_subprocess\.py$",
r"^task-sdk/src/airflow/sdk/coordinators/java/.*",
],
FileGroupForCi.GO_SDK_E2E_FILES: [
# `.md` excluded — doc-only edits do not affect the Go build or e2e tests.
r"^go-sdk/(?!.*\.md$).*",
r"^airflow-e2e-tests/tests/airflow_e2e_tests/go_sdk_tests/.*",
r"^airflow-e2e-tests/docker/go\.yml$",
r"^task-sdk/src/airflow/sdk/coordinators/_subprocess\.py$",
r"^task-sdk/src/airflow/sdk/coordinators/executable/.*",
],
FileGroupForCi.OPENLINEAGE_E2E_FILES: [
r"^airflow-e2e-tests/tests/airflow_e2e_tests/openlineage_tests/.*",
r"^airflow-e2e-tests/docker/openlineage\.yml$",
r"^providers/openlineage/.*",
r"^providers/common/compat/.*",
r"^providers/common/io/.*",
r"^providers/common/sql/.*",
],
FileGroupForCi.OPENLINEAGE_E2E_COMPAT_FILES: [
# Only add files that affect the compat setup and do NOT already trigger the full matrix
# here. The compat workflow (.github/workflows/openlineage-e2e-compat-tests.yml) is
# intentionally absent: it matches ENVIRONMENT_FILES and so already forces full_tests.
r"^airflow-e2e-tests/tests/airflow_e2e_tests/conftest\.py$",
r"^airflow-e2e-tests/tests/airflow_e2e_tests/constants\.py$",
r"^airflow-e2e-tests/docker/openlineage-compat\.Dockerfile$",
],
FileGroupForCi.PYTHON_PRODUCTION_FILES: [
# Production Python source the runtime ships — excludes tests, docs,
# dev tooling, and generated files within those trees. Used by
# `run_python_scans` (SAST/SCA target) to decide whether the security
# scans need to run.
#
# `example_dags/` are illustrative, not shipped runtime code, so they
# are excluded from the SAST target. They are still selected for their
# own tests via the broader `ALL_AIRFLOW_PYTHON_FILES` /
# `ALL_PROVIDERS_PYTHON_FILES` groups, so excluding them here only
# affects the SAST target, not test selection. The `(?:.*/)?` covers
# both airflow-core's top-level `airflow/example_dags/` and the nested
# `providers/<name>/.../example_dags/` layout.
r"^airflow-core/src/airflow/(?!(?:.*/)?example_dags/)(?!.*/(?:openapi-gen|i18n/locales)/).*\.py$",
r"^task-sdk/src/airflow/(?!.*_generated\.py$).*\.py$",
r"^airflow-ctl/src/airflowctl/(?!.*generated\.py$).*\.py$",
r"^providers/(?:[^/]+/)+src/(?!(?:.*/)?example_dags/).*\.py$",
r"^shared/[^/]+/src/.*\.py$",
r"^pyproject\.toml$",
r"^hatch_build\.py$",
],
FileGroupForCi.JAVASCRIPT_PRODUCTION_FILES: [
# Exclude the openapi-gen tree and translation bundles — those are
# generated / data files that ride under the same prefixes but
# carry no behavioral risk and would otherwise distort the
# production-code line-count gate.
r"^airflow-core/src/airflow/(?!.*/(?:openapi-gen|i18n/locales)/).*\.[jt]sx?$",
r"^airflow-core/src/airflow/.*\.lock$",
r"^airflow-core/src/airflow/ui/(?!.*/(?:openapi-gen|i18n/locales)/).*\.yaml$",
r"^airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/.*\.yaml$",
],
FileGroupForCi.API_FILES: [
r"^airflow-core/src/airflow/api/",
r"^airflow-core/src/airflow/api_fastapi/",
r"^airflow-core/tests/unit/api/",
r"^airflow-core/tests/unit/api_fastapi/",
],
FileGroupForCi.GIT_PROVIDER_FILES: [
r"^providers/git/src/",
],
FileGroupForCi.STANDARD_PROVIDER_FILES: [
r"^providers/standard/src/",
],
FileGroupForCi.API_CODEGEN_FILES: [
r"^airflow-core/src/airflow/api_fastapi/core_api/openapi/.*generated\.yaml",
r"^clients/gen",
],
FileGroupForCi.HELM_FILES: [
r"^chart",
r"^airflow-core/src/airflow/kubernetes",
r"^airflow-core/tests/unit/kubernetes",
],
# `^chart/` (under HELM_FILES) is intentionally NOT reused
# — the overlays don't care about every chart-template edit,
# only their own files.
FileGroupForCi.KUSTOMIZE_OVERLAYS_FILES: [
r"^chart/kustomize-overlays/",
r"^chart/tests/overlay_tests/",
r"^chart/templates/",
r"^chart/files/",
r"^scripts/ci/prek/build_kustomize_overlays\.py$",
r"^dev/breeze/src/airflow_breeze/commands/kubernetes_commands\.py$",
r"^dev/breeze/src/airflow_breeze/commands/kubernetes_kustomize_commands\.py$",
r"^\.github/workflows/kustomize-overlays-tests\.yml$",
],
FileGroupForCi.DOC_FILES: [
r"^docs",
r"^devel-common/src/docs",
r"^\.github/SECURITY\.md",
r"^providers/.*/docs/",
r"^providers/.*/src/.*\.py$",
r"^providers/.*/tests/system/.*\.py$",
r"^providers-summary-docs",
r"^docker-stack-docs",
r"^chart",
r"^task-sdk/docs/",
r"^task-sdk/src/.*\.py$",
r"^task-sdk/tests/.*\.py$",
r"^airflow-core/docs/",
r"^airflow-core/src/.*\.py$",
r"^airflow-core/tests/system/.*\.py$",
r"^airflow-ctl/docs",
r"^airflow-ctl/src/.*\.py$",
r"^airflow-ctl/tests/.*\.py$",
r"^CHANGELOG\.txt",
r"^airflow-core/src/airflow/config_templates/config\.yml",
r"^chart/RELEASE_NOTES\.rst",
r"^chart/values\.schema\.json",
r"^chart/values\.json",
r"^RELEASE_NOTES\.rst",
],
FileGroupForCi.TEXT_NON_DOC_FILES: [
r"^.*\.txt",
r"^.*\.md",
],
FileGroupForCi.UI_FILES: [
r"^airflow-core/src/airflow/ui/",
r"^airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/",
],
FileGroupForCi.KUBERNETES_FILES: [
r"^chart",
r"^kubernetes-tests",
r"^providers/cncf/kubernetes/",
],
FileGroupForCi.ALL_PYTHON_FILES: [
r".*\.py$",
],
FileGroupForCi.ALL_AIRFLOW_PYTHON_FILES: [
r"^airflow-core/.*\.py$",
],
FileGroupForCi.ALL_AIRFLOW_CTL_PYTHON_FILES: [
r"^airflow-ctl/.*\.py$",
],
FileGroupForCi.ALL_PROVIDERS_PYTHON_FILES: [
r"^providers/.*\.py$",
],
FileGroupForCi.ALL_PROVIDERS_DISTRIBUTION_CONFIG_FILES: [
r"^providers/.*/pyproject\.toml$",
r"^providers/.*/provider\.yaml$",
],
FileGroupForCi.ALL_DEV_PYTHON_FILES: [
r"^dev/.*\.py$",
],
FileGroupForCi.ALL_DEVEL_COMMON_PYTHON_FILES: [
r"^devel-common/.*\.py$",
],
FileGroupForCi.ALL_SCRIPTS_PYTHON_FILES: [
r"^scripts/.*\.py$",
],
FileGroupForCi.ALL_HELM_TESTS_PYTHON_FILES: [
r"^chart/tests/.*\.py$",
],
FileGroupForCi.ALL_AIRFLOW_E2E_TESTS_PYTHON_FILES: [
r"^airflow-e2e-tests/.*\.py$",
],
FileGroupForCi.ALL_DOCKER_TESTS_PYTHON_FILES: [
r"^docker-tests/.*\.py$",
],
FileGroupForCi.ALL_KUBERNETES_TESTS_PYTHON_FILES: [
r"^kubernetes-tests/.*\.py$",
],
FileGroupForCi.ALL_SOURCE_FILES: [
r"^.pre-commit-config.yaml$",
r"^airflow-core/src/.*",
r"^airflow-core/tests/.*",
r"^airflow-ctl/src/.*",
r"^airflow-ctl/tests/.*",
r"^chart/templates/.*",
r"^providers/.*/src/.*",
r"^providers/.*/tests/.*",
r"^shared/.*\.py$",
r"^task-sdk/src/.*",
r"^task-sdk/tests/.*",
r"^devel-common/src/.*",
r"^devel-common/tests/.*",
r"^chart/tests/.*",
r"^kubernetes-tests/tests/.*",
r"^docker-tests/tests/.*",
],
FileGroupForCi.SYSTEM_TEST_FILES: [
r"^airflow-core/tests/system/",
],
FileGroupForCi.ALWAYS_TESTS_FILES: [
r"^airflow-core/tests/unit/always/",
],
FileGroupForCi.ALL_PROVIDER_YAML_FILES: [
r".*/provider\.yaml$",
],
FileGroupForCi.ALL_PYPROJECT_TOML_FILES: [
r".*pyproject\.toml$",
],
FileGroupForCi.TESTS_UTILS_FILES: [
r"^airflow-core/tests/unit/utils/",
r"^devel-common/.*\.py$",
],
FileGroupForCi.TASK_SDK_FILES: [
r"^task-sdk/src/airflow/sdk/.*\.py$",
r"^task-sdk/tests/.*\.py$",
],
FileGroupForCi.TASK_SDK_INTEGRATION_TEST_FILES: [
r"^task-sdk-integration-tests/.*\.py$",
],
FileGroupForCi.GO_SDK_FILES: [
# `.md` excluded — doc-only edits do not affect the Go build or tests, but
# everything else (go.mod, go.sum, build config) must trigger the unit tests.
r"^go-sdk/(?!.*\.md$).*",
],
FileGroupForCi.JAVA_SDK_FILES: [
# `.md` excluded — doc-only edits do not affect the Gradle build.
r"^java-sdk/(?!.*\.md$).*",
],
FileGroupForCi.TS_SDK_FILES: [
# `.md` excluded — doc-only edits do not affect the generated supervisor schema.
r"^ts-sdk/(?!.*\.md$).*",
],
FileGroupForCi.ASSET_FILES: [
r"^airflow-core/src/airflow/assets/",
r"^airflow-core/src/airflow/models/assets/",
r"^airflow-core/src/airflow/datasets/",
r"^task-sdk/src/airflow/sdk/definitions/asset/",
],
FileGroupForCi.UNIT_TEST_FILES: [
r"^airflow-core/tests/unit/",
r"^task-sdk/tests/",
r"^providers/.*/tests/unit/",
r"^dev/breeze/tests/",
r"^airflow-ctl/tests/",
],
FileGroupForCi.AIRFLOW_CTL_FILES: [
r"^airflow-ctl/src/airflowctl/.*\.py$",
r"^airflow-ctl/tests/.*\.py$",
],
FileGroupForCi.AIRFLOW_CTL_INTEGRATION_TEST_FILES: [
r"^airflow-ctl-tests/.*\.py$",
],
FileGroupForCi.DEVEL_TOML_FILES: [
r"^devel-common/pyproject\.toml$",
],
FileGroupForCi.SCRIPTS_FILES: [
r"^scripts/ci/.*\.py$",
r"^scripts/cov/.*\.py$",
r"^scripts/tools/.*\.py$",
r"^scripts/tests/.*\.py$",
],
FileGroupForCi.PREK_FILES: [
r"^scripts/ci/prek",
],
FileGroupForCi.UV_LOCK_FILE: [
r"^uv\.lock$",
],
FileGroupForCi.KERBEROS_FILES: [
r"^airflow-core/src/airflow/security/kerberos\.py$",
r"^airflow-core/src/airflow/cli/commands/kerberos_command\.py$",
],
FileGroupForCi.OTEL_FILES: [
r"^airflow-core/src/airflow/observability/.*",
r"^shared/observability/src/airflow_shared/observability/.*",
# The otel integration tests assert the exact span hierarchy that
# task_runner emits, so changes to either must exercise the integration.
r"^airflow-core/tests/integration/otel/.*",
r"^task-sdk/src/airflow/sdk/execution_time/task_runner\.py$",
],
FileGroupForCi.CELERY_FILES: [
# Core executor sources - redis is celery's broker/result backend, so the
# core "redis" integration is exercised when the executor framework changes.
r"^airflow-core/src/airflow/executors/.*",
],
}
)
# Maps each testable core integration to the file group whose change should trigger it.
# "redis" maps to celery/core-executor sources (redis is celery's broker/result backend).
TESTABLE_CORE_INTEGRATION_FILE_GROUPS = {
"kerberos": FileGroupForCi.KERBEROS_FILES,
"otel": FileGroupForCi.OTEL_FILES,
"redis": FileGroupForCi.CELERY_FILES,
}
PYTHON_OPERATOR_FILES = [
r"^providers/tests/standard/operators/test_python.py",
]
TEST_TYPE_MATCHES: HashableDict[SelectiveTestType] = HashableDict(
{
SelectiveCoreTestType.API: [
r"^airflow-core/src/airflow/api/",
r"^airflow-core/src/airflow/api_fastapi/",
r"^airflow-core/tests/unit/api/",
r"^airflow-core/tests/unit/api_fastapi/",
],
SelectiveCoreTestType.CLI: [
r"^airflow-core/src/airflow/cli/",
r"^airflow-core/tests/unit/cli/",
],
SelectiveProvidersTestType.PROVIDERS: [
r"^providers/.*/src/airflow/providers/",
r"^providers/.*/tests/",
],
SelectiveTaskSdkTestType.TASK_SDK: [
r"^task-sdk/src/",
r"^task-sdk/tests/",
],
SelectiveCoreTestType.SERIALIZATION: [
r"^airflow-core/src/airflow/serialization/",
r"^airflow-core/tests/unit/serialization/",
],
SelectiveAirflowCtlTestType.AIRFLOW_CTL: [
r"^airflow-ctl/src/",
r"^airflow-ctl/tests/",
],
}
)
def find_provider_affected(changed_file: str, include_docs: bool) -> str | None:
file_path = AIRFLOW_ROOT_PATH / changed_file
if not include_docs:
for parent_dir_path in file_path.parents:
if parent_dir_path.name == "docs" and (parent_dir_path.parent / "provider.yaml").exists():
# Skip Docs changes if include_docs is not set
return None
# Find if the path under src/system tests/tests belongs to provider or is a common code across
# multiple providers
for parent_dir_path in file_path.parents:
if parent_dir_path == AIRFLOW_PROVIDERS_ROOT_PATH:
# We have not found any provider specific path up to the root of the provider base folder
break
if parent_dir_path.is_relative_to(AIRFLOW_PROVIDERS_ROOT_PATH):
relative_path = parent_dir_path.relative_to(AIRFLOW_PROVIDERS_ROOT_PATH)
# check if this path belongs to a specific provider
if (parent_dir_path / "provider.yaml").exists():
# new providers structure
return str(relative_path).replace(os.sep, ".")
if file_path.is_relative_to(AIRFLOW_DEVEL_COMMON_PATH):
# if devel-common changes, we want to run tests for all providers, as they might start failing
return "Providers"
return None
def _match_files_with_regexps(files: tuple[str, ...], matched_files, matching_regexps):
for file in files:
if any(re.match(regexp, file) for regexp in matching_regexps):
matched_files.append(file)
def _exclude_files_with_regexps(files: tuple[str, ...], matched_files, exclude_regexps):
for file in files:
if any(re.match(regexp, file) for regexp in exclude_regexps):
if file in matched_files:
matched_files.remove(file)
@clearable_cache
def _matching_files(
files: tuple[str, ...], match_group: FileGroupForCi | SelectiveTestType, match_dict: HashableDict
) -> list[str]:
matched_files: list[str] = []
match_regexps = match_dict[match_group]
_match_files_with_regexps(files, matched_files, match_regexps)
count = len(matched_files)
if count > 0:
console_print(f"[warning]{match_group} matched {count} files.[/]")
console_print(matched_files)
else:
console_print(f"[warning]{match_group} did not match any file.[/]")
return matched_files
def _split_list(input_list, n) -> list[list[str]]:
"""
Splits input_list into exactly n sub-lists, distributing items as evenly as possible.
Note: This cannot be replaced with itertools.batched (Python 3.12+) as it creates
batches of a fixed SIZE, whereas this function creates a fixed NUMBER of groups.
Args:
input_list: List to split
n: Number of sub-lists to create (output will always have exactly n lists)
Returns:
List containing exactly n sub-lists with items distributed as evenly as possible.
Some sub-lists may be empty if n > len(input_list).
Example:
>>> _split_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
[[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
"""
it = iter(input_list)
return [
list(itertools.islice(it, i))
for i in [len(input_list) // n + (1 if x < len(input_list) % n else 0) for x in range(n)]
]
def _get_test_type_description(provider_test_types: list[str]) -> str:
if not provider_test_types:
return ""
first_provider = provider_test_types[0]
last_provider = provider_test_types[-1]
if first_provider.startswith("Providers["):
first_provider = first_provider.replace("Providers[", "").replace("]", "")
if last_provider.startswith("Providers["):
last_provider = last_provider.replace("Providers[", "").replace("]", "")
return (
f"{first_provider[:13]}...{last_provider[:13]}"
if first_provider != last_provider
else (first_provider[:29])
)
def _get_test_list_as_json(list_of_list_of_types: list[list[str]]) -> list[dict[str, str]] | None:
if len(list_of_list_of_types) == 1 and len(list_of_list_of_types[0]) == 0:
return None
return [
{"description": _get_test_type_description(list_of_types), "test_types": " ".join(list_of_types)}
for list_of_types in list_of_list_of_types
]
class SelectiveChecks:
__HASHABLE_FIELDS = {"_files", "_default_branch", "_commit_ref", "_pr_labels", "_github_event"}
def __init__(
self,
files: tuple[str, ...] = (),
default_branch=AIRFLOW_BRANCH,
default_constraints_branch=DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH,
commit_ref: str | None = None,
pr_labels: tuple[str, ...] = (),
github_event: GithubEvents = GithubEvents.PULL_REQUEST,
github_repository: str = APACHE_AIRFLOW_GITHUB_REPOSITORY,
github_actor: str = "",
github_context_dict: dict[str, Any] | None = None,
platform: str = CI_AMD_PLATFORM,
):
self._files = files
self._default_branch = default_branch
self._default_constraints_branch = default_constraints_branch
self._commit_ref = commit_ref
self._pr_labels = pr_labels
self._github_event = github_event
self._github_repository = github_repository
self._github_actor = github_actor
self._github_context_dict = github_context_dict or {}
self._platform = platform
self._new_toml: dict[str, Any] = {}
self._old_toml: dict[str, Any] = {}
def __important_attributes(self) -> tuple[Any, ...]:
return tuple(getattr(self, f) for f in self.__HASHABLE_FIELDS)
def __hash__(self):
return hash(self.__important_attributes())
def __eq__(self, other):
return isinstance(other, SelectiveChecks) and all(
[getattr(other, f) == getattr(self, f) for f in self.__HASHABLE_FIELDS]
)
def __str__(self) -> str:
from airflow_breeze.utils.github import get_ga_output
output = []
for field_name in dir(self):
if not field_name.startswith("_"):
value = getattr(self, field_name)
if value is not None:
output.append(get_ga_output(field_name, value))
return "\n".join(output)
default_postgres_version = DEFAULT_POSTGRES_VERSION
default_mysql_version = DEFAULT_MYSQL_VERSION
default_kubernetes_version = DEFAULT_KUBERNETES_VERSION
default_kind_version = KIND_VERSION
default_helm_version = HELM_VERSION
java_sdk_version = JAVA_SDK_VERSION
@cached_property
def latest_versions_only(self) -> bool:
return LATEST_VERSIONS_ONLY_LABEL in self._pr_labels
@cached_property
def default_python_version(self) -> str:
return (
CURRENT_PYTHON_MAJOR_MINOR_VERSIONS[-1]
if LATEST_VERSIONS_ONLY_LABEL in self._pr_labels
else DEFAULT_PYTHON_MAJOR_MINOR_VERSION
)
@cached_property
def default_branch(self) -> str:
return self._default_branch
@cached_property
def default_constraints_branch(self) -> str:
return self._default_constraints_branch
def _should_run_all_tests_and_versions(self) -> bool:
if self._github_event in [GithubEvents.PUSH, GithubEvents.SCHEDULE, GithubEvents.WORKFLOW_DISPATCH]:
if self.only_text_non_doc_files_changed and self._github_event == GithubEvents.PUSH:
console_print(
f"[warning]Only text non doc files changed in {self._github_event}, skip full tests[/]"
)
return False
console_print(f"[warning]Running everything because event is {self._github_event}[/]")
return True
if not self._commit_ref:
console_print("[warning]Running everything in all versions as commit is missing[/]")
return True
if self.pyproject_toml_changed:
console_print("[warning]Running everything with all versions: changed pyproject.toml[/]")
return True
return False
@cached_property
def all_versions(self) -> bool:
if DEFAULT_VERSIONS_ONLY_LABEL in self._pr_labels:
return False
if LATEST_VERSIONS_ONLY_LABEL in self._pr_labels:
return False
if ALL_VERSIONS_LABEL in self._pr_labels:
return True
if self._should_run_all_tests_and_versions():
return True
return False
@cached_property
def full_tests_needed(self) -> bool:
if self._should_run_all_tests_and_versions():
return True
if self._matching_files(
FileGroupForCi.ENVIRONMENT_FILES,
CI_FILE_GROUP_MATCHES,
):
console_print("[warning]Running full set of tests because env files changed[/]")
return True
if self._matching_files(
FileGroupForCi.API_CODEGEN_FILES,
CI_FILE_GROUP_MATCHES,
):
# Only the API *contract* changing (the generated OpenAPI spec, or the
# client generator) ripples broadly — to the UI codegen, the generated
# clients, and every consumer — so it warrants the full matrix. Plain
# API source/test edits that leave the committed spec untouched do not:
# a prek hook regenerates and verifies the spec, so an unchanged spec
# reliably means an unchanged contract. Those edits still run the `API`
# test type and the `fab` provider (via `run_api_tests`); they just no
# longer drag in the whole provider matrix.
console_print(
"[warning]Running full set of tests because the API contract "
"(generated OpenAPI spec / client generator) changed[/]"
)
return True
if self._matching_files(
FileGroupForCi.GIT_PROVIDER_FILES,
CI_FILE_GROUP_MATCHES,
):
# TODO(potiuk): remove me when we get rid of the dependency
console_print(
"[warning]Running full set of tests because git provider files changed "
"and for now we have core tests depending on them.[/]"
)
return True
if self._matching_files(
FileGroupForCi.STANDARD_PROVIDER_FILES,
CI_FILE_GROUP_MATCHES,
):
# TODO(potiuk): remove me when we get rid of the dependency
console_print(
"[warning]Running full set of tests because standard provider files changed "
"and for now we have core tests depending on them.[/]"
)
return True
if self._matching_files(
FileGroupForCi.TESTS_UTILS_FILES,
CI_FILE_GROUP_MATCHES,
):
console_print("[warning]Running full set of tests because tests/utils changed[/]")
return True
if FULL_TESTS_NEEDED_LABEL in self._pr_labels:
console_print(
"[warning]Full tests needed because "
f"label '{FULL_TESTS_NEEDED_LABEL}' is in {self._pr_labels}[/]"
)
return True
return False
@cached_property
def python_versions(self) -> list[str]:
if self.all_versions:
return CURRENT_PYTHON_MAJOR_MINOR_VERSIONS
if self.latest_versions_only:
return [CURRENT_PYTHON_MAJOR_MINOR_VERSIONS[-1]]
return [DEFAULT_PYTHON_MAJOR_MINOR_VERSION]
@cached_property
def python_versions_list_as_string(self) -> str:
return " ".join(self.python_versions)
@cached_property
def all_python_versions(self) -> list[str]:
"""
All python versions include all past python versions available in previous branches
Even if we remove them from the main version. This is needed to make sure we can cherry-pick
changes from main to the previous branch.
"""
if self.all_versions:
return ALL_PYTHON_MAJOR_MINOR_VERSIONS
if self.latest_versions_only:
return [CURRENT_PYTHON_MAJOR_MINOR_VERSIONS[-1]]
return [DEFAULT_PYTHON_MAJOR_MINOR_VERSION]
@cached_property
def all_python_versions_list_as_string(self) -> str:
return " ".join(self.all_python_versions)
@cached_property
def postgres_versions(self) -> list[str]:
if self.all_versions:
return CURRENT_POSTGRES_VERSIONS
if self.latest_versions_only:
return [CURRENT_POSTGRES_VERSIONS[-1]]
return [DEFAULT_POSTGRES_VERSION]
@cached_property
def mysql_versions(self) -> list[str]:
if self.all_versions:
return CURRENT_MYSQL_VERSIONS
if self.latest_versions_only:
return [CURRENT_MYSQL_VERSIONS[-1]]
return [DEFAULT_MYSQL_VERSION]
@cached_property
def kind_version(self) -> str:
return KIND_VERSION
@cached_property
def helm_version(self) -> str:
return HELM_VERSION
@cached_property
def postgres_exclude(self) -> list[dict[str, str]]:
if not self.all_versions:
# Only basic combination so we do not need to exclude anything
return []
return [
# Exclude all combinations that are repeating python/postgres versions
{"python-version": python_version, "backend-version": postgres_version}
for python_version, postgres_version in excluded_combos(
CURRENT_PYTHON_MAJOR_MINOR_VERSIONS, CURRENT_POSTGRES_VERSIONS
)
]
@cached_property
def mysql_exclude(self) -> list[dict[str, str]]:
if not self.all_versions:
# Only basic combination so we do not need to exclude anything
return []
return [
# Exclude all combinations that are repeating python/mysql versions
{"python-version": python_version, "backend-version": mysql_version}
for python_version, mysql_version in excluded_combos(
CURRENT_PYTHON_MAJOR_MINOR_VERSIONS, CURRENT_MYSQL_VERSIONS
)
]
@cached_property
def sqlite_exclude(self) -> list[dict[str, str]]:
return []
@cached_property
def kubernetes_versions(self) -> list[str]:
if self.all_versions:
return CURRENT_KUBERNETES_VERSIONS
if self.latest_versions_only:
return [CURRENT_KUBERNETES_VERSIONS[-1]]
return [DEFAULT_KUBERNETES_VERSION]
@cached_property
def kubernetes_versions_list_as_string(self) -> str:
return " ".join(self.kubernetes_versions)
@cached_property
def kubernetes_combos(self) -> list[str]:
python_version_array: list[str] = self.python_versions_list_as_string.split(" ")
kubernetes_version_array: list[str] = self.kubernetes_versions_list_as_string.split(" ")
combo_titles, short_combo_titles, combos = get_kubernetes_python_combos(
kubernetes_version_array, python_version_array
)
return short_combo_titles
@cached_property
def kubernetes_combos_list_as_string(self) -> str:
return " ".join(self.kubernetes_combos)
def _matching_files(
self, match_group: FileGroupForCi | SelectiveTestType, match_dict: HashableDict
) -> list[str]:
return _matching_files(self._files, match_group, match_dict)
def _should_be_run(self, source_area: FileGroupForCi) -> bool:
if self.full_tests_needed:
console_print(f"[warning]{source_area} enabled because we are running everything[/]")
return True
matched_files = self._matching_files(source_area, CI_FILE_GROUP_MATCHES)
if matched_files:
console_print(
f"[warning]{source_area} enabled because it matched {len(matched_files)} changed files[/]"
)
return True
console_print(f"[warning]{source_area} disabled because it did not match any changed files[/]")
return False
@cached_property
def run_mypy_providers(self) -> bool:
# Non-provider mypy checks run as part of regular static checks (prek hooks).
# Only provider mypy needs a separate CI job (requires the CI Docker image with breeze).
return (
self._matching_files(FileGroupForCi.ALL_PROVIDERS_PYTHON_FILES, CI_FILE_GROUP_MATCHES)
or self._matching_files(
FileGroupForCi.ALL_PROVIDERS_DISTRIBUTION_CONFIG_FILES, CI_FILE_GROUP_MATCHES
)
or self._are_all_providers_affected()
or (
self._matching_files(FileGroupForCi.DEVEL_TOML_FILES, CI_FILE_GROUP_MATCHES)
and self._default_branch == "main"
)
or self.full_tests_needed
) and self._default_branch == "main"
@cached_property
def run_python_scans(self) -> bool:
return self._should_be_run(FileGroupForCi.PYTHON_PRODUCTION_FILES)
@cached_property
def run_javascript_scans(self) -> bool:
return self._should_be_run(FileGroupForCi.JAVASCRIPT_PRODUCTION_FILES)
@cached_property
def run_api_tests(self) -> bool:
return self._should_be_run(FileGroupForCi.API_FILES)
@cached_property
def run_ol_tests(self) -> bool:
return self._should_be_run(FileGroupForCi.ASSET_FILES)