Skip to content

Commit 707610e

Browse files
committed
[CI] Introduce handcrafted action for clang-tidy
1 parent ccc6db9 commit 707610e

File tree

2 files changed

+143
-25
lines changed

2 files changed

+143
-25
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 'Native Clang-Tidy Analysis'
2+
description: 'Run clang-tidy analysis without Docker'
3+
inputs:
4+
build_dir:
5+
description: 'Build directory for CMake'
6+
required: false
7+
default: 'build'
8+
exclude:
9+
description: 'Directories to exclude from analysis'
10+
required: false
11+
default: '3rdparty'
12+
clang_tidy_version:
13+
description: 'Clang-tidy version to use'
14+
required: false
15+
default: '20'
16+
outputs:
17+
total_comments:
18+
description: 'Total number of clang-tidy issues found'
19+
value: ${{ steps.analyze.outputs.total_comments }}
20+
runs:
21+
using: 'composite'
22+
steps:
23+
- name: Verify clang-tidy installation
24+
shell: bash
25+
run: |
26+
clang-tidy-${{ inputs.clang_tidy_version }} --version
27+
28+
- name: Get changed files
29+
id: changed-files
30+
shell: bash
31+
run: |
32+
git fetch origin ${{ github.event.pull_request.base.ref }}
33+
CHANGED_FILES=$(git diff --name-only \
34+
origin/${{ github.event.pull_request.base.ref }}...HEAD \
35+
-- '*.cpp' '*.hpp' '*.c' '*.h' | grep -v '^${{ inputs.exclude }}/' || true)
36+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
37+
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
38+
echo "EOF" >> $GITHUB_OUTPUT
39+
40+
if [ -z "$CHANGED_FILES" ]; then
41+
echo "has_changes=false" >> $GITHUB_OUTPUT
42+
else
43+
echo "has_changes=true" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Run clang-tidy analysis
47+
id: analyze
48+
shell: bash
49+
if: steps.changed-files.outputs.has_changes == 'true'
50+
run: |
51+
COMMENTS_FILE=$(mktemp)
52+
TOTAL_ISSUES=0
53+
54+
while IFS= read -r file; do
55+
if [ -n "$file" ] && [ -f "$file" ]; then
56+
echo "Analyzing $file..."
57+
if clang-tidy-${{ inputs.clang_tidy_version }} "$file" \
58+
-p ${{ inputs.build_dir }} --format-style=file 2>&1 | \
59+
tee -a "$COMMENTS_FILE"; then
60+
ISSUES=$(grep -c "warning:\|error:" "$COMMENTS_FILE" || echo "0")
61+
TOTAL_ISSUES=$((TOTAL_ISSUES + ISSUES))
62+
else
63+
echo "::error::Failed to analyze $file"
64+
TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
65+
fi
66+
fi
67+
done <<< "${{ steps.changed-files.outputs.changed_files }}"
68+
69+
echo "total_comments=$TOTAL_ISSUES" >> $GITHUB_OUTPUT
70+
71+
if [ -f "$COMMENTS_FILE" ] && [ -s "$COMMENTS_FILE" ]; then
72+
echo "::group::Clang-tidy Analysis Results"
73+
cat "$COMMENTS_FILE"
74+
echo "::endgroup::"
75+
fi
76+
77+
if [ "$TOTAL_ISSUES" -gt 0 ]; then
78+
echo "::error::Found $TOTAL_ISSUES clang-tidy issues"
79+
else
80+
echo "No clang-tidy issues found"
81+
fi
82+
83+
- name: Set output for no changes
84+
shell: bash
85+
if: steps.changed-files.outputs.has_changes == 'false'
86+
run: |
87+
echo "total_comments=0" >> $GITHUB_OUTPUT

.github/workflows/static-analysis-pr.yml

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,45 @@ concurrency:
2121
jobs:
2222
clang-tidy:
2323
runs-on: ubuntu-24.04
24+
container:
25+
image: ghcr.io/learning-process/ppc-ubuntu:latest
26+
credentials:
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
2429
steps:
2530
- uses: actions/checkout@v4
2631
with:
2732
submodules: recursive
33+
fetch-depth: 0
34+
2835
- name: ccache
2936
uses: hendrikmuhs/ccache-action@v1.2
3037
with:
3138
key: ${{ runner.os }}-clang
32-
- uses: ZedThree/clang-tidy-review@v0.21.0
39+
create-symlink: true
40+
max-size: 1G
41+
42+
- name: CMake configure
43+
run: >
44+
cmake -S . -B build -G Ninja
45+
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
46+
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
47+
env:
48+
CC: clang-20
49+
CXX: clang++-20
50+
51+
- name: Build project
52+
run: |
53+
cmake --build build --parallel
54+
env:
55+
CC: clang-20
56+
CXX: clang++-20
57+
58+
- uses: ./.github/actions/clang-tidy-native
3359
id: review
3460
with:
35-
build_dir: build
36-
apt_packages: openmpi-bin,openmpi-common,libopenmpi-dev,ninja-build,libomp-19-dev,valgrind
37-
cmake_command: >
38-
cmake -S . -B build -G Ninja
39-
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
40-
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4161
exclude: 3rdparty
42-
clang_tidy_checks: ""
43-
split_workflow: true
44-
clang_tidy_version: "19"
45-
lgtm_comment_body: ""
46-
env:
47-
CC: clang-19
48-
CXX: clang++-19
62+
clang_tidy_version: "20"
4963
- if: steps.review.outputs.total_comments > 0
5064
run: |
5165
echo "clang-tidy run has failed. See previous 'Run clang-tidy' stage logs"
@@ -54,28 +68,45 @@ jobs:
5468
needs:
5569
- clang-tidy
5670
runs-on: ubuntu-24.04
71+
container:
72+
image: ghcr.io/learning-process/ppc-ubuntu:latest
73+
credentials:
74+
username: ${{ github.actor }}
75+
password: ${{ secrets.GITHUB_TOKEN }}
5776
steps:
5877
- uses: actions/checkout@v4
5978
with:
6079
submodules: recursive
80+
fetch-depth: 0
81+
6182
- name: ccache
6283
uses: hendrikmuhs/ccache-action@v1.2
6384
with:
6485
key: ${{ runner.os }}-gcc
65-
- uses: ZedThree/clang-tidy-review@v0.21.0
86+
create-symlink: true
87+
max-size: 1G
88+
89+
- name: CMake configure
90+
run: >
91+
cmake -S . -B build -G Ninja
92+
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
93+
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
94+
env:
95+
CC: gcc-14
96+
CXX: g++-14
97+
98+
- name: Build project
99+
run: |
100+
cmake --build build --parallel
101+
env:
102+
CC: gcc-14
103+
CXX: g++-14
104+
105+
- uses: ./.github/actions/clang-tidy-native
66106
id: review
67107
with:
68-
build_dir: build
69-
apt_packages: openmpi-bin,openmpi-common,libopenmpi-dev,ninja-build,libomp-19-dev,valgrind
70-
cmake_command: >
71-
cmake -S . -B build -G Ninja
72-
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
73-
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
74108
exclude: 3rdparty
75-
clang_tidy_checks: ""
76-
split_workflow: true
77-
clang_tidy_version: "19"
78-
lgtm_comment_body: ""
109+
clang_tidy_version: "20"
79110
- if: steps.review.outputs.total_comments > 0
80111
run: |
81112
echo "clang-tidy run has failed. See previous 'Run clang-tidy' stage logs"

0 commit comments

Comments
 (0)