Skip to content

Commit 878c50d

Browse files
committed
Merge remote-tracking branch 'origin/main' into move-test
2 parents 8fd96ec + be0aa7b commit 878c50d

File tree

249 files changed

+5999
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+5999
-1345
lines changed

.ci/all_requirements.txt

Lines changed: 192 additions & 2 deletions
Large diffs are not rendered by default.

.ci/premerge_advisor_explain.py

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,83 @@
44
"""Script for getting explanations from the premerge advisor."""
55

66
import argparse
7-
import os
87
import platform
98
import sys
9+
import json
1010

1111
import requests
12+
import github
13+
import github.PullRequest
1214

1315
import generate_test_report_lib
1416

1517
PREMERGE_ADVISOR_URL = (
1618
"http://premerge-advisor.premerge-advisor.svc.cluster.local:5000/explain"
1719
)
20+
COMMENT_TAG = "<!--PREMERGE ADVISOR COMMENT: {platform}-->"
1821

1922

20-
def main(commit_sha: str, build_log_files: list[str]):
23+
def get_comment_id(platform: str, pr: github.PullRequest.PullRequest) -> int | None:
24+
platform_comment_tag = COMMENT_TAG.format(platform=platform)
25+
for comment in pr.as_issue().get_comments():
26+
if platform_comment_tag in comment.body:
27+
return comment.id
28+
return None
29+
30+
31+
def get_comment(
32+
github_token: str,
33+
pr_number: int,
34+
body: str,
35+
) -> dict[str, str]:
36+
repo = github.Github(github_token).get_repo("llvm/llvm-project")
37+
pr = repo.get_issue(pr_number).as_pull_request()
38+
comment = {"body": body}
39+
comment_id = get_comment_id(platform.system(), pr)
40+
if comment_id:
41+
comment["id"] = comment_id
42+
43+
44+
def main(
45+
commit_sha: str,
46+
build_log_files: list[str],
47+
github_token: str,
48+
pr_number: int,
49+
return_code: int,
50+
):
51+
"""The main entrypoint for the script.
52+
53+
This function parses failures from files, requests information from the
54+
premerge advisor, and may write a Github comment depending upon the output.
55+
There are four different scenarios:
56+
1. There has never been a previous failure and the job passes - We do not
57+
create a comment. We write out an empty file to the comment path so the
58+
issue-write workflow knows not to create anything.
59+
2. There has never been a previous failure and the job fails - We create a
60+
new comment containing the failure information and any possible premerge
61+
advisor findings.
62+
3. There has been a previous failure and the job passes - We update the
63+
existing comment by passing its ID and a passed message to the
64+
issue-write workflow.
65+
4. There has been a previous failure and the job fails - We update the
66+
existing comment in the same manner as above, but generate the comment
67+
as if we have a failure.
68+
69+
Args:
70+
commit_sha: The base commit SHA for this PR run.
71+
build_log_files: The list of JUnit XML files and ninja logs.
72+
github_token: The token to use to access the Github API.
73+
pr_number: The number of the PR associated with this run.
74+
return_code: The numerical return code of ninja/CMake.
75+
"""
76+
if return_code == 0:
77+
with open("comment", "w") as comment_file_handle:
78+
comment = get_comment(
79+
":white_check_mark: With the latest revision this PR passed "
80+
"the premerge checks."
81+
)
82+
if comment["id"]:
83+
json.dump([comment], comment_file_handle)
2184
junit_objects, ninja_logs = generate_test_report_lib.load_info_from_files(
2285
build_log_files
2386
)
@@ -45,13 +108,31 @@ def main(commit_sha: str, build_log_files: list[str]):
45108
)
46109
if advisor_response.status_code == 200:
47110
print(advisor_response.json())
111+
comments = [
112+
get_comment(
113+
github_token,
114+
pr_number,
115+
generate_test_report_lib.generate_report(
116+
generate_test_report_lib.compute_platform_title(),
117+
return_code,
118+
junit_objects,
119+
ninja_logs,
120+
failure_explanations_list=advisor_response.json(),
121+
),
122+
)
123+
]
124+
with open("comment", "w") as comment_file_handle:
125+
json.dump(comments, comment_file_handle)
48126
else:
49127
print(advisor_response.reason)
50128

51129

