Skip to content

Commit 0e5f373

Browse files
authored
[Github][CIR] Add CI/CD for clang tidy [1/N] (#1917)
Part of #1912 This PR only fixes 1 file. Also added a CI file to see if it'd run correctly
1 parent 8dd5e0c commit 0e5f373

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Clang CIR clang-tidy linting
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- 'main'
11+
paths:
12+
- 'clang/lib/CIR/FrontendAction/**'
13+
- '.github/workflows/clang-cir-lint.yml'
14+
pull_request:
15+
branches:
16+
- main
17+
- 'users/**'
18+
paths:
19+
- 'clang/lib/CIR/FrontendAction/**'
20+
- '.github/workflows/clang-cir-lint.yml'
21+
22+
concurrency:
23+
# Skip intermediate builds: always.
24+
# Cancel intermediate builds: only if it is a pull request build.
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
27+
28+
jobs:
29+
code_linter:
30+
if: github.repository_owner == 'llvm'
31+
runs-on: ubuntu-24.04
32+
steps:
33+
- name: Fetch LLVM sources
34+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
35+
with:
36+
fetch-depth: 2
37+
38+
- name: Get changed files that triggers rerun
39+
id: changed-files
40+
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
41+
with:
42+
files: |
43+
.github/workflows/clang-cir-lint.yml
44+
clang/lib/CIR/FrontendAction/**
45+
separator: ","
46+
skip_initial_fetch: true
47+
base_sha: 'HEAD~1'
48+
sha: 'HEAD'
49+
50+
- name: Listed files
51+
env:
52+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
53+
run: |
54+
echo "Changed files:"
55+
echo "$CHANGED_FILES"
56+
57+
- name: Install clang-tidy
58+
if: steps.changed-files.outputs.any_changed == 'true'
59+
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
60+
with:
61+
clang-tidy: 20.1.8
62+
63+
- name: Setup Python env
64+
if: steps.changed-files.outputs.any_changed == 'true'
65+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
66+
with:
67+
python-version: '3.12'
68+
69+
- name: Configure and CodeGen
70+
if: steps.changed-files.outputs.any_changed == 'true'
71+
run: |
72+
cmake -G Ninja \
73+
-B build \
74+
-S llvm \
75+
-DLLVM_ENABLE_ASSERTIONS=OFF \
76+
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
77+
-DCMAKE_CXX_COMPILER=clang++ \
78+
-DCMAKE_C_COMPILER=clang \
79+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
80+
-DLLVM_INCLUDE_TESTS=OFF \
81+
-DCLANG_INCLUDE_TESTS=OFF \
82+
-DMLIR_INCLUDE_TESTS=OFF \
83+
-DCMAKE_BUILD_TYPE=Release \
84+
-DLLVM_TARGETS_TO_BUILD=host \
85+
-DCLANG_ENABLE_CIR=ON
86+
87+
ninja -C build mlir-headers clang-tablegen-targets
88+
89+
- name: Run run-clang-tidy
90+
if: steps.changed-files.outputs.any_changed == 'true'
91+
env:
92+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
93+
run: |
94+
./clang-tools-extra/clang-tidy/tool/run-clang-tidy.py \
95+
-p build "$CHANGED_FILES" \
96+
-checks="-*,readability-identifier-naming" \
97+
-warnings-as-errors="-*,readability-identifier-naming" \
98+
-j $(nproc)

0 commit comments

Comments
 (0)