Files
rocm-systems/.github/scripts/azure_resolve_subtree_deps.py
T
amd-hsivasun c16b06a7d7 [Ex CI] Enable aqlprofile (#1002)
* [Ex CI] Enable aqlprofile

* [Ex CI] Added PipelineID for aqlprofile
2025-09-26 14:00:41 -04:00

110 خطوط
3.8 KiB
Python

#!/usr/bin/env python3
"""
Azure Pipeline Resolver Script
------------------------------
This script determines which Azure pipelines to run based on changed subtrees.
Using a predefined dependency map, the script resolves which projects need to be processed,
skipping those that will be covered by their dependencies.
Steps:
1. Load a list of changed projects from a file.
2. Consult a dependency map to determine transitive and direct dependencies.
3. Identify projects that should be processed, excluding those handled by dependencies.
4. Output the list of projects to be run, along with their Azure pipeline IDs.
Arguments:
--subtree-file : Path to the file containing a newline-separated list of changed subtrees.
Outputs:
Prints a newline-separated list of "project_name=definition_id" for the projects that need
to be processed, where `definition_id` is the Azure pipeline ID associated with the project.
Example Usage:
To determine which pipelines to run given the changed subtrees listed in a file:
python azure_pipeline_resolver.py --subtree-file changed_subtrees.txt
"""
import argparse
from typing import List, Optional
def parse_arguments(argv: Optional[List[str]] = None) -> argparse.Namespace:
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(
description="Given a list of changed subtrees, determine which Azure pipelines to run."
)
parser.add_argument(
"--subtree-file",
required=True,
help="Path to the file containing changed subtrees",
)
return parser.parse_args(argv)
def read_file_into_set(file_path):
"""Reads the project names from the file into a set."""
with open(file_path, "r") as file:
return {line.strip() for line in file}
def resolve_dependencies(projects, dependencies):
"""Resolves projects to be run by checking all levels of dependencies."""
def has_dependency(project, projects_set):
"""Recursively checks if a project has any dependencies in the projects_set."""
if project not in dependencies:
return False
for dependency in dependencies[project]:
if dependency in projects_set or has_dependency(dependency, projects_set):
return True
return False
projects_to_run = set(projects)
for project in projects:
if has_dependency(project, projects_to_run):
projects_to_run.discard(project)
return projects_to_run
def main(argv=None) -> None:
"""Main function to process the projects and output those to be run."""
# Systems build+test dependency tree as defined in Azure CI and TheRock
systems_dependencies = {
"projects/clr": {"projects/hip"},
"projects/hip": {"projects/hipother"},
}
# Azure pipeline IDs for each project, to be populated as projects are enabled
definition_ids = {
"projects/aqlprofile": 365,
"projects/clr": 335,
"projects/hip-tests": 362,
"projects/hip": 335,
"projects/hipother": 335,
"projects/rdc": 360,
"projects/rocm-core": 349,
"projects/rocm-smi-lib": 358,
"projects/rocminfo": 356,
"projects/rocprofiler-compute": 344,
"projects/rocprofiler-register": 327,
"projects/rocprofiler-sdk": 347,
"projects/rocprofiler-systems": 345,
"projects/rocprofiler": 329,
"projects/rocr-runtime": 354,
"projects/roctracer": 331,
}
args = parse_arguments(argv)
projects = read_file_into_set(args.subtree_file)
projects_to_run = resolve_dependencies(projects, systems_dependencies)
for project in projects_to_run:
if project in definition_ids:
print(f"{project}={definition_ids[project]}")
if __name__ == "__main__":
main()