Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(cppcheck-all, cppcheck-differential): add cppcheck #7262

Merged
merged 32 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8b8de24
ci: add cppcheck
kminoda Jun 4, 2024
bf154e8
add more suppression
kminoda Jun 4, 2024
e57410b
update cppcheck version
kminoda Jun 4, 2024
2e2cb23
update suppressions list
kminoda Jun 4, 2024
e7064d5
add two workflows
kminoda Jun 4, 2024
bd4b78e
change name
kminoda Jun 4, 2024
01739e2
change timing of all ci
kminoda Jun 4, 2024
d50d05d
update
kminoda Jun 4, 2024
de6f3e8
update
kminoda Jun 4, 2024
a89e8b6
update
kminoda Jun 4, 2024
85c5036
fix
kminoda Jun 4, 2024
4eb1d9c
update name
kminoda Jun 4, 2024
e715115
fix mistake
kminoda Jun 4, 2024
ed14e35
add echo in diff
kminoda Jun 4, 2024
9231644
update regex
kminoda Jun 4, 2024
4f10212
add statistics for cppcheck-all
kminoda Jun 4, 2024
2d3bbb3
avoid checking cppcheck dir
kminoda Jun 4, 2024
ba13741
error-exit
kminoda Jun 4, 2024
e32bc67
dummy test
kminoda Jun 4, 2024
f2e9789
upload file even if it fails
kminoda Jun 4, 2024
f64238b
fix bug
kminoda Jun 4, 2024
c8f59cb
revert unnecessary commit
kminoda Jun 4, 2024
7923ce9
minor fix
kminoda Jun 4, 2024
7a02961
dummy test
kminoda Jun 4, 2024
8c7d41c
dummy test
kminoda Jun 4, 2024
330ceb8
modify to show cppcheck result even when failure
kminoda Jun 4, 2024
b8829a4
finalize PR
kminoda Jun 4, 2024
3384a55
Merge branch 'main' into ci/add_cpp_check
kminoda Jun 4, 2024
ac26f55
fix pre-commit
kminoda Jun 5, 2024
6948f0b
fix pre-commit
kminoda Jun 5, 2024
a8a59f8
Merge branch 'main' into ci/add_cpp_check
kminoda Jun 5, 2024
9890b2e
Merge branch 'main' into ci/add_cpp_check
kminoda Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .cppcheck_suppressions
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
arrayIndexThenCheck
assignBoolToFloat
checkersReport
constParameterPointer
constParameterReference
constStatement
constVariable
constVariablePointer
constVariableReference
containerOutOfBounds
cstyleCast
ctuOneDefinitionRuleViolation
current_deleted_index
duplicateAssignExpression
duplicateBranch
duplicateBreak
duplicateCondition
duplicateExpression
funcArgNamesDifferent
functionConst
functionStatic
invalidPointerCast
knownConditionTrueFalse
missingInclude
missingIncludeSystem
multiCondition
noConstructor
noExplicitConstructor
noValidConfiguration
obstacle_cruise_planner
passedByValue
preprocessorErrorDirective
redundantAssignment
redundantContinue
redundantIfRemove
redundantInitialization
returnByReference
selfAssignment
shadowArgument
shadowFunction
shadowVariable
stlFindInsert
syntaxError
uninitMemberVar
unknownMacro
unmatchedSuppression
unpreciseMathCall
unreadVariable
unsignedLessThanZero
unusedFunction
unusedScopedObject
unusedStructMember
unusedVariable
useInitializationList
useStlAlgorithm
uselessCallsSubstr
uselessOverride
variableScope
virtualCallInConstructor
60 changes: 60 additions & 0 deletions .github/workflows/cppcheck-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: cppcheck-all

on:
pull_request:
schedule:
- cron: 0 0 * * *
workflow_dispatch:

jobs:
cppcheck-all:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git libpcre3-dev

# cppcheck from apt does not yet support --check-level args, and thus install from source
- name: Install Cppcheck from source
run: |
mkdir /tmp/cppcheck
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
kminoda marked this conversation as resolved.
Show resolved Hide resolved
cd /tmp/cppcheck
git checkout 2.14.1
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install

- name: Run Cppcheck on all files
continue-on-error: true
id: cppcheck
run: |
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --xml . 2> cppcheck-report.xml
shell: bash

- name: Count errors by error ID and severity
run: |
#!/bin/bash
temp_file=$(mktemp)
grep -oP '(?<=id=")[^"]+" severity="[^"]+' cppcheck-report.xml | sed 's/" severity="/,/g' > "$temp_file"
echo "Error counts by error ID and severity:"
sort "$temp_file" | uniq -c
rm "$temp_file"
shell: bash

- name: Upload Cppcheck report
uses: actions/upload-artifact@v2
with:
name: cppcheck-report
path: cppcheck-report.xml

- name: Fail the job if Cppcheck failed
if: steps.cppcheck.outcome == 'failure'
run: exit 1
65 changes: 65 additions & 0 deletions .github/workflows/cppcheck-differential.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: cppcheck-differential

on:
pull_request:

jobs:
cppcheck-differential:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git libpcre3-dev

# cppcheck from apt does not yet support --check-level args, and thus install from source
- name: Install Cppcheck from source
run: |
mkdir /tmp/cppcheck
git clone https://github.com/danmar/cppcheck.git /tmp/cppcheck
cd /tmp/cppcheck
git checkout 2.14.1
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install

- name: Get changed files
id: changed-files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt
cat changed_files.txt

- name: Run Cppcheck on changed files
continue-on-error: true
id: cppcheck
run: |
files=$(cat changed_files.txt | grep -E '\.(cpp|hpp)$' || true)
if [ -n "$files" ]; then
echo "Running Cppcheck on changed files: $files"
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt
else
echo "No C++ files changed."
touch cppcheck-report.txt
fi
shell: bash

- name: Show cppcheck-report result
run: |
cat cppcheck-report.txt

- name: Upload Cppcheck report
uses: actions/upload-artifact@v2
with:
name: cppcheck-report
path: cppcheck-report.txt

- name: Fail the job if Cppcheck failed
if: steps.cppcheck.outcome == 'failure'
run: exit 1
Loading