Skip to content

Commit 9fcad6b

Browse files
authored
chore(ci): run cppcheck-differential on modified packages (autowarefoundation#7777)
* 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>
1 parent f6db96f commit 9fcad6b

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

.github/workflows/cppcheck-differential.yaml

+27-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ jobs:
2222
sudo apt-get update
2323
sudo apt-get install -y git
2424
25+
- name: Install colcon
26+
run: |
27+
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'
28+
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
29+
sudo apt update
30+
sudo apt install python3-colcon-common-extensions
31+
2532
# cppcheck from apt does not yet support --check-level args, and thus install from snap
2633
- name: Install Cppcheck from snap
2734
run: |
@@ -31,33 +38,42 @@ jobs:
3138
run: git fetch origin ${{ github.base_ref }}
3239
shell: bash
3340

34-
- name: Get changed files (existing files only)
35-
id: get-changed-files
41+
- name: Get modified packages
42+
id: get-modified-packages
43+
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
44+
45+
- name: Get full paths of modified packages
46+
id: get-full-paths
3647
run: |
37-
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
38-
shell: bash
48+
modified_packages="${{ steps.get-modified-packages.outputs.modified-packages }}"
49+
paths=""
50+
for pkg in $modified_packages; do
51+
path=$(colcon list --packages-select $pkg | awk '{print $2}' | xargs realpath)
52+
paths="$paths $path"
53+
done
54+
echo "full-paths=$paths" >> $GITHUB_OUTPUT
3955
40-
- name: Run Cppcheck on changed files
41-
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
56+
- name: Run Cppcheck on modified packages
57+
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
4258
continue-on-error: true
4359
id: cppcheck
4460
run: |
45-
echo "Running Cppcheck on changed files: ${{ steps.get-changed-files.outputs.changed-files }}"
46-
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
61+
echo "Running Cppcheck on modified packages: ${{ steps.get-modified-packages.outputs.modified-packages }}"
62+
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
4763
shell: bash
4864

4965
- name: Show cppcheck-report result
50-
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
66+
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
5167
run: |
5268
cat cppcheck-report.txt
5369
5470
- name: Upload Cppcheck report
55-
if: ${{ steps.get-changed-files.outputs.changed-files != '' }}
71+
if: ${{ steps.get-modified-packages.outputs.modified-packages != '' }}
5672
uses: actions/upload-artifact@v2
5773
with:
5874
name: cppcheck-report
5975
path: cppcheck-report.txt
6076

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

0 commit comments

Comments
 (0)