Skip to content

Commit 0488d00

Browse files
authored
Merge pull request #980 from Altinity/cached_builds_report
Antalya 25.6.5 Cached builds report
2 parents 0109854 + c717bcd commit 0488d00

File tree

4 files changed

+119
-8
lines changed

4 files changed

+119
-8
lines changed

.github/actions/create_workflow_report/ci_run_report.html.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
</tr>
153153
<tr>
154154
<th class="hth no-sort">Build Report</th>
155-
<td><a href="https://s3.amazonaws.com/{{ s3_bucket }}/{{ pr_number }}/{{ commit_sha }}/builds/report.html">Build Report</a></td>
155+
<td>{% for job_name, link in build_report_links.items() %}<a href="{{ link }}">[{{ job_name }}]</a> {% endfor %}</td>
156156
</tr>
157157
<tr>
158158
<th class="hth no-sort">Date</th>

.github/actions/create_workflow_report/create_workflow_report.py

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from datetime import datetime
88
from functools import lru_cache
99
from glob import glob
10+
import urllib.parse
1011

1112
import pandas as pd
1213
from jinja2 import Environment, FileSystemLoader
@@ -478,11 +479,15 @@ def format_test_name_for_linewrap(text: str) -> str:
478479

479480
def format_test_status(text: str) -> str:
480481
"""Format the test status for better readability."""
481-
color = (
482-
"red"
483-
if text.lower().startswith("fail")
484-
else "orange" if text.lower() in ("error", "broken", "pending") else "green"
485-
)
482+
if text.lower().startswith("fail"):
483+
color = "red"
484+
elif text.lower() == "skipped":
485+
color = "grey"
486+
elif text.lower() in ("success", "ok", "passed", "pass"):
487+
color = "green"
488+
else:
489+
color = "orange"
490+
486491
return f'<span style="font-weight: bold; color: {color}">{text}</span>'
487492

488493

@@ -510,6 +515,101 @@ def format_results_as_html_table(results) -> str:
510515
return html
511516

512517

