Skip to content

Commit

Permalink
chore(ci): run cppcheck-differential on modified packages (#7777)
Browse files Browse the repository at this point in the history
* chore(ci): run cppcheck-differential on modified packages

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* add colcon install

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* test

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

* restore

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>

---------

Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp>
  • Loading branch information
veqcc authored Jul 2, 2024
1 parent f6db96f commit 9fcad6b
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions .github/workflows/cppcheck-differential.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
sudo apt-get update
sudo apt-get install -y git
- name: Install colcon
run: |
sudo sh -c 'echo "deb [arch=amd64,arm64] http://repo.ros2.org/ubuntu/main `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt update
sudo apt install python3-colcon-common-extensions
# cppcheck from apt does not yet support --check-level args, and thus install from snap
- name: Install Cppcheck from snap
run: |
Expand All @@ -31,33 +38,42 @@ jobs:
run: git fetch origin ${{ github.base_ref }}
shell: bash

- name: Get changed files (existing files only)
id: get-changed-files
- name: Get modified packages
id: get-modified-packages
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1

- name: Get full paths of modified packages
id: get-full-paths
run: |
echo "changed-files=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD | grep -E '\.(cpp|hpp)$' | while read -r file; do [ -e "$file" ] && echo -n "$file "; done)" >> $GITHUB_OUTPUT
shell: bash
modified_packages="${{ steps.get-modified-packages.outputs.modified-packages }}"
paths=""
for pkg in $modified_packages; do
path=$(colcon list --packages-select $pkg | awk '{print $2}' | xargs realpath)
paths="$paths $path"
done
echo "full-paths=$paths" >> $GITHUB_OUTPUT
- name: Run Cppcheck on changed files
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
- name: Run Cppcheck on modified packages
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
continue-on-error: true
id: cppcheck
run: |
echo "Running Cppcheck on changed files: ${{ steps.get-changed-files.outputs.changed-files }}"
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions --inline-suppr ${{ steps.get-changed-files.outputs.changed-files }} 2> cppcheck-report.txt
echo "Running Cppcheck on modified packages: ${{ steps.get-modified-packages.outputs.modified-packages }}"
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions --inline-suppr ${{ steps.get-full-paths.outputs.full-paths }} 2> cppcheck-report.txt
shell: bash

- name: Show cppcheck-report result
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
run: |
cat cppcheck-report.txt
- name: Upload Cppcheck report
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
uses: actions/upload-artifact@v2
with:
name: cppcheck-report
path: cppcheck-report.txt

- name: Fail the job if Cppcheck failed
if: ${{ steps.get-changed-files.outputs.changed-files != '' && steps.cppcheck.outcome == 'failure' }}
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' && steps.cppcheck.outcome == 'failure' }}
run: exit 1

0 comments on commit 9fcad6b

Please sign in to comment.