4
4
branches : [ master ]
5
5
workflow_dispatch :
6
6
7
+ env :
8
+ CPPCHECK_VERSION : " 2.16.0"
9
+
7
10
jobs :
11
+ build_cppcheck :
12
+ runs-on : ubuntu-22.04
13
+ steps :
14
+ - name : Restore cached cppcheck
15
+ id : cache-cppcheck
16
+ uses : actions/cache@v4
17
+ with :
18
+ path : /tmp/cppcheck-build
19
+ key : cppcheck-${{ env.CPPCHECK_VERSION }}
20
+
21
+ - name : Build cppcheck
22
+ if : steps.cache-cppcheck.outputs.cache-hit != 'true'
23
+ run : |
24
+ cd /tmp
25
+ git clone https://github.com/danmar/cppcheck.git
26
+ cd cppcheck
27
+ git checkout ${{ env.CPPCHECK_VERSION }}
28
+ make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
29
+ mkdir -p ../cppcheck-build
30
+ cp cppcheck ../cppcheck-build/
31
+ cp -r cfg ../cppcheck-build/
32
+ chmod +x ../cppcheck-build/cppcheck
33
+ ../cppcheck-build/cppcheck --version
34
+
35
+ - name : Upload cppcheck build
36
+ uses : actions/upload-artifact@v4
37
+ with :
38
+ name : cppcheck-build
39
+ path : /tmp/cppcheck-build/
40
+ retention-days : 1
41
+
8
42
analysis :
43
+ needs : build_cppcheck
9
44
runs-on : ubuntu-22.04
45
+ continue-on-error : true
46
+ outputs :
47
+ timed_out : ${{ steps.check-timeout.outputs.timed_out }}
10
48
env :
11
- TIMEOUT_EXIT_CODE : 124 # exit code for timeout command
49
+ TIMEOUT_EXIT_CODE : 124
12
50
13
51
steps :
14
52
- name : Checkout
15
53
uses : actions/checkout@v4
16
54
17
- - name : Debug TIMEOUT_EXIT_CODE
18
- run : |
19
- echo "Timeout exit code: $TIMEOUT_EXIT_CODE"
55
+ - name : Download cppcheck build
56
+ uses : actions/download-artifact@v4
57
+ with :
58
+ name : cppcheck-build
59
+ path : ./cppcheck-build
20
60
21
- - name : Make build-dir # Cppcheck work folder
22
- run : mkdir build-dir
61
+ - name : Setup cppcheck
62
+ run : |
63
+ chmod +x ./cppcheck-build/cppcheck
64
+ echo "$PWD/cppcheck-build" >> $GITHUB_PATH
23
65
24
- # - name: Install latest cppcheck for distro # cppcheck 2.7 is the latest for ubuntu-22.04 https://packages.ubuntu.com/search?keywords=cppcheck
25
- # run: |
26
- # sudo apt-get update
27
- # sudo apt-get --yes install cppcheck
28
- # cppcheck --version
66
+ - name : Verify cppcheck
67
+ run : cppcheck --version
29
68
30
- - name : Build cppcheck 2.15.0 # https://stackoverflow.com/a/72307265
31
- run : |
32
- cd /tmp
33
- git clone https://github.com/danmar/cppcheck.git
34
- cd cppcheck
35
- git checkout 2.15.0
36
- sudo make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function" install
37
- cd /tmp
38
- sudo rm -rf /tmp/cppcheck
39
- sudo ldconfig
40
- cppcheck --version
69
+ - name : Make build-dir
70
+ run : mkdir build-dir
41
71
42
72
- uses : actions/cache@v4
43
- id : cache-build-dir # Check if the cache hit-or-not
73
+ id : cache-build-dir
44
74
with :
45
- path : ./build-dir/ # Path of folder to cache, Cppcheck work folder
75
+ path : ./build-dir/
46
76
key : build-dir-${{ hashFiles('**/*.*') }}
47
77
restore-keys : |
48
78
build-dir-
@@ -54,51 +84,68 @@ jobs:
54
84
- name : Run cppcheck analysis
55
85
id : cppcheck
56
86
run : |
57
- timeout --signal=SIGTERM 350m cppcheck -j ${{ steps.cpu-info.outputs.cpu_count }} --project=VoxPopuli_vs2013.sln --check-level=exhaustive --max-ctu-depth=9999 --cppcheck-build-dir=build-dir --enable=all --std=c++03 --verbose --xml 2> cppcheck.xml || exit_code=$?
58
- echo "exit_code=$exit_code" >> $GITHUB_ENV
59
- if [ $exit_code -eq $TIMEOUT_EXIT_CODE ]; then
60
- echo "cppcheck timed out but continuing"
61
- fi
62
-
63
- - name : Debug exit code
87
+ timeout --signal=SIGTERM 350m cppcheck -j ${{ steps.cpu-info.outputs.cpu_count }} \
88
+ --project=VoxPopuli_vs2013.sln \
89
+ --check-level=exhaustive \
90
+ --max-ctu-depth=10 \
91
+ --cppcheck-build-dir=build-dir \
92
+ --enable=all \
93
+ --std=c++03 \
94
+ --verbose \
95
+ --check-library \
96
+ --inline-suppr \
97
+ --platform=win32W \
98
+ --xml 2> cppcheck.xml || exit_code=$?
99
+ echo "exit_code=${exit_code:-0}" >> $GITHUB_ENV
100
+
101
+ - name : Check timeout status
102
+ id : check-timeout
103
+ if : always()
64
104
run : |
65
- echo "Exit code: $exit_code"
105
+ if [ "${exit_code:-0}" = "$TIMEOUT_EXIT_CODE" ]; then
106
+ echo "timed_out=true" >> $GITHUB_OUTPUT
107
+ else
108
+ echo "timed_out=false" >> $GITHUB_OUTPUT
109
+ fi
66
110
67
- # - name: Upload cppcheck xml on success # TODO enable when retry_analysis can detect exit code
68
- # if: ${{ env.exit_code != env.TIMEOUT_EXIT_CODE }}
69
- # uses: actions/upload-artifact@v4
70
- # with:
71
- # name: cppcheck-xml
72
- # path: ./cppcheck.xml
111
+ - name : Upload analysis artifacts
112
+ if : success() && steps.check-timeout.outputs.timed_out != 'true'
113
+ uses : actions/upload-artifact@v4
114
+ with :
115
+ name : cppcheck-xml
116
+ path : |
117
+ cppcheck.xml
118
+ retention-days : 90
73
119
74
120
retry_analysis :
121
+ needs : [build_cppcheck, analysis]
75
122
runs-on : ubuntu-22.04
76
- needs : analysis
77
- # if: needs.analysis.outputs.exit_code == 124 # FIXME condition, doesn't detect prior exit code
78
-
123
+ if : needs.analysis.outputs.timed_out == 'true'
79
124
steps :
80
125
- name : Checkout
81
126
uses : actions/checkout@v4
82
127
83
- - name : Make build-dir # Cppcheck work folder
84
- run : mkdir build-dir
128
+ - name : Download cppcheck build
129
+ uses : actions/download-artifact@v4
130
+ with :
131
+ name : cppcheck-build
132
+ path : ./cppcheck-build
85
133
86
- - name : Build cppcheck 2.15.0 # https://stackoverflow.com/a/72307265
134
+ - name : Setup cppcheck
87
135
run : |
88
- cd /tmp
89
- git clone https://github.com/danmar/cppcheck.git
90
- cd cppcheck
91
- git checkout 2.15.0
92
- sudo make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function" install
93
- cd /tmp
94
- sudo rm -rf /tmp/cppcheck
95
- sudo ldconfig
96
- cppcheck --version
136
+ chmod +x ./cppcheck-build/cppcheck
137
+ echo "$PWD/cppcheck-build" >> $GITHUB_PATH
138
+
139
+ - name : Verify cppcheck
140
+ run : cppcheck --version
141
+
142
+ - name : Make build-dir
143
+ run : mkdir build-dir
97
144
98
145
- uses : actions/cache@v4
99
- id : cache-build-dir # Check if the cache hit-or-not
146
+ id : cache-build-dir
100
147
with :
101
- path : ./build-dir/ # Path of folder to cache, Cppcheck work folder
148
+ path : ./build-dir/
102
149
key : build-dir-${{ hashFiles('**/*.*') }}
103
150
restore-keys : |
104
151
build-dir-
@@ -109,11 +156,26 @@ jobs:
109
156
110
157
- name : Run cppcheck analysis
111
158
id : cppcheck
159
+ continue-on-error : true
112
160
run : |
113
- timeout --signal=SIGTERM 350m cppcheck -j ${{ steps.cpu-info.outputs.cpu_count }} --project=VoxPopuli_vs2013.sln --check-level=exhaustive --max-ctu-depth=9999 --cppcheck-build-dir=build-dir --enable=all --std=c++03 --verbose --xml 2> cppcheck.xml || echo "cppcheck timed out but continuing"
114
-
115
- - name : Upload cppcheck xml
161
+ timeout --signal=SIGTERM 350m cppcheck -j ${{ steps.cpu-info.outputs.cpu_count }} \
162
+ --project=VoxPopuli_vs2013.sln \
163
+ --check-level=exhaustive \
164
+ --max-ctu-depth=10 \
165
+ --cppcheck-build-dir=build-dir \
166
+ --enable=all \
167
+ --std=c++03 \
168
+ --verbose \
169
+ --check-library \
170
+ --inline-suppr \
171
+ --platform=win32W \
172
+ --xml 2> cppcheck.xml || echo "cppcheck exit code: $?"
173
+
174
+ - name : Upload analysis artifacts
175
+ if : always()
116
176
uses : actions/upload-artifact@v4
117
177
with :
118
178
name : cppcheck-xml
119
- path : ./cppcheck.xml # Place cppcheck.xml in local source directory and open in cppcheck-gui
179
+ path : |
180
+ cppcheck.xml
181
+ retention-days : 90
0 commit comments