[llvm-branch-commits] [llvm] [CI] Make premerge_advisor_explain write comments (PR #166605)
Aiden Grossman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 6 08:57:13 PST 2025
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/166605
>From 06c030dcb4ee57be287beffd96d1b21ef1697dd4 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 5 Nov 2025 18:23:46 +0000
Subject: [PATCH 1/2] fix
Created using spr 1.3.7
---
.ci/premerge_advisor_explain.py | 34 ++++++++++++++++-----------------
.ci/utils.sh | 10 +++++-----
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/.ci/premerge_advisor_explain.py b/.ci/premerge_advisor_explain.py
index 4d840a33c3cf2..1d487af9e9ec7 100644
--- a/.ci/premerge_advisor_explain.py
+++ b/.ci/premerge_advisor_explain.py
@@ -31,22 +31,11 @@ def get_comment_id(platform: str, pr: github.PullRequest.PullRequest) -> int | N
def get_comment(
github_token: str,
pr_number: int,
- junit_objects,
- ninja_logs,
- advisor_response,
- return_code,
+ body: str,
) -> dict[str, str]:
repo = github.Github(github_token).get_repo("llvm/llvm-project")
pr = repo.get_issue(pr_number).as_pull_request()
- comment = {
- "body": generate_test_report_lib.generate_report(
- generate_test_report_lib.compute_platform_title(),
- return_code,
- junit_objects,
- ninja_logs,
- failure_explanations_list=advisor_response,
- )
- }
+ comment = {"body": body}
comment_id = get_comment_id(platform.system(), pr)
if comment_id:
comment["id"] = comment_id
@@ -59,6 +48,14 @@ def main(
pr_number: int,
return_code: int,
):
+ if return_code == 0:
+ with open("comment", "w") as comment_file_handle:
+ comment = get_comment(
+ ":white_check_mark: With the latest revision this PR passed "
+ "the premerge checks."
+ )
+ if comment["id"]:
+ json.dump([comment], comment_file_handle)
junit_objects, ninja_logs = generate_test_report_lib.load_info_from_files(
build_log_files
)
@@ -90,10 +87,13 @@ def main(
get_comment(
github_token,
pr_number,
- junit_objects,
- ninja_logs,
- advisor_response.json(),
- return_code,
+ generate_test_report_lib.generate_report(
+ generate_test_report_lib.compute_platform_title(),
+ return_code,
+ junit_objects,
+ ninja_logs,
+ failure_explanations_list=advisor_response.json(),
+ ),
)
]
with open("comment", "w") as comment_file_handle:
diff --git a/.ci/utils.sh b/.ci/utils.sh
index 72f4b04f5bf3a..91c27319f3534 100644
--- a/.ci/utils.sh
+++ b/.ci/utils.sh
@@ -33,18 +33,18 @@ function at-exit {
# If building fails there will be no results files.
shopt -s nullglob
- if [[ "$GITHUB_STEP_SUMMARY" != "" ]]; then
+ if [[ "$GITHUB_ACTIONS" != "" ]]; then
python "${MONOREPO_ROOT}"/.ci/generate_test_report_github.py \
$retcode "${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log \
>> $GITHUB_STEP_SUMMARY
+ python "${MONOREPO_ROOT}"/.ci/premerge_advisor_explain.py \
+ $(git rev-parse HEAD~1) $retcode ${{ secrets.GITHUB_TOKEN }} \
+ $GITHUB_PR_NUMBER "${BUILD_DIR}"/test-results.*.xml \
+ "${MONOREPO_ROOT}"/ninja*.log
fi
if [[ "$retcode" != "0" ]]; then
if [[ "$GITHUB_ACTIONS" != "" ]]; then
- python "${MONOREPO_ROOT}"/.ci/premerge_advisor_explain.py \
- $(git rev-parse HEAD~1) $retcode ${{ secrets.GITHUB_TOKEN }} \
- $GITHUB_PR_NUMBER "${BUILD_DIR}"/test-results.*.xml \
- "${MONOREPO_ROOT}"/ninja*.log
python "${MONOREPO_ROOT}"/.ci/premerge_advisor_upload.py \
$(git rev-parse HEAD~1) $GITHUB_RUN_NUMBER \
"${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log
>From 7e44989fceaeec33405c5368e16d999f5701a7b2 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 6 Nov 2025 16:57:02 +0000
Subject: [PATCH 2/2] docs
Created using spr 1.3.7
---
.ci/premerge_advisor_explain.py | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/.ci/premerge_advisor_explain.py b/.ci/premerge_advisor_explain.py
index 1d487af9e9ec7..08ccfb3d0e3d4 100644
--- a/.ci/premerge_advisor_explain.py
+++ b/.ci/premerge_advisor_explain.py
@@ -48,6 +48,31 @@ def main(
pr_number: int,
return_code: int,
):
+ """The main entrypoint for the script.
+
+ This function parses failures from files, requests information from the
+ premerge advisor, and may write a Github comment depending upon the output.
+ There are four different scenarios:
+ 1. There has never been a previous failure and the job passes - We do not
+ create a comment. We write out an empty file to the comment path so the
+ issue-write workflow knows not to create anything.
+ 2. There has never been a previous failure and the job fails - We create a
+ new comment containing the failure information and any possible premerge
+ advisor findings.
+ 3. There has been a previous failure and the job passes - We update the
+ existing comment by passing its ID anda passed message to the
+ issue-write workflow.
+ 4. There has been a previous failure and the job fails - We update the
+ existing comment in the same manner as above, but generate the comment
+ as if we have a failure.
+
+ Args:
+ commit_sha: The base commit SHA for this PR run.
+ build_log_files: The list of JUnit XML files and ninja logs.
+ github_token: The token to use to access the Github API.
+ pr_number: The number of the PR associated with this run.
+ return_code: The numerical return code of ninja/CMake.
+ """
if return_code == 0:
with open("comment", "w") as comment_file_handle:
comment = get_comment(
More information about the llvm-branch-commits
mailing list