Skip to content

Commit ff64baf

Browse files
Don't run entire CI for platform specific changes
1 parent 61823a5 commit ff64baf

File tree

3 files changed

+148
-22
lines changed

3 files changed

+148
-22
lines changed

.github/workflows/build.yml

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
macOS
192192
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
193193
needs: build-context
194-
if: needs.build-context.outputs.run-tests == 'true'
194+
if: needs.build-context.outputs.run-macos == 'true'
195195
strategy:
196196
fail-fast: false
197197
matrix:
@@ -217,7 +217,7 @@ jobs:
217217
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
218218
${{ fromJSON(matrix.bolt) && '(bolt)' || '' }}
219219
needs: build-context
220-
if: needs.build-context.outputs.run-tests == 'true'
220+
if: needs.build-context.outputs.run-ubuntu == 'true'
221221
strategy:
222222
fail-fast: false
223223
matrix:
@@ -248,7 +248,7 @@ jobs:
248248
runs-on: ${{ matrix.os }}
249249
timeout-minutes: 60
250250
needs: build-context
251-
if: needs.build-context.outputs.run-tests == 'true'
251+
if: needs.build-context.outputs.run-ubuntu == 'true'
252252
strategy:
253253
fail-fast: false
254254
matrix:
@@ -304,7 +304,7 @@ jobs:
304304
runs-on: ${{ matrix.os }}
305305
timeout-minutes: 60
306306
needs: build-context
307-
if: needs.build-context.outputs.run-tests == 'true'
307+
if: needs.build-context.outputs.run-ubuntu == 'true'
308308
strategy:
309309
fail-fast: false
310310
matrix:
@@ -368,7 +368,7 @@ jobs:
368368
build-android:
369369
name: Android (${{ matrix.arch }})
370370
needs: build-context
371-
if: needs.build-context.outputs.run-tests == 'true'
371+
if: needs.build-context.outputs.run-android == 'true'
372372
timeout-minutes: 60
373373
strategy:
374374
fail-fast: false
@@ -390,7 +390,7 @@ jobs:
390390
build-ios:
391391
name: iOS
392392
needs: build-context
393-
if: needs.build-context.outputs.run-tests == 'true'
393+
if: needs.build-context.outputs.run-ios == 'true'
394394
timeout-minutes: 60
395395
runs-on: macos-15
396396
steps:
@@ -413,15 +413,15 @@ jobs:
413413
build-wasi:
414414
name: 'WASI'
415415
needs: build-context
416-
if: needs.build-context.outputs.run-tests == 'true'
416+
if: needs.build-context.outputs.run-wasi == 'true'
417417
uses: ./.github/workflows/reusable-wasi.yml
418418

419419
test-hypothesis:
420420
name: "Hypothesis tests on Ubuntu"
421421
runs-on: ubuntu-24.04
422422
timeout-minutes: 60
423423
needs: build-context
424-
if: needs.build-context.outputs.run-tests == 'true'
424+
if: needs.build-context.outputs.run-ubuntu == 'true'
425425
env:
426426
OPENSSL_VER: 3.0.18
427427
PYTHONSTRICTEXTENSIONBUILD: 1
@@ -528,7 +528,7 @@ jobs:
528528
runs-on: ${{ matrix.os }}
529529
timeout-minutes: 60
530530
needs: build-context
531-
if: needs.build-context.outputs.run-tests == 'true'
531+
if: needs.build-context.outputs.run-ubuntu == 'true'
532532
strategy:
533533
fail-fast: false
534534
matrix:
@@ -581,7 +581,7 @@ jobs:
581581
# ${{ '' } is a hack to nest jobs under the same sidebar category.
582582
name: Sanitizers${{ '' }} # zizmor: ignore[obfuscation]
583583
needs: build-context
584-
if: needs.build-context.outputs.run-tests == 'true'
584+
if: needs.build-context.outputs.run-ubuntu == 'true'
585585
strategy:
586586
fail-fast: false
587587
matrix:
@@ -606,7 +606,7 @@ jobs:
606606
runs-on: ubuntu-latest
607607
timeout-minutes: 60
608608
needs: build-context
609-
if: needs.build-context.outputs.run-tests == 'true'
609+
if: needs.build-context.outputs.run-ubuntu == 'true'
610610
steps:
611611
- uses: actions/checkout@v4
612612
with:
@@ -724,13 +724,36 @@ jobs:
724724
&& '
725725
check-autoconf-regen,
726726
check-generated-files,
727+
'
728+
|| ''
729+
}}
730+
${{
731+
!fromJSON(needs.build-context.outputs.run-windows-tests)
732+
&& '
733+
build-windows,
734+
'
735+
|| ''
736+
}}
737+
${{
738+
!fromJSON(needs.build-context.outputs.run-ci-fuzz)
739+
&& '
740+
cifuzz,
741+
'
742+
|| ''
743+
}}
744+
${{
745+
!fromJSON(needs.build-context.outputs.run-macos)
746+
&& '
727747
build-macos,
748+
'
749+
|| ''
750+
}}
751+
${{
752+
!fromJSON(needs.build-context.outputs.run-ubuntu)
753+
&& '
728754
build-ubuntu,
729755
build-ubuntu-ssltests-awslc,
730756
build-ubuntu-ssltests-openssl,
731-
build-android,
732-
build-ios,
733-
build-wasi,
734757
test-hypothesis,
735758
build-asan,
736759
build-san,
@@ -739,16 +762,23 @@ jobs:
739762
|| ''
740763
}}
741764
${{
742-
!fromJSON(needs.build-context.outputs.run-windows-tests)
765+
!fromJSON(needs.build-context.outputs.run-android)
743766
&& '
744-
build-windows,
767+
build-android,
745768
'
746769
|| ''
747770
}}
748771
${{
749-
!fromJSON(needs.build-context.outputs.run-ci-fuzz)
772+
!fromJSON(needs.build-context.outputs.run-ios)
750773
&& '
751-
cifuzz,
774+
build-ios,
775+
'
776+
|| ''
777+
}}
778+
${{
779+
!fromJSON(needs.build-context.outputs.run-wasi)
780+
&& '
781+
build-wasi,
752782
'
753783
|| ''
754784
}}