518+
def backfill_skipped_statuses(
519+
job_statuses: pd.DataFrame, pr_number: int, branch: str, commit_sha: str
520+
):
521+
"""
522+
Fill in the job statuses for skipped jobs.
523+
"""
524+
525+
if pr_number == 0:
526+
ref_param = f"REF={branch}"
527+
workflow_name = "MasterCI"
528+
else:
529+
ref_param = f"PR={pr_number}"
530+
workflow_name = "PR"
531+
532+
status_file = f"result_{workflow_name.lower()}.json"
533+
s3_path = f"https://{S3_BUCKET}.s3.amazonaws.com/{ref_param.replace('=', 's/')}/{commit_sha}/{status_file}"
534+
response = requests.get(s3_path)
535+
536+
if response.status_code != 200:
537+
return job_statuses
538+
539+
status_data = response.json()
540+
skipped_jobs = []
541+
for job in status_data["results"]:
542+
if job["status"] == "skipped" and len(job["links"]) > 0:
543+
skipped_jobs.append(
544+
{
545+
"job_name": job["name"],
546+
"job_status": job["status"],
547+
"message": job["info"],
548+
"results_link": job["links"][0],
549+
}
550+
)
551+
552+
return pd.concat([job_statuses, pd.DataFrame(skipped_jobs)], ignore_index=True)
553+
554+
555+
def get_build_report_links(
556+
job_statuses: pd.DataFrame, pr_number: int, branch: str, commit_sha: str
557+
):
558+
"""
559+
Get the build report links for the given PR number, branch, and commit SHA.
560+
561+
First checks if a build job submitted a success or skipped status.
562+
If not available, it guesses the links.
563+
"""
564+
build_job_names = [
565+
"Build (amd_release)",
566+
"Build (arm_release)",
567+
"Docker server image",
568+
"Docker keeper image",
569+
]
570+
build_report_links = {}
571+
572+
for job in job_statuses.itertuples():
573+
if (
574+
job.job_name in build_job_names
575+
and job.job_status
576+
in (
577+
"success",
578+
"skipped",
579+
)
580+
and job.results_link
581+
):
582+
build_report_links[job.job_name] = job.results_link
583+
584+
if 0 < len(build_report_links) < len(build_job_names):
585+
# Only have some of the build jobs, guess the rest.
586+
# (It was straightforward to force the build jobs to always appear in the cache,
587+
# however doing the same for the docker image jobs is difficult.)
588+
ref_job, ref_link = list(build_report_links.items())[0]
589+
link_template = ref_link.replace(
590+
urllib.parse.quote(ref_job, safe=""), "{job_name}"
591+
)
592+
for job in build_job_names:
593+
if job not in build_report_links:
594+
build_report_links[job] = link_template.format(job_name=job)
595+
return build_report_links
596+
597+
# No cache or build result was found, guess the links
598+
if pr_number == 0:
599+
ref_param = f"REF={branch}"
600+
workflow_name = "MasterCI"
601+
else:
602+
ref_param = f"PR={pr_number}"
603+
workflow_name = "PR"
604+
605+
build_report_link_base = f"https://{S3_BUCKET}.s3.amazonaws.com/json.html?{ref_param}&sha={commit_sha}&name_0={urllib.parse.quote(workflow_name, safe='')}"
606+
build_report_links = {
607+
job_name: f"{build_report_link_base}&name_1={urllib.parse.quote(job_name, safe='')}"
608+
for job_name in build_job_names
609+
}
610+
return build_report_links
611+
612+
513613
def parse_args() -> argparse.Namespace:
514614
parser = argparse.ArgumentParser(description="Create a combined CI report.")
515615
parser.add_argument( # Need the full URL rather than just the ID to query the databases
@@ -626,6 +726,10 @@ def create_workflow_report(
626726
except Exception as e:
627727
pr_info_html = e
628728

729+
fail_results["job_statuses"] = backfill_skipped_statuses(
730+
fail_results["job_statuses"], pr_number, branch_name, commit_sha
731+
)
732+
629733
high_cve_count = 0
630734
if not cves_not_checked and len(fail_results["docker_images_cves"]) > 0:
631735
high_cve_count = (
@@ -666,6 +770,9 @@ def create_workflow_report(
666770
),
667771
"pr_new_fails": len(fail_results["pr_new_fails"]),
668772
},
773+
"build_report_links": get_build_report_links(
774+
fail_results["job_statuses"], pr_number, branch_name, commit_sha
775+
),
669776
"ci_jobs_status_html": format_results_as_html_table(
670777
fail_results["job_statuses"]
671778
),

ci/praktika/info.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ def get_specific_report_url(self, pr_number, branch, sha, job_name=""):
157157

158158
if pr_number:
159159
ref_param = f"PR={pr_number}"
160+
# Hotfix for bug that is fixed properly in latest upstream
161+
workflow_name = "PR"
160162
else:
161163
assert branch
162164
ref_param = f"REF={branch}"
165+
# Hotfix for bug that is fixed properly in latest upstream
166+
workflow_name = "MasterCI"
163167
path = Settings.HTML_S3_PATH
164168
for bucket, endpoint in Settings.S3_BUCKET_TO_HTTP_ENDPOINT.items():
165169
if bucket in path:
166170
path = path.replace(bucket, endpoint)
167171
break
168-
res = f"https://{path}/{Path(Settings.HTML_PAGE_FILE).name}?{ref_param}&sha={sha}&name_0={urllib.parse.quote(self.env.WORKFLOW_NAME, safe='')}"
172+
res = f"https://{path}/{Path(Settings.HTML_PAGE_FILE).name}?{ref_param}&sha={sha}&name_0={urllib.parse.quote(workflow_name, safe='')}"
169173
if job_name:
170174
res += f"&name_1={urllib.parse.quote(job_name, safe='')}"
171175
return res

ci/praktika/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Config:
5353

5454
allow_merge_on_failure: bool = False
5555

56-
enable_commit_status: bool = False
56+
enable_commit_status: bool = True
5757

5858
# If a job Result contains multiple sub-results, and only a specific sub-result should be sent to CIDB, set its name here.
5959
result_name_for_cidb: str = ""

0 commit comments

Comments
 (0)