Skip to content

Commit b81d4d2

Browse files
committed
[GitHub][CI] Fix PR comment from boomanaiden154
1 parent 084eee2 commit b81d4d2

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

.github/workflows/pr-code-lint.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,21 @@ jobs:
5858
sparse-checkout-cone-mode: false
5959
path: code-lint-tools
6060

61-
- uses: actions/setup-python@v5
62-
id: setup_python
61+
- name: Install python
62+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
6363
with:
6464
python-version: '3.12'
65-
66-
- name: Install dependencies
67-
run: |
68-
python3 -m venv .venv
69-
source .venv/bin/activate
70-
python3 -m pip install -r code-lint-tools/llvm/utils/git/requirements_linting.txt
65+
66+
- name: Install python dependencies
67+
run: python3 -m pip install -r code-lint-tools/llvm/utils/git/requirements_linting.txt
7168

7269
- name: Install clang-tidy
7370
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
7471
with:
7572
clang-tidy: 20.1.8
7673

7774
# FIXME: create special mapping for 'gen' targets, for now build predefined set
78-
- name: Configure and Build
75+
- name: Configure and CodeGen
7976
run: |
8077
git config --global --add safe.directory '*'
8178
@@ -107,7 +104,6 @@ jobs:
107104
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
108105
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
109106
run: |
110-
source .venv/bin/activate
111107
echo "[]" > comments &&
112108
python3 ./code-lint-tools/llvm/utils/git/code-lint-helper.py \
113109
--token ${{ secrets.GITHUB_TOKEN }} \

llvm/utils/git/code-lint-helper.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
99
# ==-------------------------------------------------------------------------==#
10+
"""A helper script to run clang-tidy linter in GitHub actions
1011
11-
import argparse
12-
import os
13-
import subprocess
14-
import sys
15-
from typing import List, Optional
16-
17-
"""
1812
This script is run by GitHub actions to ensure that the code in PR's conform to
1913
the coding style of LLVM. The canonical source of this script is in the LLVM
2014
source tree under llvm/utils/git.
@@ -23,6 +17,11 @@
2317
https://llvm.org/docs/CodingStandards.html
2418
"""
2519

20+
import argparse
21+
import os
22+
import subprocess
23+
from typing import List, Optional
24+
2625

2726
class LintArgs:
2827
start_rev: str = None
@@ -54,7 +53,7 @@ def __init__(self, args: argparse.Namespace = None) -> None:
5453
def get_instructions(cpp_files: List[str]) -> str:
5554
files_str = " ".join(cpp_files)
5655
return f"""
57-
git diff -U0 origin/main..HEAD -- {files_str} |
56+
git diff -U0 origin/main...HEAD -- {files_str} |
5857
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \\
5958
-path build -p1 -quiet"""
6059

@@ -87,8 +86,8 @@ def clean_clang_tidy_output(output: str) -> Optional[str]:
8786
return None
8887

8988

89+
# TODO: Add more rules when enabling other projects to use clang-tidy in CI.
9090
def should_lint_file(filepath: str) -> bool:
91-
# For add other paths/files to this function
9291
return filepath.startswith("clang-tools-extra/clang-tidy/")
9392

9493

@@ -106,16 +105,6 @@ def filter_changed_files(changed_files: List[str]) -> List[str]:
106105
return filtered_files
107106

108107

109-
def has_clang_tidy(clang_tidy_binary: str) -> bool:
110-
cmd = [clang_tidy_binary, "--version"]
111-
proc = None
112-
try:
113-
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114-
except:
115-
return False
116-
return proc.returncode == 0
117-
118-
119108
def create_comment_text(warning: str, cpp_files: List[str]) -> str:
120109
instructions = get_instructions(cpp_files)
121110
return f"""
@@ -181,7 +170,7 @@ def run_clang_tidy(changed_files: List[str], args: LintArgs) -> Optional[str]:
181170
"git",
182171
"diff",
183172
"-U0",
184-
f"{args.start_rev}..{args.end_rev}",
173+
f"{args.start_rev}...{args.end_rev}",
185174
"--",
186175
] + changed_files
187176

@@ -315,11 +304,6 @@ def run_linter(changed_files: List[str], args: LintArgs) -> tuple[bool, Optional
315304
if args.verbose:
316305
print(f"got changed files: {changed_files}")
317306

318-
# Check for clang-tidy tool
319-
if not has_clang_tidy(args.clang_tidy_binary):
320-
print("Couldn't find C/C++ code linter: clang-tidy")
321-
sys.exit(1)
322-
323307
if args.verbose:
324308
print("running linter clang-tidy")
325309

0 commit comments

Comments
 (0)