.github/workflows/reusable-context.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ on: # yamllint disable-line rule:truthy
3232
run-ci-fuzz:
3333
description: Whether to run the CIFuzz job
3434
value: ${{ jobs.compute-changes.outputs.run-ci-fuzz }} # bool
35+
run-macos:
36+
description: Whether to run the macOS tests
37+
value: ${{ jobs.compute-changes.outputs.run-macos }} # bool
38+
run-ubuntu:
39+
description: Whether to run the Ubuntu tests
40+
value: ${{ jobs.compute-changes.outputs.run-ubuntu }} # bool
41+
run-android:
42+
description: Whether to run the Android tests
43+
value: ${{ jobs.compute-changes.outputs.run-android }} # bool
44+
run-ios:
45+
description: Whether to run the iOS tests
46+
value: ${{ jobs.compute-changes.outputs.run-ios }} # bool
47+
run-wasi:
48+
description: Whether to run the WASI tests
49+
value: ${{ jobs.compute-changes.outputs.run-wasi }} # bool
3550

3651
jobs:
3752
compute-changes:
@@ -44,6 +59,11 @@ jobs:
4459
run-tests: ${{ steps.changes.outputs.run-tests }}
4560
run-windows-msi: ${{ steps.changes.outputs.run-windows-msi }}
4661
run-windows-tests: ${{ steps.changes.outputs.run-windows-tests }}
62+
run-macos: ${{ steps.changes.outputs.run-macos }}
63+
run-ubuntu: ${{ steps.changes.outputs.run-ubuntu }}
64+
run-android: ${{ steps.changes.outputs.run-android }}
65+
run-ios: ${{ steps.changes.outputs.run-ios }}
66+
run-wasi: ${{ steps.changes.outputs.run-wasi }}
4767
steps:
4868
- name: Set up Python
4969
uses: actions/setup-python@v5

Tools/build/compute-changes.py

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
SUFFIXES_C_OR_CPP = frozenset({".c", ".h", ".cpp"})
4646
SUFFIXES_DOCUMENTATION = frozenset({".rst", ".md"})
4747

48+
MACOS_DIRS = frozenset({"Mac"})
49+
IOS_DIRS = frozenset({"Apple", "iOS"})
50+
ANDROID_DIRS = frozenset({"Android"})
51+
WASI_DIRS = frozenset({Path("Tools", "wasm")})
52+
4853

4954
@dataclass(kw_only=True, slots=True)
5055
class Outputs:
@@ -53,6 +58,11 @@ class Outputs:
5358
run_tests: bool = False
5459
run_windows_msi: bool = False
5560
run_windows_tests: bool = False
61+
run_macos: bool = False
62+
run_ubuntu: bool = False
63+
run_android: bool = False
64+
run_ios: bool = False
65+
run_wasi: bool = False
5666

5767

5868
def compute_changes() -> None:
@@ -63,7 +73,15 @@ def compute_changes() -> None:
6373
outputs = process_changed_files(files)
6474
else:
6575
# Otherwise, just run the tests
66-
outputs = Outputs(run_tests=True, run_windows_tests=True)
76+
outputs = Outputs(
77+
run_tests=True,
78+
run_windows_tests=True,
79+
run_macos=True,
80+
run_ubuntu=True,
81+
run_android=True,
82+
run_ios=True,
83+
run_wasi=True,
84+
)
6785
outputs = process_target_branch(outputs, target_branch)
6886

