Skip to content

Commit 0160f36

Browse files
authored
ci(cppcheck-all, cppcheck-differential): add cppcheck (autowarefoundation#7262)
* ci: add cppcheck Signed-off-by: kminoda <koji.minoda@tier4.jp> * add more suppression Signed-off-by: kminoda <koji.minoda@tier4.jp> * update cppcheck version Signed-off-by: kminoda <koji.minoda@tier4.jp> * update suppressions list Signed-off-by: kminoda <koji.minoda@tier4.jp> * add two workflows Signed-off-by: kminoda <koji.minoda@tier4.jp> * change name Signed-off-by: kminoda <koji.minoda@tier4.jp> * change timing of all ci Signed-off-by: kminoda <koji.minoda@tier4.jp> * update Signed-off-by: kminoda <koji.minoda@tier4.jp> * update Signed-off-by: kminoda <koji.minoda@tier4.jp> * update Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix Signed-off-by: kminoda <koji.minoda@tier4.jp> * update name Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix mistake Signed-off-by: kminoda <koji.minoda@tier4.jp> * add echo in diff Signed-off-by: kminoda <koji.minoda@tier4.jp> * update regex Signed-off-by: kminoda <koji.minoda@tier4.jp> * add statistics for cppcheck-all Signed-off-by: kminoda <koji.minoda@tier4.jp> * avoid checking cppcheck dir Signed-off-by: kminoda <koji.minoda@tier4.jp> * error-exit Signed-off-by: kminoda <koji.minoda@tier4.jp> * dummy test Signed-off-by: kminoda <koji.minoda@tier4.jp> * upload file even if it fails Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix bug Signed-off-by: kminoda <koji.minoda@tier4.jp> * revert unnecessary commit Signed-off-by: kminoda <koji.minoda@tier4.jp> * minor fix Signed-off-by: kminoda <koji.minoda@tier4.jp> * dummy test Signed-off-by: kminoda <koji.minoda@tier4.jp> * dummy test Signed-off-by: kminoda <koji.minoda@tier4.jp> * modify to show cppcheck result even when failure Signed-off-by: kminoda <koji.minoda@tier4.jp> * finalize PR Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix pre-commit Signed-off-by: kminoda <koji.minoda@tier4.jp> * fix pre-commit Signed-off-by: kminoda <koji.minoda@tier4.jp> --------- Signed-off-by: kminoda <koji.minoda@tier4.jp>
1 parent 9ec94f0 commit 0160f36

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

.cppcheck_suppressions

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
arrayIndexThenCheck
2+
assignBoolToFloat
3+
checkersReport
4+
constParameterPointer
5+
constParameterReference
6+
constStatement
7+
constVariable
8+
constVariablePointer
9+
constVariableReference
10+
containerOutOfBounds
11+
cstyleCast
12+
ctuOneDefinitionRuleViolation
13+
current_deleted_index
14+
duplicateAssignExpression
15+
duplicateBranch
16+
duplicateBreak
17+
duplicateCondition
18+
duplicateExpression
19+
funcArgNamesDifferent
20+
functionConst
21+
functionStatic
22+
invalidPointerCast
23+
knownConditionTrueFalse
24+
missingInclude
25+
missingIncludeSystem
26+
multiCondition
27+
noConstructor
28+
noExplicitConstructor
29+
noValidConfiguration
30+
obstacle_cruise_planner
31+
passedByValue
32+
preprocessorErrorDirective
33+
redundantAssignment
34+
redundantContinue
35+
redundantIfRemove
36+
redundantInitialization
37+
returnByReference
38+
selfAssignment
39+
shadowArgument
40+
shadowFunction
41+
shadowVariable
42+
stlFindInsert
43+
syntaxError
44+
uninitMemberVar
45+
unknownMacro
46+
unmatchedSuppression
47+
unpreciseMathCall
48+
unreadVariable
49+
unsignedLessThanZero
50+
unusedFunction
51+
unusedScopedObject
52+
unusedStructMember
53+
unusedVariable
54+
useInitializationList
55+
useStlAlgorithm
56+
uselessCallsSubstr
57+
uselessOverride
58+
variableScope
59+
virtualCallInConstructor

.github/workflows/cppcheck-all.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: cppcheck-all
2+
3+
on:
4+
pull_request:
5+
schedule:
6+
- cron: 0 0 * * *
7+
workflow_dispatch:
8+
9+
jobs:
10+
cppcheck-all:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Install dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y build-essential cmake git libpcre3-dev
21+
22+
# cppcheck from apt does not yet support --check-level args, and thus install from source
23+
- name: Install Cppcheck from source
24+
run: |
25+
mkdir /tmp/cppcheck
26+
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
27+
cd /tmp/cppcheck
28+
git checkout 2.14.1
29+
mkdir build
30+
cd build
31+
cmake ..
32+
make -j $(nproc)
33+
sudo make install
34+
35+
- name: Run Cppcheck on all files
36+
continue-on-error: true
37+
id: cppcheck
38+
run: |
39+
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --xml . 2> cppcheck-report.xml
40+
shell: bash
41+
42+
- name: Count errors by error ID and severity
43+
run: |
44+
#!/bin/bash
45+
temp_file=$(mktemp)
46+
grep -oP '(?<=id=")[^"]+" severity="[^"]+' cppcheck-report.xml | sed 's/" severity="/,/g' > "$temp_file"
47+
echo "Error counts by error ID and severity:"
48+
sort "$temp_file" | uniq -c
49+
rm "$temp_file"
50+
shell: bash
51+
52+
- name: Upload Cppcheck report
53+
uses: actions/upload-artifact@v2
54+
with:
55+
name: cppcheck-report
56+
path: cppcheck-report.xml
57+
58+
- name: Fail the job if Cppcheck failed
59+
if: steps.cppcheck.outcome == 'failure'
60+
run: exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: cppcheck-differential
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
cppcheck-differential:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
14+
- name: Install dependencies
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install -y build-essential cmake git libpcre3-dev
18+
19+
# cppcheck from apt does not yet support --check-level args, and thus install from source
20+
- name: Install Cppcheck from source
21+
run: |
22+
mkdir /tmp/cppcheck
23+
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
24+
cd /tmp/cppcheck
25+
git checkout 2.14.1
26+
mkdir build
27+
cd build
28+
cmake ..
29+
make -j $(nproc)
30+
sudo make install
31+
32+
- name: Get changed files
33+
id: changed-files
34+
run: |
35+
git fetch origin ${{ github.base_ref }} --depth=1
36+
git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt
37+
cat changed_files.txt
38+
39+
- name: Run Cppcheck on changed files
40+
continue-on-error: true
41+
id: cppcheck
42+
run: |
43+
files=$(cat changed_files.txt | grep -E '\.(cpp|hpp)$' || true)
44+
if [ -n "$files" ]; then
45+
echo "Running Cppcheck on changed files: $files"
46+
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt
47+
else
48+
echo "No C++ files changed."
49+
touch cppcheck-report.txt
50+
fi
51+
shell: bash
52+
53+
- name: Show cppcheck-report result
54+
run: |
55+
cat cppcheck-report.txt
56+
57+
- name: Upload Cppcheck report
58+
uses: actions/upload-artifact@v2
59+
with:
60+
name: cppcheck-report
61+
path: cppcheck-report.txt
62+
63+
- name: Fail the job if Cppcheck failed
64+
if: steps.cppcheck.outcome == 'failure'
65+
run: exit 1

0 commit comments

Comments
 (0)