|
16 | 16 |
|
17 | 17 |
|
18 | 18 | def get_build_info(service_directory: str, package_name: str) -> str: |
19 | | - """Get the build info from the build link.""" |
| 19 | + """Get the pylint build info from the CI build logs. |
| 20 | +
|
| 21 | + Parses the Azure DevOps build timeline to find the "Run Tests" task, |
| 22 | + then extracts next-pylint output for the given package from the |
| 23 | + dispatch_checks.py log format. |
| 24 | + """ |
20 | 25 | build_id = os.getenv("BUILD_BUILDID") |
21 | 26 | timeline_link = f"https://dev.azure.com/azure-sdk/internal/_apis/build/builds/{build_id}/timeline?api-version=6.0" |
22 | 27 |
|
23 | 28 | token = os.environ["SYSTEM_ACCESSTOKEN"] |
24 | 29 | AUTH_HEADERS = {"Authorization": f"Bearer {token}"} |
25 | 30 |
|
26 | 31 | try: |
27 | | - # Make the API request |
28 | 32 | response = requests.get(timeline_link, headers=AUTH_HEADERS) |
29 | 33 | response_json = json.loads(response.text) |
30 | 34 |
|
31 | 35 | for task in response_json["records"]: |
32 | | - if "Run Pylint Next" in task["name"]: |
| 36 | + if "Run Tests" in task.get("name", ""): |
33 | 37 | log_link = task["log"]["url"] + "?api-version=6.0" |
34 | | - # Get the log file from the build link |
35 | 38 | log_output = requests.get(log_link, headers=AUTH_HEADERS) |
36 | 39 | build_output = log_output.content.decode("utf-8") |
37 | | - new_output = ( |
38 | | - build_output.split( |
39 | | - f"next-pylint: commands[3]> python /mnt/vss/_work/1/s/eng/scripts/run_pylint.py -t {service_directory} --next=True" |
40 | | - )[1] |
41 | | - ).split(f"ERROR:root:{package_name} exited with linting error")[0] |
42 | | - return new_output |
| 40 | + |
| 41 | + # Extract next-pylint output from the dispatch_checks.py grouped log format |
| 42 | + group_marker = f"{package_name} :: next-pylint ::" |
| 43 | + if group_marker in build_output: |
| 44 | + section = build_output.split(group_marker, 1)[1] |
| 45 | + # The section ends at the next ##[endgroup] or the end of the log |
| 46 | + if "##[endgroup]" in section: |
| 47 | + section = section.split("##[endgroup]", 1)[0] |
| 48 | + return section.strip() |
| 49 | + |
| 50 | + return "No next-pylint output found in build logs." |
43 | 51 | except Exception as e: |
44 | 52 | logging.error(f"Exception occurred while getting build info: {e}") |
45 | 53 | return "Error getting build info" |
|
0 commit comments