Skip to content

Commit babaf72

Browse files
authored
[CI] Introduce handcrafted action for clang-tidy, update clang-tidy version to 20 (#597)
1 parent ccc6db9 commit babaf72

File tree

3 files changed

+148
-31
lines changed

3 files changed

+148
-31
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 config --global --add safe.directory $GITHUB_WORKSPACE
33+
git fetch origin ${{ github.event.pull_request.base.ref }}
34+
CHANGED_FILES=$(git diff --name-only \
35+
origin/${{ github.event.pull_request.base.ref }}...HEAD \
36+
-- '*.cpp' '*.hpp' '*.c' '*.h' | grep -v '^${{ inputs.exclude }}/' || true)
37+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
38+
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
39+
echo "EOF" >> $GITHUB_OUTPUT
40+
41+
if [ -z "$CHANGED_FILES" ]; then
42+
echo "has_changes=false" >> $GITHUB_OUTPUT
43+
else
44+
echo "has_changes=true" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Run clang-tidy analysis
48+
id: analyze
49+
shell: bash
50+
if: steps.changed-files.outputs.has_changes == 'true'
51+
run: |
52+
COMMENTS_FILE=$(mktemp)
53+
TOTAL_ISSUES=0
54+
55+
while IFS= read -r file; do
56+
if [ -n "$file" ] && [ -f "$file" ]; then
57+
echo "Analyzing $file..."
58+
if clang-tidy-${{ inputs.clang_tidy_version }} "$file" \
59+
-p ${{ inputs.build_dir }} --format-style=file 2>&1 | \
60+
tee -a "$COMMENTS_FILE"; then
61+
ISSUES=$(grep -c "warning:\|error:" "$COMMENTS_FILE" || echo "0")
62+
TOTAL_ISSUES=$((TOTAL_ISSUES + ISSUES))
63+
else
64+
echo "::error::Failed to analyze $file"
65+
TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
66+
fi
67+
fi
68+
done <<< "${{ steps.changed-files.outputs.changed_files }}"
69+
70+
echo "total_comments=$TOTAL_ISSUES" >> $GITHUB_OUTPUT
71+
72+
if [ -f "$COMMENTS_FILE" ] && [ -s "$COMMENTS_FILE" ]; then
73+
echo "::group::Clang-tidy Analysis Results"
74+
cat "$COMMENTS_FILE"
75+
echo "::endgroup::"
76+
fi
77+
78+
if [ "$TOTAL_ISSUES" -gt 0 ]; then
79+
echo "::error::Found $TOTAL_ISSUES clang-tidy issues"
80+
else
81+
echo "No clang-tidy issues found"
82+
fi
83+
84+
- name: Set output for no changes
85+
shell: bash
86+
if: steps.changed-files.outputs.has_changes == 'false'
87+
run: |
88+
echo "total_comments=0" >> $GITHUB_OUTPUT

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

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,46 @@ 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+
- name: Run clang-tidy
59+
uses: ./.github/actions/clang-tidy-native
3360
id: review
3461
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
4162
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
63+
clang_tidy_version: "20"
4964
- if: steps.review.outputs.total_comments > 0
5065
run: |
5166
echo "clang-tidy run has failed. See previous 'Run clang-tidy' stage logs"
@@ -54,28 +69,46 @@ jobs:
5469
needs:
5570
- clang-tidy
5671
runs-on: ubuntu-24.04
72+
container:
73+
image: ghcr.io/learning-process/ppc-ubuntu:latest
74+
credentials:
75+
username: ${{ github.actor }}
76+
password: ${{ secrets.GITHUB_TOKEN }}
5777
steps:
5878
- uses: actions/checkout@v4
5979
with:
6080
submodules: recursive
81+
fetch-depth: 0
82+
6183
- name: ccache
6284
uses: hendrikmuhs/ccache-action@v1.2
6385
with:
6486
key: ${{ runner.os }}-gcc
65-
- uses: ZedThree/clang-tidy-review@v0.21.0
87+
create-symlink: true
88+
max-size: 1G
89+
90+
- name: CMake configure
91+
run: >
92+
cmake -S . -B build -G Ninja
93+
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
94+
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
95+
env:
96+
CC: gcc-14
97+
CXX: g++-14
98+
99+
- name: Build project
100+
run: |
101+
cmake --build build --parallel
102+
env:
103+
CC: gcc-14
104+
CXX: g++-14
105+
106+
- name: Run clang-tidy
107+
uses: ./.github/actions/clang-tidy-native
66108
id: review
67109
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
74110
exclude: 3rdparty
75-
clang_tidy_checks: ""
76-
split_workflow: true
77-
clang_tidy_version: "19"
78-
lgtm_comment_body: ""
111+
clang_tidy_version: "20"
79112
- if: steps.review.outputs.total_comments > 0
80113
run: |
81114
echo "clang-tidy run has failed. See previous 'Run clang-tidy' stage logs"

modules/task/include/task.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
#include <omp.h>
44

5-
#include <algorithm>
65
#include <array>
76
#include <chrono>
87
#include <cstdint>
98
#include <cstdlib>
10-
#include <exception>
119
#include <fstream>
12-
#include <functional>
1310
#include <iomanip>
1411
#include <iostream>
1512
#include <memory>
@@ -18,7 +15,6 @@
1815
#include <string>
1916
#include <util/include/util.hpp>
2017
#include <utility>
21-
#include <vector>
2218

2319
namespace ppc::task {
2420

@@ -259,8 +255,8 @@ class Task {
259255
virtual bool PostProcessingImpl() = 0;
260256

261257
private:
262-
InType input_;
263-
OutType output_;
258+
InType input_{};
259+
OutType output_{};
264260
StateOfTesting state_of_testing_ = kFunc;
265261
TypeOfTask type_of_task_ = kUnknown;
266262
StatusOfTask status_of_task_ = kEnabled;

0 commit comments

Comments
 (0)