Skip to content

Commit 084eee2

Browse files
committed
[GitHub][CI] Add clang-tidy premerge workflow
1 parent b9e917f commit 084eee2

File tree

6 files changed

+798
-1
lines changed

6 files changed

+798
-1
lines changed

.github/workflows/issue-write.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- "Check code formatting"
77
- "Check for private emails used in PRs"
88
- "PR Request Release Note"
9+
- "Code lint"
910
types:
1011
- completed
1112

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Check code formatting"
1+
name: "Code lint"
22

33
permissions:
44
contents: read

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: "Check code formatting"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
- 'users/**'
11+
paths:
12+
- 'clang-tools-extra/clang-tidy/**'
13+
14+
jobs:
15+
code_linter:
16+
if: github.repository_owner == 'llvm'
17+
runs-on: ubuntu-24.04
18+
defaults:
19+
run:
20+
shell: bash
21+
container:
22+
image: 'ghcr.io/llvm/ci-ubuntu-24.04:latest'
23+
timeout-minutes: 60
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
steps:
28+
- name: Fetch LLVM sources
29+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
30+
with:
31+
fetch-depth: 2
32+
33+
- name: Get changed files
34+
id: changed-files
35+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
36+
with:
37+
separator: ","
38+
skip_initial_fetch: true
39+
base_sha: 'HEAD~1'
40+
sha: 'HEAD'
41+
42+
- name: Listed files
43+
env:
44+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
45+
run: |
46+
echo "Changed files:"
47+
echo "$CHANGED_FILES"
48+
49+
- name: Fetch code linting utils
50+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
51+
with:
52+
repository: ${{ github.event.pull_request.head.repo.full_name }}
53+
ref: ${{ github.event.pull_request.head.ref }}
54+
sparse-checkout: |
55+
llvm/utils/git/code-lint-helper.py
56+
llvm/utils/git/requirements_linting.txt
57+
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
58+
sparse-checkout-cone-mode: false
59+
path: code-lint-tools
60+
61+
- uses: actions/setup-python@v5
62+
id: setup_python
63+
with:
64+
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
71+
72+
- name: Install clang-tidy
73+
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
74+
with:
75+
clang-tidy: 20.1.8
76+
77+
# FIXME: create special mapping for 'gen' targets, for now build predefined set
78+
- name: Configure and Build
79+
run: |
80+
git config --global --add safe.directory '*'
81+
82+
source <(git diff --name-only HEAD~1...HEAD | python3 .ci/compute_projects.py)
83+
84+
if [[ "${projects_to_build}" == "" ]]; then
85+
echo "No projects to analyze"
86+
exit 0
87+
fi
88+
89+
cmake -G Ninja \
90+
-B build \
91+
-S llvm \
92+
-DLLVM_ENABLE_ASSERTIONS=OFF \
93+
-DLLVM_ENABLE_PROJECTS="${projects_to_build}" \
94+
-DCMAKE_CXX_COMPILER=clang++ \
95+
-DCMAKE_C_COMPILER=clang \
96+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
97+
-DLLVM_INCLUDE_TESTS=OFF \
98+
-DCLANG_INCLUDE_TESTS=OFF \
99+
-DCMAKE_BUILD_TYPE=Release
100+
101+
ninja -C build \
102+
clang-tablegen-targets \
103+
genconfusable # for "ConfusableIdentifierCheck.h"
104+
105+
- name: Run code linter
106+
env:
107+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
108+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
109+
run: |
110+
source .venv/bin/activate
111+
echo "[]" > comments &&
112+
python3 ./code-lint-tools/llvm/utils/git/code-lint-helper.py \
113+
--token ${{ secrets.GITHUB_TOKEN }} \
114+
--issue-number $GITHUB_PR_NUMBER \
115+
--start-rev HEAD~1 \
116+
--end-rev HEAD \
117+
--verbose \
118+
--changed-files "$CHANGED_FILES"
119+
120+
- name: Upload results
121+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
122+
if: always()
123+
with:
124+
name: workflow-args
125+
path: |
126+
comments

0 commit comments

Comments
 (0)