-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Generate CI runners for build matrix dynamically #483
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from packaging.version import Version | ||
|
||
CI_TARGETS_YAML = "ci-targets.yaml" | ||
CI_RUNNERS_YAML = "ci-runners.yaml" | ||
CI_EXTRA_SKIP_LABELS = ["documentation"] | ||
|
||
|
||
|
@@ -88,6 +89,7 @@ def should_include_entry(entry: dict[str, str], filters: dict[str, set[str]]) -> | |
|
||
def generate_matrix_entries( | ||
config: dict[str, Any], | ||
runners: dict[str, Any], | ||
platform_filter: Optional[str] = None, | ||
label_filters: Optional[dict[str, set[str]]] = None, | ||
) -> list[dict[str, str]]: | ||
|
@@ -103,6 +105,7 @@ def generate_matrix_entries( | |
target_triple, | ||
target_config, | ||
platform, | ||
runners, | ||
label_filters.get("directives", set()), | ||
) | ||
|
||
|
@@ -117,22 +120,50 @@ def generate_matrix_entries( | |
return matrix_entries | ||
|
||
|
||
def find_runner(runners: dict[str, Any], platform: str, arch: str) -> str: | ||
# Find a matching platform first | ||
match_platform = [ | ||
runner for runner in runners if runners[runner]["platform"] == platform | ||
] | ||
|
||
# Then, find a matching architecture | ||
match_arch = [ | ||
runner for runner in match_platform if runners[runner]["arch"] == arch | ||
] | ||
|
||
# If there's a matching architecture, use that | ||
if match_arch: | ||
return match_arch[0] | ||
|
||
# Otherwise, use the first with a matching platform | ||
if match_platform: | ||
return match_platform[0] | ||
|
||
raise RuntimeError(f"No runner found for platform {platform!r} and arch {arch!r}") | ||
|
||
|
||
def add_matrix_entries_for_config( | ||
matrix_entries: list[dict[str, str]], | ||
target_triple: str, | ||
config: dict[str, Any], | ||
platform: str, | ||
runners: dict[str, Any], | ||
directives: set[str], | ||
) -> None: | ||
python_versions = config["python_versions"] | ||
build_options = config["build_options"] | ||
arch = config["arch"] | ||
runner = find_runner(runners, platform, arch) | ||
|
||
# Create base entry that will be used for all variants | ||
base_entry = { | ||
"arch": arch, | ||
"target_triple": target_triple, | ||
"platform": platform, | ||
"runner": runner, | ||
# If `run` is in the config, use that — otherwise, default to if the | ||
# runner architecture matches the build architecture | ||
"run": str(config.get("run", runners[runner]["arch"] == arch)).lower(), | ||
} | ||
|
||
# Add optional fields if they exist | ||
|
@@ -142,8 +173,6 @@ def add_matrix_entries_for_config( | |
base_entry["libc"] = config["libc"] | ||
if "vcvars" in config: | ||
base_entry["vcvars"] = config["vcvars"] | ||
if "run" in config: | ||
base_entry["run"] = str(config["run"]).lower() | ||
|
||
if "dry-run" in directives: | ||
base_entry["dry-run"] = "true" | ||
|
@@ -191,6 +220,11 @@ def parse_args() -> argparse.Namespace: | |
"--labels", | ||
help="Comma-separated list of labels to filter by (e.g., 'platform:darwin,python:3.13,build:debug'), all must match.", | ||
) | ||
parser.add_argument( | ||
"--free-runners", | ||
action="store_true", | ||
help="If only free runners should be used.", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
|
@@ -201,9 +235,21 @@ def main() -> None: | |
with open(CI_TARGETS_YAML, "r") as f: | ||
config = yaml.safe_load(f) | ||
|
||
with open(CI_RUNNERS_YAML, "r") as f: | ||
runners = yaml.safe_load(f) | ||
|
||
# If only free runners are allowed, reduce to a subset | ||
if args.free_runners: | ||
runners = { | ||
runner: runner_config | ||
for runner, runner_config in runners.items() | ||
if runner_config.get("free") | ||
} | ||
Comment on lines
+241
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can hook this up for forks, #431 |
||
|
||
matrix = { | ||
"include": generate_matrix_entries( | ||
config, | ||
runners, | ||
args.platform, | ||
labels, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Describes the runners that the CI system can use | ||
|
||
depot-ubuntu-22.04: | ||
arch: x86_64 | ||
platform: linux | ||
free: false | ||
|
||
# TODO: Enable this runner to perform native builds for aarch64 | ||
# depot-ubuntu-22.04-arm: | ||
# arch: aarch64 | ||
# platform: linux | ||
# free: false | ||
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next, I'm going to try to enable PGO on aarch64 linux with this runner |
||
|
||
depot-macos-latest: | ||
arch: x86_64 | ||
platform: darwin | ||
free: false | ||
|
||
ubuntu-latest: | ||
arch: x86_64 | ||
platform: linux | ||
free: true | ||
|
||
macos-latest: | ||
arch: x86_64 | ||
platform: darwin | ||
free: true | ||
|
||
windows-latest-large: | ||
arch: x86_64 | ||
platform: windows | ||
free: false | ||
|
||
windows-latest: | ||
arch: x86_64 | ||
platform: windows | ||
free: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we do #431, we might not have access to the runners needed for
run
. We'll have to do something a bit more complicated for PGO targets in that case but I don't handle this here.