52130
if __name__ == "__main__":
53131
parser = argparse.ArgumentParser()
54132
parser.add_argument("commit_sha", help="The base commit SHA for the test.")
133+
parser.add_argument("return_code", help="The build's return code", type=int)
134+
parser.add_argument("github_token", help="Github authentication token", type=str)
135+
parser.add_argument("pr_number", help="The PR number", type=int)
55136
parser.add_argument(
56137
"build_log_files", help="Paths to JUnit report files and ninja logs.", nargs="*"
57138
)
@@ -62,4 +143,10 @@ def main(commit_sha: str, build_log_files: list[str]):
62143
if platform.machine() == "arm64":
63144
sys.exit(0)
64145

65-
main(args.commit_sha, args.build_log_files)
146+
main(
147+
args.commit_sha,
148+
args.build_log_files,
149+
args.github_token,
150+
args.pr_number,
151+
args.return_code,
152+
)

.ci/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
junitparser==3.2.0
22
google-cloud-storage==3.3.0
3+
PyGithub==2.8.1

.ci/utils.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ function at-exit {
3333
# If building fails there will be no results files.
3434
shopt -s nullglob
3535

36-
if [[ "$GITHUB_STEP_SUMMARY" != "" ]]; then
36+
if [[ "$GITHUB_ACTIONS" != "" ]]; then
3737
python "${MONOREPO_ROOT}"/.ci/generate_test_report_github.py \
3838
$retcode "${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log \
3939
>> $GITHUB_STEP_SUMMARY
40+
python "${MONOREPO_ROOT}"/.ci/premerge_advisor_explain.py \
41+
$(git rev-parse HEAD~1) $retcode "${GITHUB_TOKEN}" \
42+
$GITHUB_PR_NUMBER "${BUILD_DIR}"/test-results.*.xml \
43+
"${MONOREPO_ROOT}"/ninja*.log
4044
fi
4145

4246
if [[ "$retcode" != "0" ]]; then
4347
if [[ "$GITHUB_ACTIONS" != "" ]]; then
44-
python "${MONOREPO_ROOT}"/.ci/premerge_advisor_explain.py \
45-
$(git rev-parse HEAD~1) "${BUILD_DIR}"/test-results.*.xml \
46-
"${MONOREPO_ROOT}"/ninja*.log
4748
python "${MONOREPO_ROOT}"/.ci/premerge_advisor_upload.py \
4849
$(git rev-parse HEAD~1) $GITHUB_RUN_NUMBER \
4950
"${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log

.github/workflows/premerge.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ jobs:
6464
- name: Build and Test
6565
timeout-minutes: 120
6666
continue-on-error: ${{ runner.arch == 'ARM64' }}
67+
env:
68+
GITHUB_TOKEN: ${{ github.token }}
69+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
6770
run: |
6871
git config --global --add safe.directory '*'
6972
@@ -153,6 +156,9 @@ jobs:
153156
timeout-minutes: 180
154157
if: ${{ steps.vars.outputs.windows-projects != '' }}
155158
shell: cmd
159+
env:
160+
GITHUB_TOKEN: ${{ github.token }}
161+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
156162
run: |
157163
call C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat -arch=amd64 -host_arch=amd64
158164
# See the comments above in the Linux job for why we define each of

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
10-
#define LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
1111

1212
#include "clang/Lex/HeaderSearchOptions.h"
1313
#include "clang/Lex/PPCallbacks.h"
@@ -144,4 +144,4 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
144144
} // namespace tooling
145145
} // namespace clang
146146

147-
#endif // LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
147+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H

clang-tools-extra/clang-tidy/FileExtensionsSet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
1111

1212
#include "llvm/ADT/SmallSet.h"
1313
#include "llvm/ADT/StringRef.h"
@@ -16,4 +16,4 @@ namespace clang::tidy {
1616
using FileExtensionsSet = llvm::SmallSet<llvm::StringRef, 5>;
1717
} // namespace clang::tidy
1818

19-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
19+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H

clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
11+
912
#include "clang/AST/ASTContext.h"
1013
#include "clang/ASTMatchers/ASTMatchFinder.h"
1114
#include <algorithm>
@@ -57,3 +60,5 @@ AST_POLYMORPHIC_MATCHER(
5760
}
5861

5962
} // namespace clang::ast_matchers
63+
64+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H

clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

@@ -31,4 +31,4 @@ class DurationAdditionCheck : public ClangTidyCheck {
3131

3232
} // namespace clang::tidy::abseil
3333

34-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
34+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H

clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

@@ -31,4 +31,4 @@ class DurationUnnecessaryConversionCheck : public ClangTidyCheck {
3131

3232
} // namespace clang::tidy::abseil
3333

34-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
34+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H

0 commit comments

Comments
 (0)