-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI] Integrate Cppcheck for static code analysis (#198)
* [CI] Integrate Cppcheck for static code analysis * Include GITHUB_RUN_ID in report artifact name * Remove "uninstall" duplicate phony target * Add navigable step summary * Fix redirection for Markdown * Fix file link * Configure branch according to event
- Loading branch information
Showing
6 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project version="1"> | ||
<builddir>cppcheck-build-dir</builddir> | ||
<analyze-all-vs-configs>false</analyze-all-vs-configs> | ||
<check-headers>true</check-headers> | ||
<check-unused-templates>false</check-unused-templates> | ||
<max-ctu-depth>2</max-ctu-depth> | ||
<includedir> | ||
<dir name="include/" /> | ||
</includedir> | ||
<paths> | ||
<dir name="src" /> | ||
<dir name="app" /> | ||
<dir name="examples" /> | ||
</paths> | ||
<exclude> | ||
<path name="app/external/" /> | ||
</exclude> | ||
<libraries> | ||
<library>cppcheck-lib</library> | ||
<library>emscripten</library> | ||
<library>posix</library> | ||
<library>sqlite3</library> | ||
<library>windows</library> | ||
</libraries> | ||
<suppressions> | ||
<suppression>missingInclude</suppression> | ||
<suppression>missingIncludeSystem</suppression> | ||
<suppression>unmatchedSuppression</suppression> | ||
</suppressions> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,4 @@ amd64-freebsd-gcc | |
jq | ||
nuget-feed | ||
homebrew-zsv | ||
cppcheck* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
echo "[INF] Running $0" | ||
|
||
if ! which cppcheck >/dev/null; then | ||
echo "[ERR] cppcheck is not installed!" | ||
exit 1 | ||
fi | ||
|
||
VERSION=$(cppcheck --version | sed 's/^[^0-9]*//g' | sed 's/ .*$//g') | ||
echo "[INF] cppcheck version [$VERSION]" | ||
|
||
CPPCHECK_PROJECT_FILE=".cppcheck" | ||
CPPCHECK_BUILD_DIR="cppcheck-build-dir" | ||
CPPCHECK_XML_OUTPUT_FILE="cppcheck.xml" | ||
CPPCHECK_HTML_REPORT_DIR="cppcheck-html-report-dir" | ||
|
||
echo "[INF] CPPCHECK_PROJECT_FILE: $CPPCHECK_PROJECT_FILE" | ||
echo "[INF] CPPCHECK_BUILD_DIR: $CPPCHECK_BUILD_DIR" | ||
echo "[INF] CPPCHECK_XML_OUTPUT_FILE: $CPPCHECK_XML_OUTPUT_FILE" | ||
echo "[INF] CPPCHECK_HTML_REPORT_DIR: $CPPCHECK_HTML_REPORT_DIR" | ||
|
||
mkdir -p "$CPPCHECK_BUILD_DIR" | ||
|
||
echo "[INF] Generating XML report..." | ||
cppcheck \ | ||
--quiet \ | ||
--enable=all \ | ||
--project="$CPPCHECK_PROJECT_FILE" \ | ||
--xml 2>"$CPPCHECK_XML_OUTPUT_FILE" | ||
|
||
ls -Gghl "$CPPCHECK_XML_OUTPUT_FILE" | ||
|
||
echo "[INF] Generating HTML report..." | ||
cppcheck-htmlreport \ | ||
--title="zsv" \ | ||
--file="$CPPCHECK_XML_OUTPUT_FILE" \ | ||
--report-dir="$CPPCHECK_HTML_REPORT_DIR" \ | ||
--source-dir="$PWD" | ||
|
||
# GitHub Actions | ||
if [ "$CI" = true ]; then | ||
CPPCHECK_XML_ARTIFACT_NAME="zsv-cppcheck-xml-report-$GITHUB_RUN_ID.zip" | ||
CPPCHECK_HTML_ARTIFACT_NAME="zsv-cppcheck-html-report-$GITHUB_RUN_ID.zip" | ||
|
||
echo "[INF] Generating ZIP archive (XML)... [$CPPCHECK_XML_ARTIFACT_NAME]" | ||
zip "$CPPCHECK_XML_ARTIFACT_NAME" "$CPPCHECK_XML_OUTPUT_FILE" | ||
|
||
echo "[INF] Generating ZIP archive (HTML)... [$CPPCHECK_HTML_ARTIFACT_NAME]" | ||
zip -r "$CPPCHECK_HTML_ARTIFACT_NAME" "$CPPCHECK_HTML_REPORT_DIR" | ||
|
||
{ | ||
echo "CPPCHECK_XML_ARTIFACT_NAME=$CPPCHECK_XML_ARTIFACT_NAME" | ||
echo "CPPCHECK_HTML_ARTIFACT_NAME=$CPPCHECK_HTML_ARTIFACT_NAME" | ||
} >>"$GITHUB_ENV" | ||
|
||
echo "[INF] Generating Markdown step summary..." | ||
|
||
BRANCH= | ||
if [ "$GITHUB_REF_TYPE" = "branch" ]; then | ||
if [ "$GITHUB_EVENT_NAME" = "push" ]; then | ||
BRANCH="$GITHUB_REF_NAME" | ||
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then | ||
BRANCH="$GITHUB_HEAD_REF" | ||
fi | ||
elif [ "$GITHUB_REF_TYPE" = "tag" ]; then | ||
BRANCH="main" | ||
fi | ||
|
||
SOURCE_LINK="[{file}:{line}](https://github.com/liquidaty/zsv/blob/$BRANCH/{file}#L{line})" | ||
CWE_LINK="[{cwe}](https://cwe.mitre.org/data/definitions/{cwe}.html)" | ||
TEMPLATE="| $SOURCE_LINK | {column} | {severity} | {id} | {message} | $CWE_LINK |" | ||
{ | ||
echo "# Cppcheck Static Analysis Summary" | ||
echo "| File:Line | Column | Severity | ID | Message | CWE |" | ||
echo "| :-------: | :----: | :------: | :---: | :-----: | :---: |" | ||
cppcheck \ | ||
--quiet \ | ||
--enable=all \ | ||
--project="$CPPCHECK_PROJECT_FILE" \ | ||
--template="$TEMPLATE" \ | ||
2>&1 | ||
} >>"$GITHUB_STEP_SUMMARY" | ||
fi | ||
|
||
echo "[INF] --- [DONE] ---" |