Skip to content

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

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

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

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
- name: Install Cppcheck from source
run: |
mkdir -p $HOME/cppcheck-install
git clone https://github.com/danmar/cppcheck.git $HOME/cppcheck-source
cd $HOME/cppcheck-source
git checkout 2.14.1
mkdir build
cd build
cmake ..
make -j $(nproc)
make install DESTDIR=$HOME/cppcheck-install
echo "$HOME/cppcheck-install/usr/local/bin" >> $GITHUB_PATH
- 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
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 --suppressions-list=.cppcheck_suppressions --xml $files 2> cppcheck-report.xml
else
echo "No C++ files changed."
fi
shell: bash