6987
if outputs.run_tests:
@@ -111,25 +129,47 @@ def get_changed_files(
111129
return frozenset(map(Path, filter(None, map(str.strip, changed_files))))
112130

113131

132+
def is_platform_specific(file: Path) -> str | None:
133+
if not file.parts:
134+
return None
135+
first_part = file.parts[0]
136+
if first_part in MACOS_DIRS:
137+
return "macos"
138+
if first_part in IOS_DIRS:
139+
return "ios"
140+
if first_part in ANDROID_DIRS:
141+
return "android"
142+
if len(file.parts) >= 2 and Path(*file.parts[:2]) in WASI_DIRS: # Tools/wasm/
143+
return "wasi"
144+
return None
145+
146+
114147
def process_changed_files(changed_files: Set[Path]) -> Outputs:
115148
run_tests = False
116149
run_ci_fuzz = False
117150
run_docs = False
118151
run_windows_tests = False
119152
run_windows_msi = False
120153

154+
platforms_changed = set()
155+
has_non_plat_specific_change = False
156+
121157
for file in changed_files:
122158
# Documentation files
123159
doc_or_misc = file.parts[0] in {"Doc", "Misc"}
124160
doc_file = file.suffix in SUFFIXES_DOCUMENTATION or doc_or_misc
125161

126162
if file.parent == GITHUB_WORKFLOWS_PATH:
127163
if file.name == "build.yml":
128-
run_tests = run_ci_fuzz = True
164+
run_tests = run_ci_fuzz = has_non_plat_specific_change = True
129165
if file.name == "reusable-docs.yml":
130166
run_docs = True
131167
if file.name == "reusable-windows-msi.yml":
132168
run_windows_msi = True
169+
if file.name == "reusable-macos.yml":
170+
platforms_changed.add("macos")
171+
if file.name == "reusable-wasi.yml":
172+
platforms_changed.add("wasi")
133173

134174
if not (
135175
doc_file
@@ -138,8 +178,13 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
138178
):
139179
run_tests = True
140180

141-
if file not in UNIX_BUILD_SYSTEM_FILE_NAMES:
142-
run_windows_tests = True
181+
platform = is_platform_specific(file)
182+
if platform is not None:
183+
platforms_changed.add(platform)
184+
else:
185+
has_non_plat_specific_change = True
186+
if file not in UNIX_BUILD_SYSTEM_FILE_NAMES:
187+
run_windows_tests = True
143188

144189
# The fuzz tests are pretty slow so they are executed only for PRs
145190
# changing relevant files.
@@ -159,12 +204,38 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
159204
if file.parts[:2] == ("Tools", "msi"):
160205
run_windows_msi = True
161206

207+
# Check which platform specific tests to run
208+
if run_tests:
209+
if has_non_plat_specific_change or not platforms_changed:
210+
run_macos = True
211+
run_ubuntu = True
212+
run_android = True
213+
run_ios = True
214+
run_wasi = True
215+
else:
216+
run_macos = "macos" in platforms_changed
217+
run_ubuntu = False
218+
run_android = "android" in platforms_changed
219+
run_ios = "ios" in platforms_changed
220+
run_wasi = "wasi" in platforms_changed
221+
else:
222+
run_macos = False
223+
run_ubuntu = False
224+
run_android = False
225+
run_ios = False
226+
run_wasi = False
227+
162228
return Outputs(
163229
run_ci_fuzz=run_ci_fuzz,
164230
run_docs=run_docs,
165231
run_tests=run_tests,
166232
run_windows_tests=run_windows_tests,
167233
run_windows_msi=run_windows_msi,
234+
run_macos=run_macos,
235+
run_ubuntu=run_ubuntu,
236+
run_android=run_android,
237+
run_ios=run_ios,
238+
run_wasi=run_wasi,
168239
)
169240

170241

@@ -196,6 +267,11 @@ def write_github_output(outputs: Outputs) -> None:
196267
f.write(f"run-tests={bool_lower(outputs.run_tests)}\n")
197268
f.write(f"run-windows-tests={bool_lower(outputs.run_windows_tests)}\n")
198269
f.write(f"run-windows-msi={bool_lower(outputs.run_windows_msi)}\n")
270+
f.write(f"run-macos={bool_lower(outputs.run_macos)}\n")
271+
f.write(f"run-ubuntu={bool_lower(outputs.run_ubuntu)}\n")
272+
f.write(f"run-android={bool_lower(outputs.run_android)}\n")
273+
f.write(f"run-ios={bool_lower(outputs.run_ios)}\n")
274+
f.write(f"run-wasi={bool_lower(outputs.run_wasi)}\n")
199275

200276

201277
def bool_lower(value: bool, /) -> str:

0 commit comments

Comments
 (0)