Skip to content

Commit 73e0569

Browse files
Add clang-tidy CI (#5)
1 parent db5f46d commit 73e0569

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

.github/workflows/clang-format.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: clang-format
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.h'
7+
- '**.cxx'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
precheckin:
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v5
19+
with:
20+
ref: ${{ github.event.pull_request.head.sha }}
21+
fetch-depth: 0
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.11"
27+
28+
- name: Install clang-format
29+
run: |
30+
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
31+
os_codename="`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`"
32+
echo "deb https://apt.llvm.org/${os_codename}/ llvm-toolchain-${os_codename}-18 main" | sudo tee -a /etc/apt/sources.list
33+
sudo apt update
34+
sudo apt install -y clang-format-18
35+
36+
- name: Run git-clang-format
37+
run: |
38+
PR_BASE=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
39+
echo "running git clang-format against $PR_BASE commit"
40+
git \
41+
-c color.ui=always \
42+
-c diff.wsErrorHighlight=all \
43+
-c color.diff.whitespace='red reverse' \
44+
clang-format-18 --diff --binary clang-format-18 --commit $PR_BASE -- inc/ src/ tools/ test/ benchmark/ || \
45+
(echo "Please run the following git-clang-format locally to fix the formatting: \n
46+
git-clang-format HEAD~\n
47+
for multiple commits we should place the formatting changes in the related commit with:\n
48+
\t\tgit rebase -i -x \"git-clang-format-18 main && git commit -a --allow-empty --fixup=HEAD\" --strategy-option=theirs origin/main\n
49+
\t\t Then inspect the results with: git log --oneline\n
50+
\t\t Then squash without poluting the history with: git rebase --autosquash -i main\n" && exit 1)
51+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: clang-tidy-review
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.h'
7+
- '**.cxx'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
review:
19+
runs-on: ubuntu-24.04
20+
steps:
21+
- name: Checkout PR branch
22+
uses: actions/checkout@v5
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.11'
28+
29+
- name: Install LLVM and Clang
30+
uses: KyleMayes/[email protected]
31+
with:
32+
version: '20.1.4'
33+
34+
- name: Install lit
35+
run: pip install --disable-pip-version-check --no-input lit
36+
37+
- name: Install ROOT
38+
run: |
39+
ROOT_URL="https://root.cern/download/root_v6.34.06.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz"
40+
wget -O root.tar.gz "$ROOT_URL"
41+
sudo tar -xzf root.tar.gz -C /opt/
42+
echo "/opt/root/bin" >> "$GITHUB_PATH"
43+
44+
- name: Run clang-tidy
45+
uses: ZedThree/[email protected]
46+
id: review
47+
with:
48+
build_dir: build
49+
apt_packages: cmake,libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev,libvdt-dev,libtbb-dev
50+
split_workflow: true
51+
config_file: .clang-tidy
52+
cmake_command: >
53+
source /opt/root/bin/thisroot.sh &&
54+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
55+
-DCMAKE_C_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang"
56+
-DCMAKE_CXX_COMPILER="$GITHUB_WORKSPACE/llvm/bin/clang++"
57+
-DLLVM_DIR="$GITHUB_WORKSPACE/llvm"
58+
-DBUILD_SHARED_LIBS=ON
59+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
60+
-DRAMTOOLS_BUILD_TESTS=ON
61+
-DRAMTOOLS_BUILD_TOOLS=ON
62+
-DRAMTOOLS_BUILD_BENCHMARKS=ON &&
63+
cd build &&
64+
cmake --build . --target googletest --parallel $(nproc --all)
65+
66+
- name: Upload artifacts
67+
if: always()
68+
uses: ZedThree/clang-tidy-review/[email protected]
69+

0 commit comments

Comments
 (0)