Merge pull request #64459 from ClickHouse/ci_fix_build_report_priority

CI: fix build_report selection in case of job reuse
This commit is contained in:
Max K 2024-05-27 16:06:05 +00:00 committed by GitHub
commit 4bca858c7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -401,30 +401,40 @@ class BuildResult:
@classmethod
def load_any(cls, build_name: str, pr_number: int, head_ref: str): # type: ignore
"""
loads report from suitable report file with the following priority:
1. report from PR with the same @pr_number
2. report from branch with the same @head_ref
3. report from the master
4. any other report
loads build report from one of all available report files (matching the job digest)
with the following priority:
1. report for the current PR @pr_number (might happen in PR' wf with or without job reuse)
2. report for the current branch @head_ref (might happen in release/master' wf with or without job reuse)
3. report for master branch (might happen in any workflow in case of job reuse)
4. any other report (job reuse from another PR, if master report is not available yet)
"""
reports = []
pr_report = None
ref_report = None
master_report = None
any_report = None
for file in Path(REPORT_PATH).iterdir():
if f"{build_name}.json" in file.name:
reports.append(file)
if not reports:
return None
file_path = None
for file in reports:
if pr_number and f"_{pr_number}_" in file.name:
file_path = file
break
if f"_{head_ref}_" in file.name:
file_path = file
break
any_report = file
if "_master_" in file.name:
file_path = file
break
return cls.load_from_file(file_path or reports[-1])
master_report = file
elif f"_{head_ref}_" in file.name:
ref_report = file
elif pr_number and f"_{pr_number}_" in file.name:
pr_report = file
if not any_report:
return None
if pr_report:
file_path = pr_report
elif ref_report:
file_path = ref_report
elif master_report:
file_path = master_report
else:
file_path = any_report
return cls.load_from_file(file_path)
@classmethod
def load_from_file(cls, file: Union[Path, str]): # type: ignore