Skip to content

Commit f450e1a

Browse files
JohnsterIDRecursiveVision
authored andcommitted
cppcheck-2.16.0
1 parent b81ad8e commit f450e1a

File tree

1 file changed

+121
-59
lines changed

1 file changed

+121
-59
lines changed

.github/workflows/cppcheck.yml

+121-59
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,75 @@ on:
44
branches: [ master ]
55
workflow_dispatch:
66

7+
env:
8+
CPPCHECK_VERSION: "2.16.0"
9+
710
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+
842
analysis:
43+
needs: build_cppcheck
944
runs-on: ubuntu-22.04
45+
continue-on-error: true
46+
outputs:
47+
timed_out: ${{ steps.check-timeout.outputs.timed_out }}
1048
env:
11-
TIMEOUT_EXIT_CODE: 124 # exit code for timeout command
49+
TIMEOUT_EXIT_CODE: 124
1250

1351
steps:
1452
- name: Checkout
1553
uses: actions/checkout@v4
1654

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
2060

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
2365
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
2968

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
4171

4272
- uses: actions/cache@v4
43-
id: cache-build-dir # Check if the cache hit-or-not
73+
id: cache-build-dir
4474
with:
45-
path: ./build-dir/ # Path of folder to cache, Cppcheck work folder
75+
path: ./build-dir/
4676
key: build-dir-${{ hashFiles('**/*.*') }}
4777
restore-keys: |
4878
build-dir-
@@ -54,51 +84,68 @@ jobs:
5484
- name: Run cppcheck analysis
5585
id: cppcheck
5686
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()
64104
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
66110
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
73119

74120
retry_analysis:
121+
needs: [build_cppcheck, analysis]
75122
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'
79124
steps:
80125
- name: Checkout
81126
uses: actions/checkout@v4
82127

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
85133

86-
- name: Build cppcheck 2.15.0 # https://stackoverflow.com/a/72307265
134+
- name: Setup cppcheck
87135
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
97144

98145
- uses: actions/cache@v4
99-
id: cache-build-dir # Check if the cache hit-or-not
146+
id: cache-build-dir
100147
with:
101-
path: ./build-dir/ # Path of folder to cache, Cppcheck work folder
148+
path: ./build-dir/
102149
key: build-dir-${{ hashFiles('**/*.*') }}
103150
restore-keys: |
104151
build-dir-
@@ -109,11 +156,26 @@ jobs:
109156

110157
- name: Run cppcheck analysis
111158
id: cppcheck
159+
continue-on-error: true
112160
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()
116176
uses: actions/upload-artifact@v4
117177
with:
118178
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

Comments
 (0)