22
22
sudo apt-get update
23
23
sudo apt-get install -y git
24
24
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
+
25
32
# cppcheck from apt does not yet support --check-level args, and thus install from snap
26
33
- name : Install Cppcheck from snap
27
34
run : |
@@ -31,33 +38,42 @@ jobs:
31
38
run : git fetch origin ${{ github.base_ref }}
32
39
shell : bash
33
40
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
36
47
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
39
55
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 != '' }}
42
58
continue-on-error : true
43
59
id : cppcheck
44
60
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
47
63
shell : bash
48
64
49
65
- name : Show cppcheck-report result
50
- if : ${{ steps.get-changed-files .outputs.changed-files != '' }}
66
+ if : ${{ steps.get-modified-packages .outputs.modified-packages != '' }}
51
67
run : |
52
68
cat cppcheck-report.txt
53
69
54
70
- name : Upload Cppcheck report
55
- if : ${{ steps.get-changed-files .outputs.changed-files != '' }}
71
+ if : ${{ steps.get-modified-packages .outputs.modified-packages != '' }}
56
72
uses : actions/upload-artifact@v2
57
73
with :
58
74
name : cppcheck-report
59
75
path : cppcheck-report.txt
60
76
61
77
- 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' }}
63
79
run : exit 1
0 commit comments