Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -----------------------------------------------------------------------------
# .clang-format (Google Style with Comments)
# 官方文档: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# -----------------------------------------------------------------------------
Language: Cpp
BasedOnStyle: Google
82 changes: 70 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,89 @@ jobs:

- name: Run Cppcheck
run: |
cppcheck --enable=all --std=c++17 --error-exitcode=1 \
--suppress=missingIncludeSystem --suppress=missingInclude \
--suppress=unusedFunction --inconclusive \
# 确保第三方库目录存在且被正确排除
echo "=== Directories to exclude ==="
find . -name "third_party" -type d || echo "No third_party directories found"
echo "=== Running Cppcheck on your source code only ==="

# 只检查自己的代码,排除第三方库
cppcheck --enable=warning,style,performance,portability \
--std=c++17 --error-exitcode=0 \
--suppress=missingIncludeSystem \
--suppress=missingInclude \
--suppress=unusedFunction \
--suppress=useStlAlgorithm \
--suppress=functionStatic \
--suppress=toomanyconfigs \
--suppress=ConfigurationNotChecked \
--suppress=syntaxError \
-i third_party/ \
--inconclusive \
src/ 2> cppcheck_report.txt

echo "=== Cppcheck completed ==="
continue-on-error: true

- name: Check and Upload Cppcheck Report
- name: Filter and Check Cppcheck Report
id: cppcheck
run: |
if grep -E "(error|warning)" cppcheck_report.txt; then
echo "Cppcheck found issues. See the report."
# 过滤掉第三方库的错误和不重要的警告
if [ -s cppcheck_report.txt ]; then
grep -v "third_party/" cppcheck_report.txt | \
grep -v "nlohmann/json.hpp" | \
grep -v "JSON_CATCH" | \
grep -v "_MSVC_LANG" | \
grep -v "_MSC_VER" | \
grep -v "syntaxError" | \
grep -v "toomanyconfigs" | \
grep -v "ConfigurationNotChecked" | \
grep -v "unmatchedSuppression" > filtered_report.txt || true
else
touch filtered_report.txt
fi

# 只关注真正的错误和重要警告
if [ -s filtered_report.txt ] && grep -E "(error|warning.*shadowArgument|warning.*constVariable|warning.*funcArgNamesDifferent)" filtered_report.txt; then
echo "Found critical issues in your code:"
cat filtered_report.txt
echo "CPPCHECK_EXIT_CODE=1" >> $GITHUB_ENV
else
echo "No critical Cppcheck issues found."
echo "No critical issues found in your code."
echo "CPPCHECK_EXIT_CODE=0" >> $GITHUB_ENV
fi

- name: Upload Report on Failure
if: env.CPPCHECK_EXIT_CODE == '1'
- name: Show Report Summary
run: |
echo "=== Cppcheck Analysis Summary ==="
if [ -s cppcheck_report.txt ]; then
echo "Total issues found: $(wc -l < cppcheck_report.txt)"
echo ""
echo "=== Filtered Report (Your Code Only) ==="
if [ -s filtered_report.txt ]; then
cat filtered_report.txt
echo ""
echo "=== Issue Classification ==="
critical_count=$(grep -c -E "(error|warning.*shadowArgument|warning.*constVariable|warning.*funcArgNamesDifferent)" filtered_report.txt || echo "0")
style_count=$(grep -c -E "(style|performance)" filtered_report.txt || echo "0")
echo "Critical issues (will fail CI): $critical_count"
echo "Style/Performance suggestions: $style_count"
else
echo "No issues found in your code after filtering!"
fi
else
echo "Cppcheck completed successfully with no issues found."
fi

- name: Upload Analysis Reports
uses: actions/upload-artifact@v4
with:
name: cppcheck-report
path: cppcheck_report.txt
name: cppcheck-analysis
path: |
cppcheck_report.txt
filtered_report.txt
if-no-files-found: ignore

- name: Fail workflow on issues
- name: Fail workflow on critical issues
if: env.CPPCHECK_EXIT_CODE == '1'
run: exit 1

Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "third_party/jwt-cpp"]
path = third_party/jwt-cpp
url = https://github.com/Thalhammer/jwt-cpp.git
[submodule "third_party/websocketpp"]
path = third_party/websocketpp
url = https://github.com/zaphoyd/websocketpp.git
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")

# 查找并链接线程库
find_package(Threads REQUIRED)
# 查找并链接SQLite3数据库库
find_package(SQLite3 REQUIRED)
# 查找并链接MySQL数据库库
find_package(PkgConfig REQUIRED)
pkg_check_modules(MYSQL REQUIRED mysqlclient)
# 查找并链接OpenSSL库(用于JWT签名)
find_package(OpenSSL REQUIRED)

Expand All @@ -32,7 +33,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/third_party/websocketpp # websocketpp头文件目录
${CMAKE_SOURCE_DIR}/third_party/nlohmann/single_include # nlohmann/json头文件目录
${CMAKE_SOURCE_DIR}/third_party/Bcrypt/include # Bcrypt头文件目录
${SQLite3_INCLUDE_DIRS} # SQLite3头文件目录
${MYSQL_INCLUDE_DIRS} # MySQL头文件目录
${OPENSSL_INCLUDE_DIR} # OpenSSL头文件目录
)

Expand Down
Loading