From e5cde1b30ec95d08f04ac47b630729657ba737f9 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 03:07:52 -0700 Subject: [PATCH 001/137] fix:Checkstyle check --- .github/workflows/checkstyle.yml | 33 +++++++++++++++++++------------- pom.xml | 23 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 74529b84..3d0c1283 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -3,35 +3,42 @@ name: Checkstyle Code Quality on: push: branches: - - develop # 或者你想要检查的分支 + - develop pull_request: branches: - - develop # 你可以在 PR 时检查代码 + - develop jobs: - check: + checkstyle: runs-on: ubuntu-24.04 steps: - # 检出代码 - name: Checkout code uses: actions/checkout@v4 - # 设置 JDK(如果是 Java 项目) - - name: Set up JDK 17.* + - name: Set up JDK 17 uses: actions/setup-java@v4 with: - java-version: '17.*' + java-version: '17' distribution: 'temurin' - # 安装依赖并运行 Checkstyle(如果是 Maven 项目) - - name: Install dependencies and run Checkstyle - run: | - mvn clean package + # 缓存 Maven 依赖,加速构建 + - name: Cache Maven dependencies + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + # 直接运行 Checkstyle 检查(不执行完整的 package) + - name: Run Checkstyle + run: mvn checkstyle:check - # 查看 Checkstyle 检查报告 + # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report + if: always() # 即使失败也上传报告 uses: actions/upload-artifact@v4 with: name: checkstyle-report - path: target/checkstyle-result.xml # 这个路径应该是 Maven 生成的检查报告路径 + path: target/checkstyle-result.xml diff --git a/pom.xml b/pom.xml index c651a73c..1734cb4a 100644 --- a/pom.xml +++ b/pom.xml @@ -235,6 +235,29 @@ 17 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.1 + + + settings/checkstyle.xml + + true + + xml + + + + checkstyle-check + validate + + check + + + + From 95b5fb32fb6366fe99dbbe30d8253ea417a3b33a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 03:40:24 -0700 Subject: [PATCH 002/137] fix:Checkstyle check --- codestyle/huawei-codestyle.xml | 287 +++++++++++++++++++++++++++++++++ pom.xml | 2 +- 2 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 codestyle/huawei-codestyle.xml diff --git a/codestyle/huawei-codestyle.xml b/codestyle/huawei-codestyle.xml new file mode 100644 index 00000000..e7ab75b1 --- /dev/null +++ b/codestyle/huawei-codestyle.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1734cb4a..c1390dc5 100644 --- a/pom.xml +++ b/pom.xml @@ -242,7 +242,7 @@ 3.3.1 - settings/checkstyle.xml + checkstyle/huawei-checkstyle.xml true From e48f78a49f00a7828d1cdb0f02aae5af5a6b16ed Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 03:47:05 -0700 Subject: [PATCH 003/137] fix:Checkstyle check --- .../huawei-codestyle.xml => checkstyle/huawei-checkstyle.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codestyle/huawei-codestyle.xml => checkstyle/huawei-checkstyle.xml (100%) diff --git a/codestyle/huawei-codestyle.xml b/checkstyle/huawei-checkstyle.xml similarity index 100% rename from codestyle/huawei-codestyle.xml rename to checkstyle/huawei-checkstyle.xml From f7978bed20592583edf9930d85ae17a87d0ddfcb Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 03:58:14 -0700 Subject: [PATCH 004/137] fix:Checkstyle check --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1390dc5..b7ddff00 100644 --- a/pom.xml +++ b/pom.xml @@ -242,7 +242,7 @@ 3.3.1 - checkstyle/huawei-checkstyle.xml + ${project.basedir}/checkstyle/huawei-checkstyle.xml true From 426994319c253f635d9b309aa8f9f23fa67c0e61 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:03:53 -0700 Subject: [PATCH 005/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index e7ab75b1..0d68712a 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -35,17 +35,6 @@ - diff --git a/pom.xml b/pom.xml index b7ddff00..fc00b947 100644 --- a/pom.xml +++ b/pom.xml @@ -245,6 +245,7 @@ ${project.basedir}/checkstyle/huawei-checkstyle.xml true + warning xml From b58e79f265ccd7dad82484b34e9b302d28cb8661 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:15:40 -0700 Subject: [PATCH 007/137] fix:Checkstyle check --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fc00b947..6358bacb 100644 --- a/pom.xml +++ b/pom.xml @@ -242,7 +242,7 @@ 3.3.1 - ${project.basedir}/checkstyle/huawei-checkstyle.xml + ./checkstyle/huawei-checkstyle.xml true warning From 45714f7e8fb698aa2307a97ce09006bbac6e539e Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:19:53 -0700 Subject: [PATCH 008/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index d3d44b62..2512af0c 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -61,8 +61,7 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + \ No newline at end of file From 7d231981aeb127a5a0131649d8c3e188b3594677 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:32:59 -0700 Subject: [PATCH 010/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 298 +++++++++++++++++++++++++++---- 1 file changed, 267 insertions(+), 31 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index c97cd6fd..897c4e52 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -1,31 +1,267 @@ - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 35a3220d1811fa744376d941302287a9bc35c567 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:33:21 -0700 Subject: [PATCH 011/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index 897c4e52..ee7c30aa 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -14,6 +14,11 @@ + + From 35bfea8f8206551c44a6d756dbf5fa4798e4a95d Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:38:31 -0700 Subject: [PATCH 012/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index ee7c30aa..fa1d4b64 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -56,11 +56,6 @@ - - - - - From 3843ac132749bcc10a75ac17ed19820a7d17871f Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 10 Jul 2026 04:40:50 -0700 Subject: [PATCH 013/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index fa1d4b64..b8052b05 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -56,7 +56,6 @@ - - ./checkstyle/huawei-checkstyle.xml + ./app/src/main/resources/checkstyle.xml true warning From c52edf33dc3eadeecd8d6308834723aaaf48d2a4 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 00:15:56 -0700 Subject: [PATCH 015/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 238 +++++++++++++------------------ pom.xml | 2 +- 2 files changed, 100 insertions(+), 140 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index b8052b05..a902a249 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -1,27 +1,20 @@ - - + + - + - - - - + - @@ -35,200 +28,163 @@ - + authorFormat: 检查author标签的格式 + versionFormat: 检查version标签的格式 + scope: 可以检查的类的范围,例如:public只能检查public修饰的类,private可以检查所有的类 + excludeScope: 不能检查的类的范围,例如:public,public的类将不被检查,但访问权限小于public的类仍然会检查,其他的权限以此类推 + tokens: 该属性适用的类型,例如:CLASS_DEF,INTERFACE_DEF --> - + scope: 可以检查的方法的范围,例如:public只能检查public修饰的方法,private可以检查所有的方法 + allowMissingParamTags: 是否忽略对参数注释的检查 + allowMissingThrowsTags: 是否忽略对throws注释的检查 + allowMissingReturnTag: 是否忽略对return注释的检查 --> - + + - - - - - - + maxLineLength: 大括号'{'所在行行最多容纳的字符数 + tokens: 该属性适用的类型,例:CLASS_DEF,INTERFACE_DEF,METHOD_DEF,CTOR_DEF --> - + - - - - + - + - + - - + + - - - - + - - + + + + - - - - + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - + - + - - - - - - - + - + - - + - + - - - - - - - - - - - - + + - + @@ -260,7 +216,11 @@ - + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ca4e5a13..6358bacb 100644 --- a/pom.xml +++ b/pom.xml @@ -242,7 +242,7 @@ 3.3.1 - ./app/src/main/resources/checkstyle.xml + ./checkstyle/huawei-checkstyle.xml true warning From 929462f67f1a9807f24ea7a3f7242e0a64b8c4af Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 02:24:36 -0700 Subject: [PATCH 016/137] fix:Checkstyle check --- checkstyle/huawei-checkstyle.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index a902a249..a2a60652 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -4,7 +4,6 @@ - From 989abaf6af2f464980222202d4817c65799d3626 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 03:33:35 -0700 Subject: [PATCH 017/137] fix:Checkstyle check --- .github/scripts/checkstyle-pr.sh | 110 +++++++++++++++++++++++++++++++ .github/workflows/checkstyle.yml | 10 ++- pom.xml | 2 +- 3 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/checkstyle-pr.sh diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh new file mode 100644 index 00000000..a56185fa --- /dev/null +++ b/.github/scripts/checkstyle-pr.sh @@ -0,0 +1,110 @@ +#!/bin/bash +# ============================================================ +# checkstyle-pr.sh - 增量 Checkstyle 检查(仅报告,不阻断构建) +# 用途:扫描 PR/commit 中变更的 Java 文件,生成违规报告 +# ============================================================ + +set -e # 遇到错误立即退出(但我们会特殊处理 mvn 的返回) + +echo "========================================" +echo " Checkstyle PR 增量检查 (仅报告)" +echo "========================================" + +# 1. 确定对比的目标分支 +if [ -n "$GITHUB_BASE_REF" ]; then + # GitHub Actions 环境:PR 事件 + BASE_BRANCH="origin/$GITHUB_BASE_REF" + echo "🔍 检测到 PR 事件,目标分支: $GITHUB_BASE_REF" +elif [ -n "$GITHUB_REF" ] && [ "$GITHUB_EVENT_NAME" == "push" ]; then + # push 事件,对比上一次提交 + BASE_BRANCH="HEAD^" + echo "🔍 检测到 Push 事件,对比上一次提交" +else + # 本地运行:默认对比 origin/main,如果不存在则尝试 origin/develop + if git rev-parse --verify origin/main >/dev/null 2>&1; then + BASE_BRANCH="origin/main" + elif git rev-parse --verify origin/develop >/dev/null 2>&1; then + BASE_BRANCH="origin/develop" + else + echo "❌ 无法确定目标分支,请指定 BASE_BRANCH 环境变量或在 Git 仓库中设置远程分支。" + exit 1 + fi + echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" +fi + +# 2. 确保目标分支存在(如果是远程分支,先 fetch) +if [[ "$BASE_BRANCH" == origin/* ]] && ! git rev-parse --verify "$BASE_BRANCH" >/dev/null 2>&1; then + echo "⬇️ 正在 fetch 远程分支 $BASE_BRANCH ..." + git fetch origin "${BASE_BRANCH#origin/}" +fi + +# 3. 获取变更的 Java 文件列表 +CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) + +if [ -z "$CHANGED_FILES" ]; then + echo "✅ 本次没有变更 Java 文件,跳过检查。" + exit 0 +fi + +echo "📝 本次变更的 Java 文件:" +echo "$CHANGED_FILES" +echo "----------------------------------------" + +# 4. 将文件列表转为逗号分隔(用于 Maven 参数) +FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') + +# 5. 执行 Checkstyle(生成报告,不阻断) +echo "🚀 开始执行 Checkstyle 增量扫描..." +set +e # 暂时关闭错误退出,以便我们自己处理返回值 +mvn checkstyle:checkstyle \ + -Dcheckstyle.includes="$FILES_LIST" \ + -Dcheckstyle.excludes="**/test/**/*.java" +MVN_EXIT=$? +set -e # 恢复 + +# 6. 解析违规数 +VIOLATIONS=0 +REPORT_FILE="target/checkstyle-result.xml" +if [ -f "$REPORT_FILE" ]; then + VIOLATIONS=$(grep -c '//' | \ + sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ + while read -r line; do + echo " $line" + done +fi + +# 7. 输出到 GitHub Step Summary(仅在 Actions 环境中有效) +if [ -n "$GITHUB_STEP_SUMMARY" ]; then + { + echo "## 📋 Checkstyle 报告摘要" + echo "" + echo "| 指标 | 结果 |" + echo "|------|------|" + if [ $VIOLATIONS -eq 0 ]; then + echo "| 违规数 | ✅ **0** |" + else + echo "| 违规数 | ⚠️ **$VIOLATIONS** |" + fi + echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个 Java 文件 |" + echo "" + if [ -f "$HTML_REPORT" ]; then + echo "📄 [查看详细 HTML 报告](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" + fi + echo "💡 完整报告作为 Artifact 下载,请查看工作流运行页面。" + } >> "$GITHUB_STEP_SUMMARY" + echo "✅ Step Summary 已生成" +fi + +# 8. 始终以成功状态退出(不阻断构建) +exit 0 \ No newline at end of file diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 3d0c1283..8fbd7901 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -15,6 +15,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -33,7 +35,9 @@ jobs: # 直接运行 Checkstyle 检查(不执行完整的 package) - name: Run Checkstyle - run: mvn checkstyle:check + run: bash .github/scripts/checkstyle-pr.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report @@ -41,4 +45,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: checkstyle-report - path: target/checkstyle-result.xml + path: | + target/checkstyle-result.xml + target/site/checkstyle.html diff --git a/pom.xml b/pom.xml index 6358bacb..a4bdd76f 100644 --- a/pom.xml +++ b/pom.xml @@ -244,7 +244,7 @@ ./checkstyle/huawei-checkstyle.xml - true + false warning xml From c97a525d8782a4e99b7f07b9029f306a36d30a7a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 03:52:40 -0700 Subject: [PATCH 018/137] fix:Checkstyle check --- .github/scripts/checkstyle-pr.sh | 200 +++++++++++++++++++++++-------- 1 file changed, 153 insertions(+), 47 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index a56185fa..8f1e2468 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,110 +1,216 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - 增量 Checkstyle 检查(仅报告,不阻断构建) -# 用途:扫描 PR/commit 中变更的 Java 文件,生成违规报告 +# checkstyle-pr.sh - 真正的增量检查 +# 功能:只报告本次提交中新增或修改行的 Checkstyle 违规 +# 不阻断构建,生成过滤后的报告 # ============================================================ -set -e # 遇到错误立即退出(但我们会特殊处理 mvn 的返回) +set -e echo "========================================" -echo " Checkstyle PR 增量检查 (仅报告)" +echo " Checkstyle 增量行检查 (只检测新代码)" echo "========================================" -# 1. 确定对比的目标分支 +# 1. 确定目标分支 if [ -n "$GITHUB_BASE_REF" ]; then - # GitHub Actions 环境:PR 事件 BASE_BRANCH="origin/$GITHUB_BASE_REF" - echo "🔍 检测到 PR 事件,目标分支: $GITHUB_BASE_REF" elif [ -n "$GITHUB_REF" ] && [ "$GITHUB_EVENT_NAME" == "push" ]; then - # push 事件,对比上一次提交 BASE_BRANCH="HEAD^" - echo "🔍 检测到 Push 事件,对比上一次提交" else - # 本地运行:默认对比 origin/main,如果不存在则尝试 origin/develop if git rev-parse --verify origin/main >/dev/null 2>&1; then BASE_BRANCH="origin/main" elif git rev-parse --verify origin/develop >/dev/null 2>&1; then BASE_BRANCH="origin/develop" else - echo "❌ 无法确定目标分支,请指定 BASE_BRANCH 环境变量或在 Git 仓库中设置远程分支。" + echo "❌ 无法确定目标分支,请设置 BASE_BRANCH 环境变量。" exit 1 fi echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" fi -# 2. 确保目标分支存在(如果是远程分支,先 fetch) -if [[ "$BASE_BRANCH" == origin/* ]] && ! git rev-parse --verify "$BASE_BRANCH" >/dev/null 2>&1; then - echo "⬇️ 正在 fetch 远程分支 $BASE_BRANCH ..." - git fetch origin "${BASE_BRANCH#origin/}" -fi - -# 3. 获取变更的 Java 文件列表 +# 2. 获取变更的 Java 文件 CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) if [ -z "$CHANGED_FILES" ]; then - echo "✅ 本次没有变更 Java 文件,跳过检查。" + echo "✅ 没有 Java 文件变更,跳过检查。" exit 0 fi -echo "📝 本次变更的 Java 文件:" +echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 4. 将文件列表转为逗号分隔(用于 Maven 参数) +# 3. 生成包含变更行号信息的文件 (用于后续过滤) +echo "🔄 提取变更行号..." +CHANGE_INFO_FILE=".checkstyle-changes.txt" +rm -f "$CHANGE_INFO_FILE" + +for file in $CHANGED_FILES; do + # 获取该文件新增或修改的行号范围(新文件行号) + # git diff -U0 输出 unified=0,只显示变更行 + diff_output=$(git diff -U0 "$BASE_BRANCH" HEAD -- "$file" 2>/dev/null | grep '^@@' || true) + if [ -n "$diff_output" ]; then + # 解析 @@ -old,count +new,count @@ 提取新行号范围 + echo "$diff_output" | while read -r line; do + # 提取 + 后面的起始行和行数 + new_info=$(echo "$line" | sed -n 's/.*+\([0-9]*\)\(,[0-9]*\)\?.*/\1 \2/p') + if [ -n "$new_info" ]; then + start=$(echo "$new_info" | awk '{print $1}') + count=$(echo "$new_info" | awk '{print $2}' | sed 's/,//') + if [ -z "$count" ]; then + count=1 + fi + # 生成行号范围,例如 file:10-15 + echo "$file:$start-$((start+count-1))" >> "$CHANGE_INFO_FILE" + fi + done + fi +done + +if [ ! -s "$CHANGE_INFO_FILE" ]; then + echo "⚠️ 未提取到变更行号,可能变更只涉及删除或文件重命名,跳过检查。" + exit 0 +fi + +echo "变更行号信息已保存到 $CHANGE_INFO_FILE" + +# 4. 执行 Checkstyle 扫描全部变更文件(生成完整报告) +echo "🚀 执行 Checkstyle 扫描(生成完整报告)..." FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') -# 5. 执行 Checkstyle(生成报告,不阻断) -echo "🚀 开始执行 Checkstyle 增量扫描..." -set +e # 暂时关闭错误退出,以便我们自己处理返回值 +set +e mvn checkstyle:checkstyle \ -Dcheckstyle.includes="$FILES_LIST" \ - -Dcheckstyle.excludes="**/test/**/*.java" + -Dcheckstyle.excludes="**/test/**/*.java" \ + -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? -set -e # 恢复 +set -e -# 6. 解析违规数 -VIOLATIONS=0 REPORT_FILE="target/checkstyle-result.xml" -if [ -f "$REPORT_FILE" ]; then - VIOLATIONS=$(grep -c '//' | \ + grep '//' | \ sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ while read -r line; do echo " $line" done fi -# 7. 输出到 GitHub Step Summary(仅在 Actions 环境中有效) +# 7. 输出到 GitHub Step Summary if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 报告摘要" + echo "## 📋 Checkstyle 增量行报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $VIOLATIONS -eq 0 ]; then - echo "| 违规数 | ✅ **0** |" + if [ $FILTERED_VIOLATIONS -eq 0 ]; then + echo "| 新增代码违规数 | ✅ **0** |" else - echo "| 违规数 | ⚠️ **$VIOLATIONS** |" + echo "| 新增代码违规数 | ⚠️ **$FILTERED_VIOLATIONS** |" fi - echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个 Java 文件 |" + echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" + echo "| 检查范围 | 仅新增或修改的行 |" echo "" - if [ -f "$HTML_REPORT" ]; then - echo "📄 [查看详细 HTML 报告](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" - fi - echo "💡 完整报告作为 Artifact 下载,请查看工作流运行页面。" + echo "📄 [下载完整报告(所有文件)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" + echo "📄 [下载过滤后报告(仅新增行)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" } >> "$GITHUB_STEP_SUMMARY" - echo "✅ Step Summary 已生成" + echo "✅ Step Summary 已更新" fi -# 8. 始终以成功状态退出(不阻断构建) +# 8. 替换原始报告为过滤后的报告(以便 Artifact 上传只包含过滤结果) +# 但为了保留完整报告,我们不上传过滤后的,而是上传原始和过滤两份。 +# 在 YAML 中,我们会上传整个 target/ 下的相关文件,所以无所谓。 + +# 9. 清理临时文件 +rm -f "$CHANGE_INFO_FILE" + +# 10. 始终以成功状态退出 exit 0 \ No newline at end of file From 082e950f2b40d9f981fad8b3f170946eb2c8c494 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 04:11:07 -0700 Subject: [PATCH 019/137] fix:Checkstyle check --- .github/workflows/checkstyle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 8fbd7901..176c5e7b 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -46,5 +46,5 @@ jobs: with: name: checkstyle-report path: | - target/checkstyle-result.xml - target/site/checkstyle.html + */target/checkstyle-result.xml + */target/site/checkstyle.html From 8ed95e04dc79df9da01ad73d34824817ca477c06 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 19:19:11 -0700 Subject: [PATCH 020/137] fix:Checkstyle check --- .github/workflows/checkstyle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 176c5e7b..7dd04304 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -46,5 +46,5 @@ jobs: with: name: checkstyle-report path: | - */target/checkstyle-result.xml - */target/site/checkstyle.html + base/target/checkstyle-result.xml + base/target/site/checkstyle.html From 5e47b0f025a4e6248c73c0c9605dafb0737b2ddd Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 19:20:41 -0700 Subject: [PATCH 021/137] fix:Checkstyle check --- .github/workflows/checkstyle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 7dd04304..859b2605 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -46,5 +46,5 @@ jobs: with: name: checkstyle-report path: | - base/target/checkstyle-result.xml - base/target/site/checkstyle.html + **/target/checkstyle-result.xml + **/target/site/checkstyle.html From ec22270f24d99496902862834b167e0a337c2eb3 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 19:31:21 -0700 Subject: [PATCH 022/137] fix:Checkstyle check --- .github/workflows/checkstyle.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 859b2605..31869f81 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -39,6 +39,14 @@ jobs: env: GITHUB_BASE_REF: ${{ github.base_ref }} + - name: Debug - list all checkstyle reports + run: | + echo "当前工作目录: $(pwd)" + echo "=== 列出所有 target 目录 ===" + find . -type d -name "target" -exec echo "目录: {}" \; -exec ls -la {}/ \; + echo "=== 查找 checkstyle 文件 ===" + find . -name "checkstyle*.xml" -o -name "checkstyle*.html" | while read f; do echo "找到: $f"; done + # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 From f9fd62328dae634fcd5b50d2742234cb9257f43e Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 20:37:59 -0700 Subject: [PATCH 023/137] fix:Checkstyle check test --- .../it/common/utils/testCheckstyle.java | 79 +++++++++++++++++++ .../it/common/utils/JsonUtilsTest.java | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java diff --git a/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java new file mode 100644 index 00000000..65b4c82f --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java @@ -0,0 +1,79 @@ +package com.tinyengine.it.common.utils; +/** + * 类名错误:应使用 UpperCamelCase(首字母大写) + * 这里故意写成了小写开头的 testCheckstyle + */ +public class testCheckstyle { + + // 常量命名错误:应全部大写并用下划线分隔 + public static final String myConstant = "Hello"; + + // 成员变量命名错误:不应以下划线开头 + private String _name; + + // 成员变量命名错误:不应使用单个字符 + private int a; + + /** + * 构造方法:可以接受参数,但未提供 Javadoc + */ + public testCheckstyle(String name) { + this._name = name; + } + + /** + * 方法名错误:不应包含大写字母,应使用 lowerCamelCase + */ + public void SayHello() { + // 行长度超限(超过120字符),故意写长 + System.out.println("This line is intentionally made extremely long to exceed the maximum line length limit which is usually set to 120 characters in Huawei coding standard. It definitely exceeds 120 chars."); + + // 缩进可能使用Tab(如果你的编辑器未转换,此处会触发) + // 未使用的局部变量 + String unused = "I am not used anywhere"; + } + + /** + * 公共方法缺少 Javadoc 注释 + */ + public void doSomething() { + // 方法体为空或简单,但缺少注释 + } + + /** + * 方法名包含下划线,违反 lowerCamelCase + */ + public void do_this() { + // 空方法体 + } + + /** + * 参数和返回值缺少 Javadoc 说明(如果有要求) + */ + public int add(int a, int b) { + return a + b; + } + + /** + * 重载方法,但缺少 Javadoc + */ + public int add(int a, int b, int c) { + return a + b + c; + } + + // 缺少访问修饰符的方法(默认包级别,可能不符合规范) + void packagePrivateMethod() { + System.out.println("This method has no access modifier."); + } + + // 静态方法命名错误 + public static void StaticMethod() { + // 方法名首字母大写,违反 lowerCamelCase + } + + // 常量应放在静态代码块或声明时赋值,但此处未遵循顺序 + public static final String ANOTHER_CONST; + static { + ANOTHER_CONST = "Init"; + } +} diff --git a/base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java b/base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java index 80562311..37cdcc38 100644 --- a/base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java +++ b/base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java @@ -270,7 +270,7 @@ void testEncodePrettily_ComplexObject() { void testDecode_ByteArray() { // Arrange String json = "{\"key\":\"value\",\"number\":123}"; - byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); + byte[] jsonBytes = json.getBytes(); // Act Map result = JsonUtils.decode(jsonBytes, Map.class); From 9025582328f296b980b49bb57b11ced83ec92286 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 13 Jul 2026 23:54:21 -0700 Subject: [PATCH 024/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 31869f81..1110f76d 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -11,6 +11,8 @@ on: jobs: checkstyle: runs-on: ubuntu-24.04 + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - name: Checkout code From 8a82ac0875b2adc1eaf806c8364d729d99d58dca Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 00:04:33 -0700 Subject: [PATCH 025/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 1110f76d..441e47ab 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -12,7 +12,7 @@ jobs: checkstyle: runs-on: ubuntu-24.04 env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true steps: - name: Checkout code From 2bee0b1e7367758a14086619496b5a30e978b804 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 01:01:14 -0700 Subject: [PATCH 026/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 8f1e2468..360bd582 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -79,14 +79,14 @@ echo "🚀 执行 Checkstyle 扫描(生成完整报告)..." FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') set +e -mvn checkstyle:checkstyle \ +mvn checkstyle:check \ -Dcheckstyle.includes="$FILES_LIST" \ -Dcheckstyle.excludes="**/test/**/*.java" \ -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? set -e -REPORT_FILE="target/checkstyle-result.xml" +REPORT_FILE="base/target/checkstyle-result.xml" if [ ! -f "$REPORT_FILE" ]; then echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 From 4bf78064f31f1fcab6c2b926e8c832f87e330802 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 01:11:59 -0700 Subject: [PATCH 027/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 360bd582..43ccf281 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -199,8 +199,9 @@ if [ -n "$GITHUB_STEP_SUMMARY" ]; then echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" echo "| 检查范围 | 仅新增或修改的行 |" echo "" - echo "📄 [下载完整报告(所有文件)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" - echo "📄 [下载过滤后报告(仅新增行)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" + # 使用环境变量构建链接 + echo "📄 [下载完整报告(所有文件)](${GH_SERVER_URL}/${GH_REPOSITORY}/actions/runs/${GH_RUN_ID})" + echo "📄 [下载过滤后报告(仅新增行)](${GH_SERVER_URL}/${GH_REPOSITORY}/actions/runs/${GH_RUN_ID})" } >> "$GITHUB_STEP_SUMMARY" echo "✅ Step Summary 已更新" fi From 4102cc68b82ca0dabc9873599d5e3c0c405e3cc7 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 01:36:40 -0700 Subject: [PATCH 028/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 441e47ab..1110f76d 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -12,7 +12,7 @@ jobs: checkstyle: runs-on: ubuntu-24.04 env: - ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - name: Checkout code From 9c654e97562fc0150da1f9d307e956388ac6c117 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 01:46:37 -0700 Subject: [PATCH 029/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 1110f76d..162c2b21 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -16,19 +16,19 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 - name: Set up JDK 17 - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: '17' distribution: 'temurin' # 缓存 Maven 依赖,加速构建 - name: Cache Maven dependencies - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -52,9 +52,10 @@ jobs: # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: checkstyle-report path: | **/target/checkstyle-result.xml **/target/site/checkstyle.html + if-no-files-found: warn From 9c1e5c8a51285b82af9271e7c41d2f16eefd74db Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:10:41 -0700 Subject: [PATCH 030/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 159 +++++-------------------------- 1 file changed, 22 insertions(+), 137 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 43ccf281..f9b08516 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,14 +1,15 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - 真正的增量检查 -# 功能:只报告本次提交中新增或修改行的 Checkstyle 违规 -# 不阻断构建,生成过滤后的报告 +# checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) +# 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 +# 不阻断构建,生成完整报告 # ============================================================ set -e echo "========================================" -echo " Checkstyle 增量行检查 (只检测新代码)" +echo " Checkstyle 增量检查" +echo " 扫描范围:本次变更的 Java 文件(完整文件)" echo "========================================" # 1. 确定目标分支 @@ -40,44 +41,11 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 生成包含变更行号信息的文件 (用于后续过滤) -echo "🔄 提取变更行号..." -CHANGE_INFO_FILE=".checkstyle-changes.txt" -rm -f "$CHANGE_INFO_FILE" - -for file in $CHANGED_FILES; do - # 获取该文件新增或修改的行号范围(新文件行号) - # git diff -U0 输出 unified=0,只显示变更行 - diff_output=$(git diff -U0 "$BASE_BRANCH" HEAD -- "$file" 2>/dev/null | grep '^@@' || true) - if [ -n "$diff_output" ]; then - # 解析 @@ -old,count +new,count @@ 提取新行号范围 - echo "$diff_output" | while read -r line; do - # 提取 + 后面的起始行和行数 - new_info=$(echo "$line" | sed -n 's/.*+\([0-9]*\)\(,[0-9]*\)\?.*/\1 \2/p') - if [ -n "$new_info" ]; then - start=$(echo "$new_info" | awk '{print $1}') - count=$(echo "$new_info" | awk '{print $2}' | sed 's/,//') - if [ -z "$count" ]; then - count=1 - fi - # 生成行号范围,例如 file:10-15 - echo "$file:$start-$((start+count-1))" >> "$CHANGE_INFO_FILE" - fi - done - fi -done - -if [ ! -s "$CHANGE_INFO_FILE" ]; then - echo "⚠️ 未提取到变更行号,可能变更只涉及删除或文件重命名,跳过检查。" - exit 0 -fi - -echo "变更行号信息已保存到 $CHANGE_INFO_FILE" - -# 4. 执行 Checkstyle 扫描全部变更文件(生成完整报告) -echo "🚀 执行 Checkstyle 扫描(生成完整报告)..." +# 3. 将文件列表转为逗号分隔 FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') +# 4. 执行 Checkstyle 扫描(生成完整报告) +echo "🚀 执行 Checkstyle 扫描(完整文件)..." set +e mvn checkstyle:check \ -Dcheckstyle.includes="$FILES_LIST" \ @@ -86,98 +54,24 @@ mvn checkstyle:check \ MVN_EXIT=$? set -e +# 5. 确定报告路径(根据项目结构调整) REPORT_FILE="base/target/checkstyle-result.xml" if [ ! -f "$REPORT_FILE" ]; then echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 fi -# 5. 过滤报告:只保留变更行上的违规 -echo "🔄 过滤违规,只保留变更行上的问题..." -FILTERED_REPORT="target/checkstyle-filtered-result.xml" -FILTERED_VIOLATIONS=0 - -# 使用 Python 脚本过滤(GitHub Actions 环境自带 python3) -python3 << EOF -import sys -import xml.etree.ElementTree as ET - -# 读取变更行信息 -changed_lines = {} -with open("$CHANGE_INFO_FILE", "r") as f: - for line in f: - line = line.strip() - if not line: - continue - parts = line.split(':') - if len(parts) != 2: - continue - file = parts[0] - range_str = parts[1] - start_end = range_str.split('-') - if len(start_end) == 2: - start = int(start_end[0]) - end = int(start_end[1]) - for i in range(start, end+1): - changed_lines.setdefault(file, set()).add(i) - else: - # 单行 - changed_lines.setdefault(file, set()).add(int(start_end[0])) - -# 解析 Checkstyle 报告 -tree = ET.parse("$REPORT_FILE") -root = tree.getroot() - -# 创建过滤后的根 -new_root = ET.Element("checkstyle", attrib=root.attrib) - -for file_elem in root.findall("file"): - file_name = file_elem.get("name") - # 获取相对于项目根目录的路径(可能带有绝对路径,需要规范化) - # 简单处理:取文件名部分,但为了匹配,我们只比较文件名(如果路径不同) - # 更健壮:使用文件名的 basename 或匹配路径结尾 - # 这里我们直接匹配字符串,因为 diff 输出的是相对路径,而 Checkstyle 输出绝对路径 - # 我们尝试使用相对路径匹配 - changed_set = changed_lines.get(file_name, set()) - if not changed_set: - # 尝试取 basename 匹配 - base = file_name.split('/')[-1] - for key in changed_lines: - if key.endswith(base): - changed_set = changed_lines[key] - break - - new_file = ET.SubElement(new_root, "file", attrib=file_elem.attrib) - errors_found = False - for error in file_elem.findall("error"): - line_num = int(error.get("line", 0)) - if line_num in changed_set: - new_file.append(error) - errors_found = True - if not errors_found: - # 如果该文件没有违规,则移除(但保留空文件无意义,可以跳过) - new_root.remove(new_file) - -# 写回过滤后的报告 -tree = ET.ElementTree(new_root) -tree.write("$FILTERED_REPORT", encoding="utf-8", xml_declaration=True) -EOF - -# 6. 统计过滤后的违规数 -if [ -f "$FILTERED_REPORT" ]; then - FILTERED_VIOLATIONS=$(grep -c '//' | \ + grep '//' | \ sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ while read -r line; do echo " $line" @@ -187,31 +81,22 @@ fi # 7. 输出到 GitHub Step Summary if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 增量行报告" + echo "## 📋 Checkstyle 报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $FILTERED_VIOLATIONS -eq 0 ]; then - echo "| 新增代码违规数 | ✅ **0** |" + if [ $VIOLATIONS -eq 0 ]; then + echo "| 违规数 | ✅ **0** |" else - echo "| 新增代码违规数 | ⚠️ **$FILTERED_VIOLATIONS** |" + echo "| 违规数 | ⚠️ **$VIOLATIONS** |" fi echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" - echo "| 检查范围 | 仅新增或修改的行 |" + echo "| 检查方式 | 对变更文件进行完整扫描 |" echo "" - # 使用环境变量构建链接 - echo "📄 [下载完整报告(所有文件)](${GH_SERVER_URL}/${GH_REPOSITORY}/actions/runs/${GH_RUN_ID})" - echo "📄 [下载过滤后报告(仅新增行)](${GH_SERVER_URL}/${GH_REPOSITORY}/actions/runs/${GH_RUN_ID})" + echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" } >> "$GITHUB_STEP_SUMMARY" echo "✅ Step Summary 已更新" fi -# 8. 替换原始报告为过滤后的报告(以便 Artifact 上传只包含过滤结果) -# 但为了保留完整报告,我们不上传过滤后的,而是上传原始和过滤两份。 -# 在 YAML 中,我们会上传整个 target/ 下的相关文件,所以无所谓。 - -# 9. 清理临时文件 -rm -f "$CHANGE_INFO_FILE" - -# 10. 始终以成功状态退出 +# 8. 始终以成功状态退出 exit 0 \ No newline at end of file From b1e0c25a9c843f5167db77f4dd15ef80c6de0b1a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:15:16 -0700 Subject: [PATCH 031/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 162c2b21..49f8daaa 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -57,5 +57,5 @@ jobs: name: checkstyle-report path: | **/target/checkstyle-result.xml - **/target/site/checkstyle.html + **/target/site/ if-no-files-found: warn From 81d4c6b9b256f7f788c449817b221ff265e3aa87 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:26:55 -0700 Subject: [PATCH 032/137] fix:Checkstyle check test --- checkstyle/huawei-checkstyle.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index a2a60652..3c3a42d5 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -204,6 +204,12 @@ + + + + + + From 3e5b3ad51d6f64656a49f6a81ff47c963eb43980 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:29:32 -0700 Subject: [PATCH 033/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 49f8daaa..68c46b38 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -57,5 +57,5 @@ jobs: name: checkstyle-report path: | **/target/checkstyle-result.xml - **/target/site/ + **/target/site if-no-files-found: warn From e5e068824703806ffcdbbf26e2866c87afe8ee36 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:33:17 -0700 Subject: [PATCH 034/137] fix:Checkstyle check test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a4bdd76f..75ea4963 100644 --- a/pom.xml +++ b/pom.xml @@ -239,7 +239,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.1 + 3.3.2 ./checkstyle/huawei-checkstyle.xml From 44ab636ac642f97d0aa28cb61065fb89c3e1e7b4 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 02:34:38 -0700 Subject: [PATCH 035/137] fix:Checkstyle check test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75ea4963..a4bdd76f 100644 --- a/pom.xml +++ b/pom.xml @@ -239,7 +239,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.2 + 3.3.1 ./checkstyle/huawei-checkstyle.xml From 08a216600d0d5e80a0e3a1e802760c0654a9ec3c Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 03:00:45 -0700 Subject: [PATCH 036/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 68c46b38..009140a2 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -57,5 +57,6 @@ jobs: name: checkstyle-report path: | **/target/checkstyle-result.xml - **/target/site + **/target/site/checkstyle.html + if-no-files-found: warn From fc0c4652978b235698262b5852afbf7ea79c491a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 03:07:19 -0700 Subject: [PATCH 037/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 1 - pom.xml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 009140a2..162c2b21 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -58,5 +58,4 @@ jobs: path: | **/target/checkstyle-result.xml **/target/site/checkstyle.html - if-no-files-found: warn diff --git a/pom.xml b/pom.xml index a4bdd76f..74015246 100644 --- a/pom.xml +++ b/pom.xml @@ -239,7 +239,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.1 + 3.6.0 ./checkstyle/huawei-checkstyle.xml From f9310076809cceb0475be9d5046b5a6aac27f11a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 03:11:35 -0700 Subject: [PATCH 038/137] fix:Checkstyle check test --- checkstyle/huawei-checkstyle.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index 3c3a42d5..5863decf 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -206,10 +206,7 @@ - - - - + From 625f4e9e37392f98a1c4381694a6cf1b139cbe00 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 05:12:35 -0700 Subject: [PATCH 039/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index f9b08516..01e02994 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -49,7 +49,6 @@ echo "🚀 执行 Checkstyle 扫描(完整文件)..." set +e mvn checkstyle:check \ -Dcheckstyle.includes="$FILES_LIST" \ - -Dcheckstyle.excludes="**/test/**/*.java" \ -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? set -e From 0ed020683a729774cb7e970ed078e5f71a2f6684 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 05:27:57 -0700 Subject: [PATCH 040/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 1 + checkstyle/huawei-checkstyle.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 01e02994..25135bb3 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -46,6 +46,7 @@ FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') # 4. 执行 Checkstyle 扫描(生成完整报告) echo "🚀 执行 Checkstyle 扫描(完整文件)..." +echo "FILES_LIST: $FILES_LIST" set +e mvn checkstyle:check \ -Dcheckstyle.includes="$FILES_LIST" \ diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index 5863decf..a926d82b 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -204,7 +204,7 @@ - + From 2730cfca15fe69a5777e6ee3d22b0c19b738099b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 14 Jul 2026 05:36:21 -0700 Subject: [PATCH 041/137] fix:Checkstyle check test --- .../it/common/utils/testCheckstyle.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java index 65b4c82f..38ef8956 100644 --- a/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java +++ b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java @@ -1,4 +1,6 @@ package com.tinyengine.it.common.utils; +import java.lang.reflect.Field; + /** * 类名错误:应使用 UpperCamelCase(首字母大写) * 这里故意写成了小写开头的 testCheckstyle @@ -21,6 +23,36 @@ public testCheckstyle(String name) { this._name = name; } + public void test() { + long value = 1l; // 错误:使用了小写 l + System.out.println(value); + } + public void longMethod() { + // 填充到超过 300 行,例如添加 301 个空行或打印语句 + for (int i = 0; i < 301; i++) { + System.out.println("line " + i); + } + } + + public void test1() { + if (true) { + if (true) { + if (true) { + if (true) { // 第4层嵌套,超过最大值3 + System.out.println("deep"); + } + } + } + } + } + + public void test2() { + String s = "hello"; + if (s == "hello") { // 错误:应使用 equals() + System.out.println("equal"); + } + } + /** * 方法名错误:不应包含大写字母,应使用 lowerCamelCase */ From a06b69435ad8987287dc4470246eb1dfdfcbbeb4 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 28 Jul 2026 05:56:43 -0700 Subject: [PATCH 042/137] fix:Checkstyle check test --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..dfb04fd9 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1 @@ +sonar.sourceEncoding=UTF-8 \ No newline at end of file From c0b862017417baa6e56001124bc9ea1f9c5cc1f5 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 00:00:20 -0700 Subject: [PATCH 043/137] fix:Checkstyle check test --- .../it/common/utils/CheckstyleValidation.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 base/src/main/java/com/tinyengine/it/common/utils/CheckstyleValidation.java diff --git a/base/src/main/java/com/tinyengine/it/common/utils/CheckstyleValidation.java b/base/src/main/java/com/tinyengine/it/common/utils/CheckstyleValidation.java new file mode 100644 index 00000000..c273d28d --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/common/utils/CheckstyleValidation.java @@ -0,0 +1,31 @@ +package com.tinyengine.it.common.utils; + +public class CheckstyleValidation { + // This class intentionally violates Checkstyle rules for testing GitHub Action + + public static final int CONSTANT = 42; // Valid constant name + + private int bad_variable_name; // Violates naming convention + + public CheckstyleValidation() { + // Empty constructor (violates EmptyBlock rule) + } + + public void badMethod() { + if (true) { + System.out.println("This is a bad method"); // Violates line length if too long + } else { + return; // SimplifyBooleanReturn violation + } + } + + public void multipleVariables() { + int a = 1, b = 2; // Violates MultipleVariableDeclarations rule + } + + public void longMethod() { // Violates MethodLength if too long + for (int i = 0; i < 100; i++) { + System.out.println("Line " + i); + } + } +} From 63a64b995e1dae81b3c85a577de7f9a823ab8213 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 00:22:24 -0700 Subject: [PATCH 044/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 1 + checkstyle/huawei-checkstyle.xml | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 25135bb3..986cf359 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -49,6 +49,7 @@ echo "🚀 执行 Checkstyle 扫描(完整文件)..." echo "FILES_LIST: $FILES_LIST" set +e mvn checkstyle:check \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ -Dcheckstyle.includes="$FILES_LIST" \ -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index a926d82b..07664f0b 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -225,4 +225,27 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9b1399918eb10440ff781b121efc6c0c20f81c8a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 00:22:40 -0700 Subject: [PATCH 045/137] fix:Checkstyle check test --- pom.xml | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74015246..a6d8c315 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ maven-checkstyle-plugin 3.6.0 - + ./checkstyle/huawei-checkstyle.xml false @@ -259,6 +259,54 @@ + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.21.0 + + + category/java/bestpractices.xml + category/java/codestyle.xml + category/java/design.xml + category/java/errorprone.xml + category/java/performance.xml + category/java/security.xml + + true + false + + + + pmd-check + verify + + check + + + + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.7.3.0 + + + spotbugs-check + verify + + check + + + + + Max + Low + true + + From 8413433b9682aa3e3a7cd117793313ba06d40895 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 00:34:33 -0700 Subject: [PATCH 046/137] fix:Checkstyle check test --- checkstyle/huawei-checkstyle.xml | 44 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index 07664f0b..de566f38 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -218,6 +218,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -226,26 +249,5 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 9fb67ea736a096c595f85d533809ced96bc97c5b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 01:11:27 -0700 Subject: [PATCH 047/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 3 +-- .github/workflows/checkstyle.yml | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 986cf359..ca183d3c 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -48,9 +48,8 @@ FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') echo "🚀 执行 Checkstyle 扫描(完整文件)..." echo "FILES_LIST: $FILES_LIST" set +e -mvn checkstyle:check \ +mvn -pl base checkstyle:check \ -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.includes="$FILES_LIST" \ -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? set -e diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 162c2b21..c7ceeb7d 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -25,7 +25,10 @@ jobs: with: java-version: '17' distribution: 'temurin' - + - name: Debug Checkstyle config + run: | + cd base + mvn checkstyle:check -X | grep -A 10 "Loading checkstyle" # 缓存 Maven 依赖,加速构建 - name: Cache Maven dependencies uses: actions/cache@v5 From 22022b4edc983cb041e7db824742c0b2bf85e1dc Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 01:46:36 -0700 Subject: [PATCH 048/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index c7ceeb7d..6798c151 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -25,10 +25,7 @@ jobs: with: java-version: '17' distribution: 'temurin' - - name: Debug Checkstyle config - run: | - cd base - mvn checkstyle:check -X | grep -A 10 "Loading checkstyle" + # 缓存 Maven 依赖,加速构建 - name: Cache Maven dependencies uses: actions/cache@v5 @@ -52,6 +49,10 @@ jobs: echo "=== 查找 checkstyle 文件 ===" find . -name "checkstyle*.xml" -o -name "checkstyle*.html" | while read f; do echo "找到: $f"; done + - name: Debug Checkstyle config + run: | + cd base + mvn checkstyle:check -X | grep -A 10 "Loading checkstyle" # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 From 3ceae07d971d331079c6bcf66ff4aa8bb053cab8 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 02:25:45 -0700 Subject: [PATCH 049/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index ca183d3c..09cada22 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -54,6 +54,13 @@ mvn -pl base checkstyle:check \ MVN_EXIT=$? set -e +# 额外生成 HTML 报告(不受违规影响,始终执行) +echo "📄 生成 HTML 报告..." +mvn -pl base checkstyle:checkstyle \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.outputFormat=html \ + -Dcheckstyle.violationSeverity=warning + # 5. 确定报告路径(根据项目结构调整) REPORT_FILE="base/target/checkstyle-result.xml" if [ ! -f "$REPORT_FILE" ]; then From 024bd3997f028bc0cdf120a084f0f28921ed9e2b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 03:31:41 -0700 Subject: [PATCH 050/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 6798c151..c99ce795 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -49,10 +49,13 @@ jobs: echo "=== 查找 checkstyle 文件 ===" find . -name "checkstyle*.xml" -o -name "checkstyle*.html" | while read f; do echo "找到: $f"; done - - name: Debug Checkstyle config + - name: Debug - Check HTML existence run: | - cd base - mvn checkstyle:check -X | grep -A 10 "Loading checkstyle" + echo "Searching for checkstyle.html:" + find . -name "checkstyle.html" -type f + echo "Also check site directory:" + ls -la base/target/site/ || echo "base/target/site not found" + # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 From 2f7db206fc759a4a505ac96157f6cbe02d562035 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 03:33:43 -0700 Subject: [PATCH 051/137] fix:Checkstyle check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index c99ce795..bef5ca55 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -64,5 +64,5 @@ jobs: name: checkstyle-report path: | **/target/checkstyle-result.xml - **/target/site/checkstyle.html + **/target/reports/ if-no-files-found: warn From 05cb819bd1e10208faf39591d4d341364d8ab6dd Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 03:34:20 -0700 Subject: [PATCH 052/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 09cada22..33ed2767 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -54,12 +54,6 @@ mvn -pl base checkstyle:check \ MVN_EXIT=$? set -e -# 额外生成 HTML 报告(不受违规影响,始终执行) -echo "📄 生成 HTML 报告..." -mvn -pl base checkstyle:checkstyle \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.outputFormat=html \ - -Dcheckstyle.violationSeverity=warning # 5. 确定报告路径(根据项目结构调整) REPORT_FILE="base/target/checkstyle-result.xml" From 70b30c92062a0fb930c5fa687e6ae7026fa9c597 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 03:40:29 -0700 Subject: [PATCH 053/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 6 ++++++ .github/workflows/checkstyle.yml | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 33ed2767..09cada22 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -54,6 +54,12 @@ mvn -pl base checkstyle:check \ MVN_EXIT=$? set -e +# 额外生成 HTML 报告(不受违规影响,始终执行) +echo "📄 生成 HTML 报告..." +mvn -pl base checkstyle:checkstyle \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.outputFormat=html \ + -Dcheckstyle.violationSeverity=warning # 5. 确定报告路径(根据项目结构调整) REPORT_FILE="base/target/checkstyle-result.xml" diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index bef5ca55..7bcda550 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -54,7 +54,7 @@ jobs: echo "Searching for checkstyle.html:" find . -name "checkstyle.html" -type f echo "Also check site directory:" - ls -la base/target/site/ || echo "base/target/site not found" + ls -la base/target/reports/ || echo "base/target/reports not found" # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report @@ -64,5 +64,6 @@ jobs: name: checkstyle-report path: | **/target/checkstyle-result.xml + **/target/checkstyle-checker.xml **/target/reports/ if-no-files-found: warn From 5d3ad7f2edf5c881289ea7fc44fec06dcd6bbe04 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 04:20:47 -0700 Subject: [PATCH 054/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 163 ++++++++++++++++++++++--------- .github/workflows/checkstyle.yml | 2 +- 2 files changed, 118 insertions(+), 47 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 09cada22..cca23538 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,15 +1,15 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) -# 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 -# 不阻断构建,生成完整报告 +# checkstyle-pr.sh - 增量检查(支持多模块,汇总统计) +# 功能:对本次提交中变更的 Java 文件,按模块分组执行 Checkstyle 检查 +# 不阻断构建,生成完整报告,汇总所有模块的违规数 # ============================================================ set -e echo "========================================" -echo " Checkstyle 增量检查" -echo " 扫描范围:本次变更的 Java 文件(完整文件)" +echo " Checkstyle 增量检查(多模块)" +echo " 扫描范围:本次变更的 Java 文件(按模块分组)" echo "========================================" # 1. 确定目标分支 @@ -41,69 +41,140 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 将文件列表转为逗号分隔 -FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') - -# 4. 执行 Checkstyle 扫描(生成完整报告) -echo "🚀 执行 Checkstyle 扫描(完整文件)..." -echo "FILES_LIST: $FILES_LIST" -set +e -mvn -pl base checkstyle:check \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.violationSeverity=warning -MVN_EXIT=$? -set -e +# 3. 按模块分组,提取模块内相对路径 +declare -A module_files +for file in $CHANGED_FILES; do + # 提取第一级目录作为模块名(例如 base, app, core 等) + module="${file%%/*}" + # 如果模块名为空(如文件在根目录),跳过或处理 + if [ -z "$module" ] || [ "$module" == "$file" ]; then + echo "⚠️ 忽略根目录文件: $file" + continue + fi + # 去掉模块前缀,得到相对路径 + rel="${file#$module/}" + # 追加到对应模块的列表中(逗号分隔) + if [ -z "${module_files[$module]}" ]; then + module_files[$module]="$rel" + else + module_files[$module]="${module_files[$module]},$rel" + fi +done -# 额外生成 HTML 报告(不受违规影响,始终执行) -echo "📄 生成 HTML 报告..." -mvn -pl base checkstyle:checkstyle \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.outputFormat=html \ - -Dcheckstyle.violationSeverity=warning - -# 5. 确定报告路径(根据项目结构调整) -REPORT_FILE="base/target/checkstyle-result.xml" -if [ ! -f "$REPORT_FILE" ]; then - echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" +if [ ${#module_files[@]} -eq 0 ]; then + echo "⚠️ 没有识别到任何模块的 Java 文件变更,跳过检查。" exit 0 fi -# 6. 统计违规数 -VIOLATIONS=$(grep -c '//' | \ - sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ - while read -r line; do - echo " $line" - done + echo "📋 违规摘要(前 30 条,仅显示第一个有违规的模块):" + # 取第一个有违规的模块显示摘要,避免输出过长 + for module in "${!module_files[@]}"; do + report_file="$module/target/checkstyle-result.xml" + if [ -f "$report_file" ] && [ $(grep -c '//' | \ + sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ + while read -r line; do + echo " $line" + done + break # 只显示第一个有违规的模块 + fi + done fi -# 7. 输出到 GitHub Step Summary +# 6. 输出到 GitHub Step Summary(汇总所有模块) if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 报告" + echo "## 📋 Checkstyle 报告(汇总)" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $VIOLATIONS -eq 0 ]; then - echo "| 违规数 | ✅ **0** |" + if [ $total_violations -eq 0 ]; then + echo "| 总违规数 | ✅ **0** |" else - echo "| 违规数 | ⚠️ **$VIOLATIONS** |" + echo "| 总违规数 | ⚠️ **$total_violations** |" + fi + echo "| 涉及模块 | **${!module_files[*]}** |" + echo "" + if [ $total_violations -gt 0 ]; then + echo "### 模块违规分布" + echo "$module_violations" | sed 's/^/ /' fi - echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" - echo "| 检查方式 | 对变更文件进行完整扫描 |" echo "" echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" } >> "$GITHUB_STEP_SUMMARY" echo "✅ Step Summary 已更新" fi -# 8. 始终以成功状态退出 +# 7. 始终以成功状态退出 exit 0 \ No newline at end of file diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 7bcda550..acfaaca6 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -53,7 +53,7 @@ jobs: run: | echo "Searching for checkstyle.html:" find . -name "checkstyle.html" -type f - echo "Also check site directory:" + echo "Also check reports directory:" ls -la base/target/reports/ || echo "base/target/reports not found" # 如果检查失败,仍然上传报告供查看 From ccbc2c9d9e74f7a11fe5211b72c8928309242179 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 04:43:42 -0700 Subject: [PATCH 055/137] fix:Checkstyle check test --- .github/scripts/checkstyle-pr.sh | 164 +++++++++---------------------- 1 file changed, 47 insertions(+), 117 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index cca23538..ffceefd5 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,15 +1,15 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - 增量检查(支持多模块,汇总统计) -# 功能:对本次提交中变更的 Java 文件,按模块分组执行 Checkstyle 检查 -# 不阻断构建,生成完整报告,汇总所有模块的违规数 +# checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) +# 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 +# 不阻断构建,生成完整报告 # ============================================================ set -e echo "========================================" -echo " Checkstyle 增量检查(多模块)" -echo " 扫描范围:本次变更的 Java 文件(按模块分组)" +echo " Checkstyle 增量检查" +echo " 扫描范围:本次变更的 Java 文件(完整文件)" echo "========================================" # 1. 确定目标分支 @@ -41,140 +41,70 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 按模块分组,提取模块内相对路径 -declare -A module_files -for file in $CHANGED_FILES; do - # 提取第一级目录作为模块名(例如 base, app, core 等) - module="${file%%/*}" - # 如果模块名为空(如文件在根目录),跳过或处理 - if [ -z "$module" ] || [ "$module" == "$file" ]; then - echo "⚠️ 忽略根目录文件: $file" - continue - fi - # 去掉模块前缀,得到相对路径 - rel="${file#$module/}" - # 追加到对应模块的列表中(逗号分隔) - if [ -z "${module_files[$module]}" ]; then - module_files[$module]="$rel" - else - module_files[$module]="${module_files[$module]},$rel" - fi -done +# 3. 将文件列表转为逗号分隔 +FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') + +# 4. 执行 Checkstyle 扫描(生成完整报告) +echo "🚀 执行 Checkstyle 扫描(完整文件)..." +echo "FILES_LIST: $FILES_LIST" +set +e +mvn -pl base checkstyle:check \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.includes="**/testCheckstyle.java" \ + -Dcheckstyle.violationSeverity=warning +MVN_EXIT=$? +set -e -if [ ${#module_files[@]} -eq 0 ]; then - echo "⚠️ 没有识别到任何模块的 Java 文件变更,跳过检查。" +# 额外生成 HTML 报告(不受违规影响,始终执行) +echo "📄 生成 HTML 报告..." +mvn -pl base checkstyle:checkstyle \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.outputFormat=html \ + -Dcheckstyle.violationSeverity=warning + +# 5. 确定报告路径(根据项目结构调整) +REPORT_FILE="base/target/checkstyle-result.xml" +if [ ! -f "$REPORT_FILE" ]; then + echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 fi -echo "📝 按模块分组后的相对路径:" -for module in "${!module_files[@]}"; do - echo " $module: ${module_files[$module]}" -done -echo "----------------------------------------" - -# 4. 对每个模块执行 Checkstyle 检查 -for module in "${!module_files[@]}"; do - file_list="${module_files[$module]}" - echo "🚀 扫描模块: $module" - echo " 文件列表: $file_list" - - # 检查模块目录是否存在且包含 pom.xml - if [ ! -d "$module" ] || [ ! -f "$module/pom.xml" ]; then - echo "⚠️ 模块目录 $module 不存在或没有 pom.xml,跳过。" - continue - fi - - # 执行检查(XML 报告) - echo " - 生成 XML 报告..." - set +e - (cd "$module" && mvn checkstyle:check \ - -Dcheckstyle.config.location=../checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.includes="$file_list" \ - -Dcheckstyle.violationSeverity=warning) - if [ $? -ne 0 ]; then - echo " ⚠️ 模块 $module 的 Checkstyle 检查失败(但继续)" - fi - set -e - - # 生成 HTML 报告(始终执行) - echo " - 生成 HTML 报告..." - set +e - (cd "$module" && mvn checkstyle:checkstyle \ - -Dcheckstyle.config.location=../checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.includes="$file_list" \ - -Dcheckstyle.outputFormat=html \ - -Dcheckstyle.violationSeverity=warning) - if [ $? -ne 0 ]; then - echo " ⚠️ 模块 $module 的 HTML 报告生成失败(但继续)" - fi - set -e - echo "" -done - -# 5. 汇总所有模块的违规数 -total_violations=0 -module_violations="" - -# 遍历所有变更的模块,统计违规数 -for module in "${!module_files[@]}"; do - report_file="$module/target/checkstyle-result.xml" - if [ -f "$report_file" ]; then - count=$(grep -c '//' | \ - sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ - while read -r line; do - echo " $line" - done - break # 只显示第一个有违规的模块 - fi - done + echo "📋 违规摘要(前 30 条):" + grep '//' | \ + sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ + while read -r line; do + echo " $line" + done fi -# 6. 输出到 GitHub Step Summary(汇总所有模块) +# 7. 输出到 GitHub Step Summary if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 报告(汇总)" + echo "## 📋 Checkstyle 报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $total_violations -eq 0 ]; then - echo "| 总违规数 | ✅ **0** |" + if [ $VIOLATIONS -eq 0 ]; then + echo "| 违规数 | ✅ **0** |" else - echo "| 总违规数 | ⚠️ **$total_violations** |" - fi - echo "| 涉及模块 | **${!module_files[*]}** |" - echo "" - if [ $total_violations -gt 0 ]; then - echo "### 模块违规分布" - echo "$module_violations" | sed 's/^/ /' + echo "| 违规数 | ⚠️ **$VIOLATIONS** |" fi + echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" + echo "| 检查方式 | 对变更文件进行完整扫描 |" echo "" echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" } >> "$GITHUB_STEP_SUMMARY" echo "✅ Step Summary 已更新" fi -# 7. 始终以成功状态退出 +# 8. 始终以成功状态退出 exit 0 \ No newline at end of file From f3eecf9544b5e81a24bf81d2c05b7a727f14c4f3 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 18:44:48 -0700 Subject: [PATCH 056/137] fix:pmd test --- .github/workflows/pmd.yml | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/pmd.yml diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml new file mode 100644 index 00000000..1ec80c19 --- /dev/null +++ b/.github/workflows/pmd.yml @@ -0,0 +1,43 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: pmd + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + schedule: + - cron: '41 12 * * 3' + +permissions: + contents: read + +jobs: + pmd-code-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + - name: Run PMD + id: pmd + uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + with: + rulesets: 'rulesets/java/quickstart.xml' + sourcePath: 'src/main/java' + analyzeModifiedFilesOnly: false + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: pmd-report.sarif \ No newline at end of file From 4384f2227b9b3e8d9ee02d520c63ed55d91ad7af Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 18:51:19 -0700 Subject: [PATCH 057/137] fix:pmd test --- .github/workflows/pmd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 1ec80c19..8ea39107 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -23,6 +23,8 @@ jobs: security-events: write # for github/codeql-action/upload-sarif to upload SARIF results actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true steps: - uses: actions/checkout@v4 - name: Set up JDK 17 From eac5e85e8075cf2f0559777caa475260ad7d2c38 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 18:58:10 -0700 Subject: [PATCH 058/137] fix:pmd test --- .github/workflows/pmd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 8ea39107..23cdfa52 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -36,6 +36,7 @@ jobs: id: pmd uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 with: + version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'src/main/java' analyzeModifiedFilesOnly: false From f6012b6f15f9b5624e5b14c2f11e10b76d69bad4 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 19:00:27 -0700 Subject: [PATCH 059/137] fix:pmd test --- .github/workflows/pmd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 23cdfa52..917d8d52 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -34,9 +34,8 @@ jobs: distribution: 'temurin' - name: Run PMD id: pmd - uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + uses: pmd/pmd-github-action@v5 with: - version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'src/main/java' analyzeModifiedFilesOnly: false From b632204bfae4979bb1be2079d5ecf051cadb96c9 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 19:06:19 -0700 Subject: [PATCH 060/137] fix:pmd test --- .github/workflows/pmd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 917d8d52..23cdfa52 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -34,8 +34,9 @@ jobs: distribution: 'temurin' - name: Run PMD id: pmd - uses: pmd/pmd-github-action@v5 + uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 with: + version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'src/main/java' analyzeModifiedFilesOnly: false From 1a260c13db076fc63fdd33bbec67c88ef157503f Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 19:13:22 -0700 Subject: [PATCH 061/137] fix:pmd test --- .github/workflows/pmd.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 23cdfa52..fb676e8b 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -38,9 +38,10 @@ jobs: with: version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' - sourcePath: 'src/main/java' + sourcePath: 'base/src/main/java' analyzeModifiedFilesOnly: false - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: pmd-report.sarif \ No newline at end of file + sarif_file: pmd-report.sarif + name: pmd-report \ No newline at end of file From 4e52367c2058166e82154e80c95a7116d0b298b3 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 19:22:57 -0700 Subject: [PATCH 062/137] fix:pmd test --- .github/scripts/checkstyle-pr.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index ffceefd5..624e0b08 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -107,4 +107,14 @@ if [ -n "$GITHUB_STEP_SUMMARY" ]; then fi # 8. 始终以成功状态退出 -exit 0 \ No newline at end of file +# ================================================ +# 7. 根据违规数决定构建状态(拦截 PR) +# ================================================ +if [ $VIOLATIONS -eq 0 ]; then + echo "✅ 检查通过,构建成功。" + exit 0 +else + echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" + # 为了让 GitHub Actions 标记为失败,退出码设为 1 + exit 1 +fi \ No newline at end of file From 81a56c3dd2e57d79a793e715019e01f6acb22423 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 19:58:41 -0700 Subject: [PATCH 063/137] fix:pmd test --- .github/workflows/pmd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index fb676e8b..a740a22d 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -40,6 +40,7 @@ jobs: rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'base/src/main/java' analyzeModifiedFilesOnly: false + outputSarif: false - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: From 2cdffc4e43db3bce01a24e1c552db4c10d63023a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 20:05:57 -0700 Subject: [PATCH 064/137] fix:pmd test --- .github/workflows/pmd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index a740a22d..1cee8d13 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -41,6 +41,9 @@ jobs: sourcePath: 'base/src/main/java' analyzeModifiedFilesOnly: false outputSarif: false + uploadSarif: false + uploadSarifReport: false + - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: From aae082d64b25db7f8c8568d919b1098d5aecea6e Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Mon, 3 Aug 2026 20:09:21 -0700 Subject: [PATCH 065/137] fix:pmd test --- .github/workflows/pmd.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 1cee8d13..e0473c97 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -40,8 +40,6 @@ jobs: rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'base/src/main/java' analyzeModifiedFilesOnly: false - outputSarif: false - uploadSarif: false uploadSarifReport: false - name: Upload SARIF file From 1f12a916c1104290b3294703b72c462e9d428047 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 01:37:52 -0700 Subject: [PATCH 066/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index e0473c97..c96a0022 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -34,7 +34,7 @@ jobs: distribution: 'temurin' - name: Run PMD id: pmd - uses: pmd/pmd-github-action@967a81f8b657c87f7c3e96b62301cb1a48efef29 + uses: pmd/pmd-github-action@v2 with: version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' From fc02bcb5b1c8f5dc3c2a1bc7e1b0a91e4749ac10 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 01:45:34 -0700 Subject: [PATCH 067/137] fix:pmd test --- .github/workflows/pmd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index c96a0022..fd80e8c8 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -25,6 +25,7 @@ jobs: runs-on: ubuntu-latest env: ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 - name: Set up JDK 17 @@ -45,5 +46,4 @@ jobs: - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: pmd-report.sarif - name: pmd-report \ No newline at end of file + sarif_file: pmd-report.sarif \ No newline at end of file From 3b63a2bf553653190baf893d097a7472b4fba09b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 03:43:29 -0700 Subject: [PATCH 068/137] fix:pmd test --- .github/workflows/pmd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index fd80e8c8..74926498 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -24,7 +24,6 @@ jobs: actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status runs-on: ubuntu-latest env: - ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - uses: actions/checkout@v4 From 1654700ca17f7043861dc1a075a9491369df18db Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:05:11 -0700 Subject: [PATCH 069/137] fix:pmd test --- .github/workflows/pmd.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 74926498..372dd8c0 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -45,4 +45,10 @@ jobs: - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: pmd-report.sarif \ No newline at end of file + sarif_file: pmd-report.sarif + + - name: Upload SARIF file as artifact + uses: actions/upload-artifact@v4 + with: + name: pmd-sarif-report # 给工件起一个有意义的名字 + path: pmd-report.sarif \ No newline at end of file From b38b50a6255f10bb8061c739483011d334eef87d Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:12:32 -0700 Subject: [PATCH 070/137] fix:pmd test --- .github/workflows/pmd.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 372dd8c0..bde81647 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -51,4 +51,17 @@ jobs: uses: actions/upload-artifact@v4 with: name: pmd-sarif-report # 给工件起一个有意义的名字 - path: pmd-report.sarif \ No newline at end of file + path: pmd-report.sarif + + - name: Convert SARIF to HTML + uses: b-zurg/sarif-converter@v1 + with: + sarif: pmd-report.sarif # 输入的 SARIF 文件路径 + output: pmd-report.html # 输出的 HTML 文件路径 + type: html # 输出格式,默认为 html + + - name: Upload HTML report + uses: actions/upload-artifact@v4 + with: + name: pmd-html-report + path: pmd-report.html \ No newline at end of file From 96e63c7114f5d1fb03baf5138c87da7c1c51b0f2 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:18:09 -0700 Subject: [PATCH 071/137] fix:pmd test --- .github/workflows/pmd.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index bde81647..808d0b9c 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -42,6 +42,9 @@ jobs: analyzeModifiedFilesOnly: false uploadSarifReport: false + - name: Convert SARIF to HTML + run: npx sarif-explorer --input pmd-report.sarif --output pmd-report.html + - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 with: @@ -53,13 +56,6 @@ jobs: name: pmd-sarif-report # 给工件起一个有意义的名字 path: pmd-report.sarif - - name: Convert SARIF to HTML - uses: b-zurg/sarif-converter@v1 - with: - sarif: pmd-report.sarif # 输入的 SARIF 文件路径 - output: pmd-report.html # 输出的 HTML 文件路径 - type: html # 输出格式,默认为 html - - name: Upload HTML report uses: actions/upload-artifact@v4 with: From 8e5fb54b12784988a345f9b53e37b680d2b82fbe Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:23:11 -0700 Subject: [PATCH 072/137] fix:pmd test --- .github/workflows/pmd.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 808d0b9c..a2710acc 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -42,8 +42,10 @@ jobs: analyzeModifiedFilesOnly: false uploadSarifReport: false - - name: Convert SARIF to HTML - run: npx sarif-explorer --input pmd-report.sarif --output pmd-report.html + - name: Install sarif-tools and convert to HTML + run: | + pip install sarif-tools + sarif html pmd-report.sarif --output pmd-report.html - name: Upload SARIF file uses: github/codeql-action/upload-sarif@v3 From c8355ae49e14409b96978fe1329d7e457313ad35 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:32:50 -0700 Subject: [PATCH 073/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index a2710acc..307910a3 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -39,7 +39,7 @@ jobs: version: '6.55.0' rulesets: 'rulesets/java/quickstart.xml' sourcePath: 'base/src/main/java' - analyzeModifiedFilesOnly: false + analyzeModifiedFilesOnly: true uploadSarifReport: false - name: Install sarif-tools and convert to HTML From 424842f9b873d7ff5c1fe2220f8790fe2f88bb90 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:40:30 -0700 Subject: [PATCH 074/137] fix:pmd test --- .github/workflows/pmd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 307910a3..f3e49055 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -41,6 +41,7 @@ jobs: sourcePath: 'base/src/main/java' analyzeModifiedFilesOnly: true uploadSarifReport: false + failOnViolation: true - name: Install sarif-tools and convert to HTML run: | From 1ff2d9fd1d0fd57f9a5339a0922e82552b2d94a9 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 04:49:06 -0700 Subject: [PATCH 075/137] fix:pmd test --- .github/workflows/pmd.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index f3e49055..4d40e35e 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -63,4 +63,14 @@ jobs: uses: actions/upload-artifact@v4 with: name: pmd-html-report - path: pmd-report.html \ No newline at end of file + path: pmd-report.html + + - name: Check PMD violations + run: | + if [[ ${{ steps.pmd.outputs.violations }} -eq 0 ]]; then + echo "✅ PMD 未发现代码问题,构建通过。" + exit 0 + else + echo "❌ PMD 发现 ${{ steps.pmd.outputs.violations }} 个代码问题,构建失败。" + exit 1 + fi \ No newline at end of file From c6d5bb44155bf3a20e6611eaf76ea2a526bc3903 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:00:17 -0700 Subject: [PATCH 076/137] fix:pmd test --- .../tinyengine/it/test/SampleViolations.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/src/main/java/com/tinyengine/it/test/SampleViolations.java diff --git a/app/src/main/java/com/tinyengine/it/test/SampleViolations.java b/app/src/main/java/com/tinyengine/it/test/SampleViolations.java new file mode 100644 index 00000000..d967edbd --- /dev/null +++ b/app/src/main/java/com/tinyengine/it/test/SampleViolations.java @@ -0,0 +1,95 @@ +package com.tinyengine.it.test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class SampleViolations { + // 1. 未使用的私有字段 (UnusedPrivateField) + private String unusedField = "I am not used"; + + // 2. 常量命名不符合规范 (ConstantNamingConventions) → 应全大写 + public static final String myConstant = "should be UPPER_CASE"; + + // 3. 字段命名不符合规范 (FieldNamingConventions) → 应 camelCase,这里合规,略过 + + // 4. 不应使用 'l' 作为变量名 (AvoidFieldNameMatchingMethodName) 但更常见的是短变量名 + + public void demoMethod() { + // 5. 未使用的局部变量 (UnusedLocalVariable) + int unusedLocal = 42; + + // 6. 短变量名 (ShortVariable) + int a = 10; + + // 7. 使用 System.out.println (SystemPrintln) + System.out.println("This is a direct system print"); + + // 8. 魔法数字 (MagicNumber) + int magic = (int) (3.14 * 2); // 3.14 和 2 都是魔法数字 + + // 9. 在循环中创建对象 (AvoidInstantiatingObjectsInLoops) + List list = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + String s = new String("loop object"); // 无必要 + list.add(s); + } + + // 10. 空的 catch 块 (EmptyCatchBlock) + try { + Files.readAllLines(Paths.get("nonexistent.txt")); + } catch (IOException e) { + // empty + } + + // 11. 未关闭的资源 (CloseResource) + try { + Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:test", "sa", ""); + // 使用 conn 后未关闭 + } catch (SQLException e) { + e.printStackTrace(); + } + + // 12. 使用 'return' 语句过多 (MultipleReturns) 或过于复杂 + if (magic > 0) { + return; + } else { + // 多个 return 点 + } + + // 13. 未使用的参数 (UnusedFormalParameter) + unusedMethod("hello", 123); + } + + private void unusedMethod(String param1, int param2) { + // 这里只使用了 param1,param2 未使用 + System.out.println(param1); + } + + // 14. 方法过长 (TooLongMethod) 但这里仅作演示,可通过增加行数制造,但不必 + // 15. 参数过多 (TooManyParameters) + public void tooManyParams(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) { + // 10个参数,可能触发参数过多规则 + } + + // 16. 不应使用 'Thread.sleep' 在循环中?不强制 + + // 17. 使用 'ConcurrentHashMap' 代替 'Hashtable'?不强制 + + // 18. 使用 'BigDecimal' 构造函数时避免 double (BigDecimalConstructor) + public void bigDecimalIssue() { + java.math.BigDecimal bd = new java.math.BigDecimal(0.1); // 可能触发 + } + + // 19. 使用 'StringBuffer' 而不是 'StringBuilder'? (StringBufferUsage) + public void stringBufferUsage() { + StringBuffer sb = new StringBuffer(); // 可能建议使用 StringBuilder + sb.append("test"); + } + +} From 1a7a16586eb00d3aab10436cc813524200d1f51e Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:02:38 -0700 Subject: [PATCH 077/137] fix:pmd test --- .github/workflows/pmd.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 4d40e35e..4d20332b 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -42,6 +42,16 @@ jobs: analyzeModifiedFilesOnly: true uploadSarifReport: false failOnViolation: true + - name: Run PMD + id: pmd + uses: pmd/pmd-github-action@v2 + with: + version: '6.55.0' + rulesets: 'rulesets/java/quickstart.xml' + sourcePath: 'app/src/main/java' + analyzeModifiedFilesOnly: true + uploadSarifReport: false + failOnViolation: true - name: Install sarif-tools and convert to HTML run: | From 2ede5e42d8e78f3214583f3d5d7fefe0d8fbd4ab Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:03:50 -0700 Subject: [PATCH 078/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 4d20332b..3a29133e 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -43,7 +43,7 @@ jobs: uploadSarifReport: false failOnViolation: true - name: Run PMD - id: pmd + id: pmd2 uses: pmd/pmd-github-action@v2 with: version: '6.55.0' From 6937a6915ec47bb96221d9060fff5c4eb768a94e Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:12:24 -0700 Subject: [PATCH 079/137] fix:pmd test --- .github/workflows/pmd.yml | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 3a29133e..c6b92a6b 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -32,26 +32,29 @@ jobs: with: java-version: '17' distribution: 'temurin' - - name: Run PMD + - name: Run PMD on both modules id: pmd - uses: pmd/pmd-github-action@v2 - with: - version: '6.55.0' - rulesets: 'rulesets/java/quickstart.xml' - sourcePath: 'base/src/main/java' - analyzeModifiedFilesOnly: true - uploadSarifReport: false - failOnViolation: true - - name: Run PMD - id: pmd2 - uses: pmd/pmd-github-action@v2 - with: - version: '6.55.0' - rulesets: 'rulesets/java/quickstart.xml' - sourcePath: 'app/src/main/java' - analyzeModifiedFilesOnly: true - uploadSarifReport: false - failOnViolation: true + run: | + PMD_VERSION="6.55.0" + curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip + unzip -q pmd.zip -d pmd + export PATH="$PWD/pmd/bin:$PATH" + + pmd check --no-cache \ + -d base/src/main/java \ + -d app/src/main/java \ + -f sarif \ + -R rulesets/java/quickstart.xml \ + -r pmd-report.sarif + + # 提取违规数量 + if [ -f pmd-report.sarif ]; then + violations=$(jq '.runs[0].results | length' pmd-report.sarif) + else + violations=0 + fi + echo "violations=$violations" >> $GITHUB_OUTPUT + - name: Install sarif-tools and convert to HTML run: | From 3afd8109afdcd110411c628f46aff3a557ecc5a8 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:18:26 -0700 Subject: [PATCH 080/137] fix:pmd test --- .github/workflows/pmd.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index c6b92a6b..daec2975 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -37,7 +37,9 @@ jobs: run: | PMD_VERSION="6.55.0" curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip - unzip -q pmd.zip -d pmd + unzip -q pmd.zip -d . + # 重命名文件夹以简化路径 + mv pmd-bin-${PMD_VERSION} pmd export PATH="$PWD/pmd/bin:$PATH" pmd check --no-cache \ From 55804740291a7e1f2b5bd586720278b0fac53272 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:21:20 -0700 Subject: [PATCH 081/137] fix:pmd test --- .github/workflows/pmd.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index daec2975..30b578f2 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -37,11 +37,15 @@ jobs: run: | PMD_VERSION="6.55.0" curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip - unzip -q pmd.zip -d . - # 重命名文件夹以简化路径 + unzip -q pmd.zip + # 解压后目录为 pmd-bin-6.55.0,重命名为 pmd mv pmd-bin-${PMD_VERSION} pmd export PATH="$PWD/pmd/bin:$PATH" + # 调试:检查 pmd 是否可执行 + which pmd || echo "pmd not found" + ls -la pmd/bin/ + pmd check --no-cache \ -d base/src/main/java \ -d app/src/main/java \ From dec82dd23a64a8724ced1efc6a9ec97d0d7f36de Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:22:47 -0700 Subject: [PATCH 082/137] fix:pmd test --- .github/workflows/pmd.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 30b578f2..3429e750 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -38,11 +38,8 @@ jobs: PMD_VERSION="6.55.0" curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip unzip -q pmd.zip - # 解压后目录为 pmd-bin-6.55.0,重命名为 pmd mv pmd-bin-${PMD_VERSION} pmd export PATH="$PWD/pmd/bin:$PATH" - - # 调试:检查 pmd 是否可执行 which pmd || echo "pmd not found" ls -la pmd/bin/ @@ -53,7 +50,6 @@ jobs: -R rulesets/java/quickstart.xml \ -r pmd-report.sarif - # 提取违规数量 if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) else From 631f8a1549cffa852e7ac2599ed8d7fbdbb190b7 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:27:44 -0700 Subject: [PATCH 083/137] fix:pmd test --- .github/workflows/pmd.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 3429e750..6d470702 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -39,11 +39,10 @@ jobs: curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip unzip -q pmd.zip mv pmd-bin-${PMD_VERSION} pmd - export PATH="$PWD/pmd/bin:$PATH" - which pmd || echo "pmd not found" - ls -la pmd/bin/ + PMD_CMD="$PWD/pmd/bin/run.sh" + chmod +x "$PMD_CMD" - pmd check --no-cache \ + "$PMD_CMD" check --no-cache \ -d base/src/main/java \ -d app/src/main/java \ -f sarif \ From 82a65e336f23bb635dbb6a73bf457a7b53695b6f Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:31:48 -0700 Subject: [PATCH 084/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 6d470702..17bc1c14 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -42,7 +42,7 @@ jobs: PMD_CMD="$PWD/pmd/bin/run.sh" chmod +x "$PMD_CMD" - "$PMD_CMD" check --no-cache \ + "$PMD_CMD" pmd check --no-cache \ -d base/src/main/java \ -d app/src/main/java \ -f sarif \ From f55422b1ef657c73b6b823fa4753bcedf4c7f518 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:36:05 -0700 Subject: [PATCH 085/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 17bc1c14..fa153d28 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -42,7 +42,7 @@ jobs: PMD_CMD="$PWD/pmd/bin/run.sh" chmod +x "$PMD_CMD" - "$PMD_CMD" pmd check --no-cache \ + "$PMD_CMD" pmd --no-cache \ -d base/src/main/java \ -d app/src/main/java \ -f sarif \ From a18fcdc3223772252bc49a55c95ecb5b119e1201 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:44:03 -0700 Subject: [PATCH 086/137] fix:pmd test --- .github/workflows/pmd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index fa153d28..ded700d8 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -47,7 +47,8 @@ jobs: -d app/src/main/java \ -f sarif \ -R rulesets/java/quickstart.xml \ - -r pmd-report.sarif + -r pmd-report.sarif \ + --no-fail-on-violation # 添加此行 if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) From 9fc20ade12ad8df0c4039697bd332cbbb06316cb Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 05:48:32 -0700 Subject: [PATCH 087/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index ded700d8..4df0b6fa 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -48,7 +48,7 @@ jobs: -f sarif \ -R rulesets/java/quickstart.xml \ -r pmd-report.sarif \ - --no-fail-on-violation # 添加此行 + -failOnViolation false if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) From 6f87f7a9104326a4b2fa503ff36d6405dc3ebf63 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 19:13:38 -0700 Subject: [PATCH 088/137] fix:pmd test --- .github/workflows/pmd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 4df0b6fa..b371ab1c 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -47,8 +47,7 @@ jobs: -d app/src/main/java \ -f sarif \ -R rulesets/java/quickstart.xml \ - -r pmd-report.sarif \ - -failOnViolation false + -r pmd-report.sarif || true if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) From 472d06bc829bf0f4af9c939857da9562cfa69897 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 19:26:49 -0700 Subject: [PATCH 089/137] fix:pmd test --- .github/workflows/pmd.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index b371ab1c..993fb396 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -32,9 +32,24 @@ jobs: with: java-version: '17' distribution: 'temurin' - - name: Run PMD on both modules + - name: Run PMD on changed Java files only id: pmd run: | + # 获取变更的 Java 文件 + CHANGED_FILES=$(git diff --name-only origin/develop HEAD | grep '\.java$' || true) + if [ -z "$CHANGED_FILES" ]; then + echo "No Java files changed, skipping PMD." + echo "violations=0" >> $GITHUB_OUTPUT + exit 0 + fi + + # 生成文件列表 + > changed-files.txt + for file in $CHANGED_FILES; do + echo "$PWD/$file" >> changed-files.txt + done + + # 下载 PMD PMD_VERSION="6.55.0" curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip unzip -q pmd.zip @@ -42,13 +57,14 @@ jobs: PMD_CMD="$PWD/pmd/bin/run.sh" chmod +x "$PMD_CMD" + # 扫描变更文件 "$PMD_CMD" pmd --no-cache \ - -d base/src/main/java \ - -d app/src/main/java \ - -f sarif \ - -R rulesets/java/quickstart.xml \ - -r pmd-report.sarif || true + -filelist changed-files.txt \ + -f sarif \ + -R rulesets/java/quickstart.xml \ + -r pmd-report.sarif || true + # 统计违规 if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) else From 02039308964baabfd37527e9a8620d7bf0f4aad9 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 19:33:24 -0700 Subject: [PATCH 090/137] fix:pmd test --- .github/workflows/pmd.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 993fb396..13d13be3 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -32,24 +32,36 @@ jobs: with: java-version: '17' distribution: 'temurin' + fetch-depth: 0 # Fetch all history for all branches and tags - name: Run PMD on changed Java files only id: pmd run: | - # 获取变更的 Java 文件 - CHANGED_FILES=$(git diff --name-only origin/develop HEAD | grep '\.java$' || true) + # 1. 确定目标分支(从环境变量获取) + if [ -n "$GITHUB_BASE_REF" ]; then + BASE_BRANCH="$GITHUB_BASE_REF" + else + # 如果是 push 事件,回退到 main 或 develop + BASE_BRANCH="develop" # 或 main,根据项目调整 + fi + + # 2. 确保目标分支的远程引用存在 + git fetch origin "$BASE_BRANCH" --depth=1 || true + + # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) + CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No Java files changed, skipping PMD." echo "violations=0" >> $GITHUB_OUTPUT exit 0 fi - # 生成文件列表 + # 4. 生成文件列表(绝对路径) > changed-files.txt for file in $CHANGED_FILES; do echo "$PWD/$file" >> changed-files.txt done - # 下载 PMD + # 5. 下载 PMD PMD_VERSION="6.55.0" curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip unzip -q pmd.zip @@ -57,20 +69,23 @@ jobs: PMD_CMD="$PWD/pmd/bin/run.sh" chmod +x "$PMD_CMD" - # 扫描变更文件 + # 6. 扫描变更的 Java 文件 "$PMD_CMD" pmd --no-cache \ -filelist changed-files.txt \ -f sarif \ -R rulesets/java/quickstart.xml \ -r pmd-report.sarif || true - # 统计违规 + # 7. 统计违规数 if [ -f pmd-report.sarif ]; then violations=$(jq '.runs[0].results | length' pmd-report.sarif) else violations=0 fi echo "violations=$violations" >> $GITHUB_OUTPUT + + # 清理 + rm -f changed-files.txt - name: Install sarif-tools and convert to HTML From c5e762c308be58dca8e2be4a1b0b245da093e221 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 19:47:39 -0700 Subject: [PATCH 091/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 13d13be3..220499f9 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -71,7 +71,7 @@ jobs: # 6. 扫描变更的 Java 文件 "$PMD_CMD" pmd --no-cache \ - -filelist changed-files.txt \ + --file-list changed-files.txt \ -f sarif \ -R rulesets/java/quickstart.xml \ -r pmd-report.sarif || true From 8506a6cb989edd6a4ff5c59cfc95e7b3c4873a76 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 19:52:58 -0700 Subject: [PATCH 092/137] fix:pmd test --- .github/workflows/pmd.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 220499f9..74fadb8b 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -49,6 +49,15 @@ jobs: # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) + + echo "📝 变更的 Java 文件列表:" + if [ -n "$CHANGED_FILES" ]; then + echo "$CHANGED_FILES" + else + echo "(无)" + fi + echo "----------------------------------------" + if [ -z "$CHANGED_FILES" ]; then echo "No Java files changed, skipping PMD." echo "violations=0" >> $GITHUB_OUTPUT From d766de0a6e012bbfc5e2e7c555fc1a7ace0c8d9b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 20:03:41 -0700 Subject: [PATCH 093/137] fix:pmd test --- .github/workflows/pmd.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 74fadb8b..7a9b29e8 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -26,13 +26,14 @@ jobs: env: FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 + with: + fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 - name: Set up JDK 17 - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: '17' distribution: 'temurin' - fetch-depth: 0 # Fetch all history for all branches and tags - name: Run PMD on changed Java files only id: pmd run: | @@ -108,7 +109,7 @@ jobs: sarif_file: pmd-report.sarif - name: Upload SARIF file as artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 with: name: pmd-sarif-report # 给工件起一个有意义的名字 path: pmd-report.sarif From 09fa71f71d31498f106e134375b6a6d7bbe1cb89 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 20:08:41 -0700 Subject: [PATCH 094/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 7a9b29e8..b1476a49 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -104,7 +104,7 @@ jobs: sarif html pmd-report.sarif --output pmd-report.html - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v3 + uses: github/codeql-action/upload-sarif@v4 with: sarif_file: pmd-report.sarif From dceff4f0791d996549036080b00d17ab280d3d47 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 23:32:37 -0700 Subject: [PATCH 095/137] fix:pmd test --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index b1476a49..c2cd6919 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -104,7 +104,7 @@ jobs: sarif html pmd-report.sarif --output pmd-report.html - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@v7 with: sarif_file: pmd-report.sarif From 7979afe5d9fa3796465a1d4fb6bf9c364e43869b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Tue, 4 Aug 2026 23:36:36 -0700 Subject: [PATCH 096/137] fix:pmd test --- .github/workflows/pmd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index c2cd6919..3ac2e69e 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -104,18 +104,18 @@ jobs: sarif html pmd-report.sarif --output pmd-report.html - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v7 + uses: github/codeql-action/upload-sarif@v4 with: sarif_file: pmd-report.sarif - name: Upload SARIF file as artifact - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v7 with: name: pmd-sarif-report # 给工件起一个有意义的名字 path: pmd-report.sarif - name: Upload HTML report - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: pmd-html-report path: pmd-report.html From 3c9faf2e6afeb9144a1704c1598798af8264e651 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:03:09 -0700 Subject: [PATCH 097/137] fix:code check test --- .github/workflows/codecheck.yml | 83 +++++++++++++++++++++++++++++++++ pom.xml | 10 ++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/codecheck.yml diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml new file mode 100644 index 00000000..3c9aa406 --- /dev/null +++ b/.github/workflows/codecheck.yml @@ -0,0 +1,83 @@ +name: Code Quality Checks + +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +jobs: + static-analysis: + runs-on: ubuntu-24.04 + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + java-version: '17' + distribution: 'temurin' + + - name: Cache Maven dependencies + uses: actions/cache@v5 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + # ==================== validate 阶段:Checkstyle(增量检查,允许失败) ==================== + - name: [validate] Run Checkstyle + id: checkstyle + continue-on-error: true # 允许失败,不影响后续编译 + run: bash .github/scripts/checkstyle-pr.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} + + # ==================== 编译(供 PMD 和 SpotBugs 使用) ==================== + - name: Compile project + run: mvn compile -DskipTests + + # ==================== verify 阶段:PMD(直接失败,按你的 pom 配置) ==================== + - name: [verify] Run PMD (including CPD) + id: pmd + # 不设置 continue-on-error,因为 failOnViolation=true 时,mvn 会返回非零,我们希望构建失败 + run: mvn pmd:check pmd:cpd-check + + # ==================== verify 阶段:SpotBugs(如果 PMD 通过则执行) ==================== + - name: [verify] Run SpotBugs + id: spotbugs + # 如果你的 SpotBugs 也配置了 failOnError=true,这里也建议不加 continue-on-error + # 否则可保留 continue-on-error: true + run: mvn spotbugs:check + + # ==================== 调试:列出所有报告(仅当执行成功时) ==================== + - name: Debug - list all reports + if: always() # 即使失败也尝试列出已生成的文件 + run: | + echo "当前工作目录: $(pwd)" + echo "=== 查找所有检查报告 ===" + find . \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) -type f | while read f; do echo "找到: $f"; done + + # ==================== 上传所有报告(无论成功与否) ==================== + - name: Upload reports + if: always() + uses: actions/upload-artifact@v7 + with: + name: quality-reports + path: | + **/target/checkstyle-result.xml + **/target/checkstyle-checker.xml + **/target/reports/ + **/target/pmd.xml + **/target/cpd.xml + **/target/spotbugsXml.xml + if-no-files-found: warn diff --git a/pom.xml b/pom.xml index a6d8c315..442fdce5 100644 --- a/pom.xml +++ b/pom.xml @@ -276,6 +276,7 @@ true false + 100 @@ -285,6 +286,14 @@ check + + cpd-check + verify + + cpd-check + + + @@ -305,6 +314,7 @@ Max Low true + true From 11b9e95122bf7bfae72127350f45395f94165784 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:07:20 -0700 Subject: [PATCH 098/137] fix:code check test --- .github/workflows/codecheck.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index 3c9aa406..08361093 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -34,7 +34,6 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - # ==================== validate 阶段:Checkstyle(增量检查,允许失败) ==================== - name: [validate] Run Checkstyle id: checkstyle continue-on-error: true # 允许失败,不影响后续编译 From 474acefc6a11d3bce3b6ee4f3bc65ad6a3e74fb7 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:18:38 -0700 Subject: [PATCH 099/137] fix:code check test --- .github/workflows/codecheck.yml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index 08361093..843f917c 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -31,42 +31,34 @@ jobs: with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + restore-keys: + - ${{ runner.os }}-maven- - - name: [validate] Run Checkstyle + - name: Run Checkstyle id: checkstyle - continue-on-error: true # 允许失败,不影响后续编译 + continue-on-error: true run: bash .github/scripts/checkstyle-pr.sh env: GITHUB_BASE_REF: ${{ github.base_ref }} - # ==================== 编译(供 PMD 和 SpotBugs 使用) ==================== - name: Compile project run: mvn compile -DskipTests - # ==================== verify 阶段:PMD(直接失败,按你的 pom 配置) ==================== - - name: [verify] Run PMD (including CPD) + - name: Run PMD (including CPD) id: pmd - # 不设置 continue-on-error,因为 failOnViolation=true 时,mvn 会返回非零,我们希望构建失败 run: mvn pmd:check pmd:cpd-check - # ==================== verify 阶段:SpotBugs(如果 PMD 通过则执行) ==================== - - name: [verify] Run SpotBugs + - name: Run SpotBugs id: spotbugs - # 如果你的 SpotBugs 也配置了 failOnError=true,这里也建议不加 continue-on-error - # 否则可保留 continue-on-error: true run: mvn spotbugs:check - # ==================== 调试:列出所有报告(仅当执行成功时) ==================== - - name: Debug - list all reports - if: always() # 即使失败也尝试列出已生成的文件 + - name: Debug reports + if: always() run: | - echo "当前工作目录: $(pwd)" - echo "=== 查找所有检查报告 ===" - find . \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) -type f | while read f; do echo "找到: $f"; done + echo "Current directory: $(pwd)" + echo "=== Find all report files ===" + find . -type f \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) - # ==================== 上传所有报告(无论成功与否) ==================== - name: Upload reports if: always() uses: actions/upload-artifact@v7 @@ -79,4 +71,4 @@ jobs: **/target/pmd.xml **/target/cpd.xml **/target/spotbugsXml.xml - if-no-files-found: warn + if-no-files-found: warn \ No newline at end of file From ff97070bfc043495e26deaa89542994ccca7f48b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:22:24 -0700 Subject: [PATCH 100/137] fix:code check test --- .github/workflows/codecheck.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index 843f917c..e7f58b73 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -31,8 +31,8 @@ jobs: with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: - - ${{ runner.os }}-maven- + restore-keys: | + ${{ runner.os }}-maven- - name: Run Checkstyle id: checkstyle From cc7d8552011169e3d2c9c296ac46b6cd19c811e8 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:26:05 -0700 Subject: [PATCH 101/137] fix:code check test --- .github/workflows/codecheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index e7f58b73..717507f0 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -9,7 +9,7 @@ on: - develop jobs: - static-analysis: + checkstyle: runs-on: ubuntu-24.04 env: FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true From 5811ddc0f09821336231d3438ef30288c1a1e73b Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:32:24 -0700 Subject: [PATCH 102/137] fix:code check test --- .github/workflows/codecheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml index 717507f0..e0cc1a25 100644 --- a/.github/workflows/codecheck.yml +++ b/.github/workflows/codecheck.yml @@ -1,4 +1,4 @@ -name: Code Quality Checks +name: Checkstyle Code on: push: From 8b81772654f08eed0a52d1b5820ed38acbe91f86 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:33:40 -0700 Subject: [PATCH 103/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index acfaaca6..8408192c 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -1,4 +1,4 @@ -name: Checkstyle Code Quality +name: Checkstyle Code on: push: From 790c02c17769feb050ed5dd57ffc386a99162212 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Wed, 5 Aug 2026 02:35:47 -0700 Subject: [PATCH 104/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 8408192c..9f8f7451 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -1,4 +1,4 @@ -name: Checkstyle Code +name: Checkstyle Code Quality1 on: push: From a518629ceeea3d8a88460e3614b23597e49ceb2c Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 00:45:01 -0700 Subject: [PATCH 105/137] fix:code check test --- .github/workflows/checkstyle.yml | 69 -------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 .github/workflows/checkstyle.yml diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml deleted file mode 100644 index 9f8f7451..00000000 --- a/.github/workflows/checkstyle.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Checkstyle Code Quality1 - -on: - push: - branches: - - develop - pull_request: - branches: - - develop - -jobs: - checkstyle: - runs-on: ubuntu-24.04 - env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 - - - name: Set up JDK 17 - uses: actions/setup-java@v5 - with: - java-version: '17' - distribution: 'temurin' - - # 缓存 Maven 依赖,加速构建 - - name: Cache Maven dependencies - uses: actions/cache@v5 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - # 直接运行 Checkstyle 检查(不执行完整的 package) - - name: Run Checkstyle - run: bash .github/scripts/checkstyle-pr.sh - env: - GITHUB_BASE_REF: ${{ github.base_ref }} - - - name: Debug - list all checkstyle reports - run: | - echo "当前工作目录: $(pwd)" - echo "=== 列出所有 target 目录 ===" - find . -type d -name "target" -exec echo "目录: {}" \; -exec ls -la {}/ \; - echo "=== 查找 checkstyle 文件 ===" - find . -name "checkstyle*.xml" -o -name "checkstyle*.html" | while read f; do echo "找到: $f"; done - - - name: Debug - Check HTML existence - run: | - echo "Searching for checkstyle.html:" - find . -name "checkstyle.html" -type f - echo "Also check reports directory:" - ls -la base/target/reports/ || echo "base/target/reports not found" - - # 如果检查失败,仍然上传报告供查看 - - name: Upload Checkstyle report - if: always() # 即使失败也上传报告 - uses: actions/upload-artifact@v7 - with: - name: checkstyle-report - path: | - **/target/checkstyle-result.xml - **/target/checkstyle-checker.xml - **/target/reports/ - if-no-files-found: warn From c635530c9184ee84405df8447545433ba5b2c7d3 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 00:48:38 -0700 Subject: [PATCH 106/137] fix:code check test --- .github/workflows/checkstyle.yml | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/checkstyle.yml diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml new file mode 100644 index 00000000..f3a273d5 --- /dev/null +++ b/.github/workflows/checkstyle.yml @@ -0,0 +1,69 @@ +name: Checkstyle Code Quality1 + +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +jobs: + checkstyle: + runs-on: ubuntu-24.04 + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 + + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + java-version: '17' + distribution: 'temurin' + + # 缓存 Maven 依赖,加速构建 + - name: Cache Maven dependencies + uses: actions/cache@v5 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + # 直接运行 Checkstyle 检查(不执行完整的 package) + - name: Run Checkstyle + run: bash .github/scripts/checkstyle-pr.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} + + - name: Debug - list all checkstyle reports + run: | + echo "当前工作目录: $(pwd)" + echo "=== 列出所有 target 目录 ===" + find . -type d -name "target" -exec echo "目录: {}" \; -exec ls -la {}/ \; + echo "=== 查找 checkstyle 文件 ===" + find . -name "checkstyle*.xml" -o -name "checkstyle*.html" | while read f; do echo "找到: $f"; done + + - name: Debug - Check HTML existence + run: | + echo "Searching for checkstyle.html:" + find . -name "checkstyle.html" -type f + echo "Also check reports directory:" + ls -la base/target/reports/ || echo "base/target/reports not found" + + # 如果检查失败,仍然上传报告供查看 + - name: Upload Checkstyle report + if: always() # 即使失败也上传报告 + uses: actions/upload-artifact@v7 + with: + name: checkstyle-report + path: | + **/target/checkstyle-result.xml + **/target/checkstyle-checker.xml + **/target/reports/ + if-no-files-found: warn From cdff35b82bc2a16e8c39315ae926578e59bf1d51 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 00:49:41 -0700 Subject: [PATCH 107/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 624e0b08..1b7cbdd5 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -116,5 +116,5 @@ if [ $VIOLATIONS -eq 0 ]; then else echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" # 为了让 GitHub Actions 标记为失败,退出码设为 1 - exit 1 + exit 0 fi \ No newline at end of file From 469d300e2f4a935e033a629d2638739e23b57eeb Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 00:53:22 -0700 Subject: [PATCH 108/137] fix:code check test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 442fdce5..693938d1 100644 --- a/pom.xml +++ b/pom.xml @@ -274,7 +274,7 @@ category/java/performance.xml category/java/security.xml - true + false false 100 From 3d3435e7cdee934b8fd8262ff1350b5155d19446 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 00:57:17 -0700 Subject: [PATCH 109/137] fix:code check test --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 693938d1..497853fe 100644 --- a/pom.xml +++ b/pom.xml @@ -285,6 +285,10 @@ check + + false + + cpd-check @@ -292,7 +296,9 @@ cpd-check - + + false + From 9bdc0ad145248fe82c171b65c74b6777e282d3fd Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:17:21 -0700 Subject: [PATCH 110/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 2 +- .github/workflows/checkstyle.yml | 98 +++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 1b7cbdd5..816b8f56 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -112,7 +112,7 @@ fi # ================================================ if [ $VIOLATIONS -eq 0 ]; then echo "✅ 检查通过,构建成功。" - exit 0 + exit 1 else echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" # 为了让 GitHub Actions 标记为失败,退出码设为 1 diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index f3a273d5..b9464a2f 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -1,4 +1,4 @@ -name: Checkstyle Code Quality1 +name: Checkstyle Code Quality on: push: @@ -67,3 +67,99 @@ jobs: **/target/checkstyle-checker.xml **/target/reports/ if-no-files-found: warn + + - name: Run PMD on changed Java files only + id: pmd + run: | + # 1. 确定目标分支(从环境变量获取) + if [ -n "$GITHUB_BASE_REF" ]; then + BASE_BRANCH="$GITHUB_BASE_REF" + else + # 如果是 push 事件,回退到 main 或 develop + BASE_BRANCH="develop" # 或 main,根据项目调整 + fi + + # 2. 确保目标分支的远程引用存在 + git fetch origin "$BASE_BRANCH" --depth=1 || true + + # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) + CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) + + echo "📝 变更的 Java 文件列表:" + if [ -n "$CHANGED_FILES" ]; then + echo "$CHANGED_FILES" + else + echo "(无)" + fi + echo "----------------------------------------" + + if [ -z "$CHANGED_FILES" ]; then + echo "No Java files changed, skipping PMD." + echo "violations=0" >> $GITHUB_OUTPUT + exit 0 + fi + + # 4. 生成文件列表(绝对路径) + > changed-files.txt + for file in $CHANGED_FILES; do + echo "$PWD/$file" >> changed-files.txt + done + + # 5. 下载 PMD + PMD_VERSION="6.55.0" + curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip + unzip -q pmd.zip + mv pmd-bin-${PMD_VERSION} pmd + PMD_CMD="$PWD/pmd/bin/run.sh" + chmod +x "$PMD_CMD" + + # 6. 扫描变更的 Java 文件 + "$PMD_CMD" pmd --no-cache \ + --file-list changed-files.txt \ + -f sarif \ + -R rulesets/java/quickstart.xml \ + -r pmd-report.sarif || true + + # 7. 统计违规数 + if [ -f pmd-report.sarif ]; then + violations=$(jq '.runs[0].results | length' pmd-report.sarif) + else + violations=0 + fi + echo "violations=$violations" >> $GITHUB_OUTPUT + + # 清理 + rm -f changed-files.txt + + + - name: Install sarif-tools and convert to HTML + run: | + pip install sarif-tools + sarif html pmd-report.sarif --output pmd-report.html + + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v4 + with: + sarif_file: pmd-report.sarif + + - name: Upload SARIF file as artifact + uses: actions/upload-artifact@v7 + with: + name: pmd-sarif-report # 给工件起一个有意义的名字 + path: pmd-report.sarif + + - name: Upload HTML report + uses: actions/upload-artifact@v7 + with: + name: pmd-html-report + path: pmd-report.html + + - name: Check PMD violations + run: | + if [[ ${{ steps.pmd.outputs.violations }} -eq 0 ]]; then + echo "✅ PMD 未发现代码问题,构建通过。" + exit 0 + else + echo "❌ PMD 发现 ${{ steps.pmd.outputs.violations }} 个代码问题,构建失败。" + exit 1 + fi From 2cd2420cadbd45e5ce1eb76f1568998f371ce016 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:20:23 -0700 Subject: [PATCH 111/137] fix:code check test --- .github/workflows/codecheck.yml | 74 ------------------ .github/workflows/pmd.yml | 131 -------------------------------- 2 files changed, 205 deletions(-) delete mode 100644 .github/workflows/codecheck.yml delete mode 100644 .github/workflows/pmd.yml diff --git a/.github/workflows/codecheck.yml b/.github/workflows/codecheck.yml deleted file mode 100644 index e0cc1a25..00000000 --- a/.github/workflows/codecheck.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Checkstyle Code - -on: - push: - branches: - - develop - pull_request: - branches: - - develop - -jobs: - checkstyle: - runs-on: ubuntu-24.04 - env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Set up JDK 17 - uses: actions/setup-java@v5 - with: - java-version: '17' - distribution: 'temurin' - - - name: Cache Maven dependencies - uses: actions/cache@v5 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - - name: Run Checkstyle - id: checkstyle - continue-on-error: true - run: bash .github/scripts/checkstyle-pr.sh - env: - GITHUB_BASE_REF: ${{ github.base_ref }} - - - name: Compile project - run: mvn compile -DskipTests - - - name: Run PMD (including CPD) - id: pmd - run: mvn pmd:check pmd:cpd-check - - - name: Run SpotBugs - id: spotbugs - run: mvn spotbugs:check - - - name: Debug reports - if: always() - run: | - echo "Current directory: $(pwd)" - echo "=== Find all report files ===" - find . -type f \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) - - - name: Upload reports - if: always() - uses: actions/upload-artifact@v7 - with: - name: quality-reports - path: | - **/target/checkstyle-result.xml - **/target/checkstyle-checker.xml - **/target/reports/ - **/target/pmd.xml - **/target/cpd.xml - **/target/spotbugsXml.xml - if-no-files-found: warn \ No newline at end of file diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml deleted file mode 100644 index 3ac2e69e..00000000 --- a/.github/workflows/pmd.yml +++ /dev/null @@ -1,131 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: pmd - -on: - push: - branches: [ "develop" ] - pull_request: - branches: [ "develop" ] - schedule: - - cron: '41 12 * * 3' - -permissions: - contents: read - -jobs: - pmd-code-scan: - permissions: - contents: read # for actions/checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status - runs-on: ubuntu-latest - env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true - steps: - - uses: actions/checkout@v5 - with: - fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 - - name: Set up JDK 17 - uses: actions/setup-java@v5 - with: - java-version: '17' - distribution: 'temurin' - - name: Run PMD on changed Java files only - id: pmd - run: | - # 1. 确定目标分支(从环境变量获取) - if [ -n "$GITHUB_BASE_REF" ]; then - BASE_BRANCH="$GITHUB_BASE_REF" - else - # 如果是 push 事件,回退到 main 或 develop - BASE_BRANCH="develop" # 或 main,根据项目调整 - fi - - # 2. 确保目标分支的远程引用存在 - git fetch origin "$BASE_BRANCH" --depth=1 || true - - # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) - CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) - - echo "📝 变更的 Java 文件列表:" - if [ -n "$CHANGED_FILES" ]; then - echo "$CHANGED_FILES" - else - echo "(无)" - fi - echo "----------------------------------------" - - if [ -z "$CHANGED_FILES" ]; then - echo "No Java files changed, skipping PMD." - echo "violations=0" >> $GITHUB_OUTPUT - exit 0 - fi - - # 4. 生成文件列表(绝对路径) - > changed-files.txt - for file in $CHANGED_FILES; do - echo "$PWD/$file" >> changed-files.txt - done - - # 5. 下载 PMD - PMD_VERSION="6.55.0" - curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip - unzip -q pmd.zip - mv pmd-bin-${PMD_VERSION} pmd - PMD_CMD="$PWD/pmd/bin/run.sh" - chmod +x "$PMD_CMD" - - # 6. 扫描变更的 Java 文件 - "$PMD_CMD" pmd --no-cache \ - --file-list changed-files.txt \ - -f sarif \ - -R rulesets/java/quickstart.xml \ - -r pmd-report.sarif || true - - # 7. 统计违规数 - if [ -f pmd-report.sarif ]; then - violations=$(jq '.runs[0].results | length' pmd-report.sarif) - else - violations=0 - fi - echo "violations=$violations" >> $GITHUB_OUTPUT - - # 清理 - rm -f changed-files.txt - - - - name: Install sarif-tools and convert to HTML - run: | - pip install sarif-tools - sarif html pmd-report.sarif --output pmd-report.html - - - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v4 - with: - sarif_file: pmd-report.sarif - - - name: Upload SARIF file as artifact - uses: actions/upload-artifact@v7 - with: - name: pmd-sarif-report # 给工件起一个有意义的名字 - path: pmd-report.sarif - - - name: Upload HTML report - uses: actions/upload-artifact@v7 - with: - name: pmd-html-report - path: pmd-report.html - - - name: Check PMD violations - run: | - if [[ ${{ steps.pmd.outputs.violations }} -eq 0 ]]; then - echo "✅ PMD 未发现代码问题,构建通过。" - exit 0 - else - echo "❌ PMD 发现 ${{ steps.pmd.outputs.violations }} 个代码问题,构建失败。" - exit 1 - fi \ No newline at end of file From 49167974fe7c91e5f1bf518640e7d17711f55c1c Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:26:52 -0700 Subject: [PATCH 112/137] fix:code check test --- .github/workflows/checkstyle.yml | 95 ---------------------- .github/workflows/pmd.yml | 131 +++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/pmd.yml diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index b9464a2f..0c5f02af 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -68,98 +68,3 @@ jobs: **/target/reports/ if-no-files-found: warn - - name: Run PMD on changed Java files only - id: pmd - run: | - # 1. 确定目标分支(从环境变量获取) - if [ -n "$GITHUB_BASE_REF" ]; then - BASE_BRANCH="$GITHUB_BASE_REF" - else - # 如果是 push 事件,回退到 main 或 develop - BASE_BRANCH="develop" # 或 main,根据项目调整 - fi - - # 2. 确保目标分支的远程引用存在 - git fetch origin "$BASE_BRANCH" --depth=1 || true - - # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) - CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) - - echo "📝 变更的 Java 文件列表:" - if [ -n "$CHANGED_FILES" ]; then - echo "$CHANGED_FILES" - else - echo "(无)" - fi - echo "----------------------------------------" - - if [ -z "$CHANGED_FILES" ]; then - echo "No Java files changed, skipping PMD." - echo "violations=0" >> $GITHUB_OUTPUT - exit 0 - fi - - # 4. 生成文件列表(绝对路径) - > changed-files.txt - for file in $CHANGED_FILES; do - echo "$PWD/$file" >> changed-files.txt - done - - # 5. 下载 PMD - PMD_VERSION="6.55.0" - curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip - unzip -q pmd.zip - mv pmd-bin-${PMD_VERSION} pmd - PMD_CMD="$PWD/pmd/bin/run.sh" - chmod +x "$PMD_CMD" - - # 6. 扫描变更的 Java 文件 - "$PMD_CMD" pmd --no-cache \ - --file-list changed-files.txt \ - -f sarif \ - -R rulesets/java/quickstart.xml \ - -r pmd-report.sarif || true - - # 7. 统计违规数 - if [ -f pmd-report.sarif ]; then - violations=$(jq '.runs[0].results | length' pmd-report.sarif) - else - violations=0 - fi - echo "violations=$violations" >> $GITHUB_OUTPUT - - # 清理 - rm -f changed-files.txt - - - - name: Install sarif-tools and convert to HTML - run: | - pip install sarif-tools - sarif html pmd-report.sarif --output pmd-report.html - - - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v4 - with: - sarif_file: pmd-report.sarif - - - name: Upload SARIF file as artifact - uses: actions/upload-artifact@v7 - with: - name: pmd-sarif-report # 给工件起一个有意义的名字 - path: pmd-report.sarif - - - name: Upload HTML report - uses: actions/upload-artifact@v7 - with: - name: pmd-html-report - path: pmd-report.html - - - name: Check PMD violations - run: | - if [[ ${{ steps.pmd.outputs.violations }} -eq 0 ]]; then - echo "✅ PMD 未发现代码问题,构建通过。" - exit 0 - else - echo "❌ PMD 发现 ${{ steps.pmd.outputs.violations }} 个代码问题,构建失败。" - exit 1 - fi diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml new file mode 100644 index 00000000..3ac2e69e --- /dev/null +++ b/.github/workflows/pmd.yml @@ -0,0 +1,131 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: pmd + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + schedule: + - cron: '41 12 * * 3' + +permissions: + contents: read + +jobs: + pmd-code-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + java-version: '17' + distribution: 'temurin' + - name: Run PMD on changed Java files only + id: pmd + run: | + # 1. 确定目标分支(从环境变量获取) + if [ -n "$GITHUB_BASE_REF" ]; then + BASE_BRANCH="$GITHUB_BASE_REF" + else + # 如果是 push 事件,回退到 main 或 develop + BASE_BRANCH="develop" # 或 main,根据项目调整 + fi + + # 2. 确保目标分支的远程引用存在 + git fetch origin "$BASE_BRANCH" --depth=1 || true + + # 3. 获取变更的 Java 文件(比较当前 HEAD 与目标分支) + CHANGED_FILES=$(git diff --name-only "origin/$BASE_BRANCH" HEAD | grep '\.java$' || true) + + echo "📝 变更的 Java 文件列表:" + if [ -n "$CHANGED_FILES" ]; then + echo "$CHANGED_FILES" + else + echo "(无)" + fi + echo "----------------------------------------" + + if [ -z "$CHANGED_FILES" ]; then + echo "No Java files changed, skipping PMD." + echo "violations=0" >> $GITHUB_OUTPUT + exit 0 + fi + + # 4. 生成文件列表(绝对路径) + > changed-files.txt + for file in $CHANGED_FILES; do + echo "$PWD/$file" >> changed-files.txt + done + + # 5. 下载 PMD + PMD_VERSION="6.55.0" + curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip + unzip -q pmd.zip + mv pmd-bin-${PMD_VERSION} pmd + PMD_CMD="$PWD/pmd/bin/run.sh" + chmod +x "$PMD_CMD" + + # 6. 扫描变更的 Java 文件 + "$PMD_CMD" pmd --no-cache \ + --file-list changed-files.txt \ + -f sarif \ + -R rulesets/java/quickstart.xml \ + -r pmd-report.sarif || true + + # 7. 统计违规数 + if [ -f pmd-report.sarif ]; then + violations=$(jq '.runs[0].results | length' pmd-report.sarif) + else + violations=0 + fi + echo "violations=$violations" >> $GITHUB_OUTPUT + + # 清理 + rm -f changed-files.txt + + + - name: Install sarif-tools and convert to HTML + run: | + pip install sarif-tools + sarif html pmd-report.sarif --output pmd-report.html + + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v4 + with: + sarif_file: pmd-report.sarif + + - name: Upload SARIF file as artifact + uses: actions/upload-artifact@v7 + with: + name: pmd-sarif-report # 给工件起一个有意义的名字 + path: pmd-report.sarif + + - name: Upload HTML report + uses: actions/upload-artifact@v7 + with: + name: pmd-html-report + path: pmd-report.html + + - name: Check PMD violations + run: | + if [[ ${{ steps.pmd.outputs.violations }} -eq 0 ]]; then + echo "✅ PMD 未发现代码问题,构建通过。" + exit 0 + else + echo "❌ PMD 发现 ${{ steps.pmd.outputs.violations }} 个代码问题,构建失败。" + exit 1 + fi \ No newline at end of file From 40eb809c35ca5c252dbbd69e48fa31adeef5d338 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:30:13 -0700 Subject: [PATCH 113/137] fix:code check test --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 497853fe..73977f4a 100644 --- a/pom.xml +++ b/pom.xml @@ -274,7 +274,7 @@ category/java/performance.xml category/java/security.xml - false + true false 100 @@ -286,7 +286,7 @@ check - false + true @@ -297,7 +297,7 @@ cpd-check - false + true From 8e46d1e8454f67af3887e21495c24441dfdfc7ea Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:42:00 -0700 Subject: [PATCH 114/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 816b8f56..11d73088 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -50,7 +50,6 @@ echo "FILES_LIST: $FILES_LIST" set +e mvn -pl base checkstyle:check \ -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.includes="**/testCheckstyle.java" \ -Dcheckstyle.violationSeverity=warning MVN_EXIT=$? set -e From 4efd3d7d442e4785df8aeced29cff540f1803f3d Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:43:32 -0700 Subject: [PATCH 115/137] fix:code check test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 73977f4a..d3151069 100644 --- a/pom.xml +++ b/pom.xml @@ -244,7 +244,7 @@ ./checkstyle/huawei-checkstyle.xml - false + true warning xml From 1d2dab3d17ae5a5c8c4dc25a691cc0dea1c2fcae Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 01:46:19 -0700 Subject: [PATCH 116/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 11d73088..0daab3c1 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -111,9 +111,9 @@ fi # ================================================ if [ $VIOLATIONS -eq 0 ]; then echo "✅ 检查通过,构建成功。" - exit 1 + exit 0 else echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" # 为了让 GitHub Actions 标记为失败,退出码设为 1 - exit 0 + exit 1 fi \ No newline at end of file From e7e38710315d355b0a5ed204c706e20f89afde56 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 02:11:20 -0700 Subject: [PATCH 117/137] fix:code check test --- .../java/com/tinyengine/it/common/utils/testCheckstyle.java | 6 ++++++ pom.xml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java index 38ef8956..0649b1f4 100644 --- a/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java +++ b/base/src/main/java/com/tinyengine/it/common/utils/testCheckstyle.java @@ -70,6 +70,7 @@ public void SayHello() { */ public void doSomething() { // 方法体为空或简单,但缺少注释 + } /** @@ -108,4 +109,9 @@ public static void StaticMethod() { static { ANOTHER_CONST = "Init"; } + + void test3(){ + String json = "{\"key\":\"value\",\"number\":123}"; + byte[] jsonBytes = json.getBytes(); + } } diff --git a/pom.xml b/pom.xml index d3151069..a95ec1b5 100644 --- a/pom.xml +++ b/pom.xml @@ -248,6 +248,8 @@ warning xml + **/*.java + From fe9022995b148e51e4062e870349118cfb505891 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 02:31:06 -0700 Subject: [PATCH 118/137] fix:code check test --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a95ec1b5..0e3e03c3 100644 --- a/pom.xml +++ b/pom.xml @@ -248,7 +248,10 @@ warning xml - **/*.java + + ${project.basedir}/src/main/java + ${project.basedir}/src/test/java + From c58b1be8e3ffffcdfbeac1f59df474c98bc01806 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 03:43:45 -0700 Subject: [PATCH 119/137] fix:code check test --- checkstyle/huawei-checkstyle.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checkstyle/huawei-checkstyle.xml b/checkstyle/huawei-checkstyle.xml index de566f38..ae341aac 100644 --- a/checkstyle/huawei-checkstyle.xml +++ b/checkstyle/huawei-checkstyle.xml @@ -44,7 +44,7 @@ allowMissingThrowsTags: 是否忽略对throws注释的检查 allowMissingReturnTag: 是否忽略对return注释的检查 --> - + @@ -94,7 +94,7 @@ - + From 97df9cf4506ce25c4b31f51afd8196bdd4d5525a Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 04:56:41 -0700 Subject: [PATCH 120/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 150 +++++++++++++++--------- .github/scripts/pmd-pr.sh | 90 ++++++++++++++ .github/scripts/spotbugs-incremental.sh | 74 ++++++++++++ .github/workflows/checkstyle.yml | 72 ++++++++++++ pom.xml | 6 +- 5 files changed, 335 insertions(+), 57 deletions(-) create mode 100644 .github/scripts/pmd-pr.sh create mode 100644 .github/scripts/spotbugs-incremental.sh diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 0daab3c1..27feafed 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,15 +1,15 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) -# 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 -# 不阻断构建,生成完整报告 +# checkstyle-pr.sh - Checkstyle 增量扫描(多模块,包含测试) +# 功能:只扫描本次提交中变更的 Java 文件(所有模块,src/main 和 src/test) +# 生成报告,根据违规数决定退出码 # ============================================================ set -e echo "========================================" -echo " Checkstyle 增量检查" -echo " 扫描范围:本次变更的 Java 文件(完整文件)" +echo " Checkstyle 增量扫描(多模块)" +echo " 扫描范围:所有模块的变更 Java 文件(包含测试)" echo "========================================" # 1. 确定目标分支 @@ -29,7 +29,7 @@ else echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" fi -# 2. 获取变更的 Java 文件 +# 2. 获取变更的 Java 文件(所有模块) CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) if [ -z "$CHANGED_FILES" ]; then @@ -41,79 +41,117 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 将文件列表转为逗号分隔 -FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') - -# 4. 执行 Checkstyle 扫描(生成完整报告) -echo "🚀 执行 Checkstyle 扫描(完整文件)..." -echo "FILES_LIST: $FILES_LIST" -set +e -mvn -pl base checkstyle:check \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.violationSeverity=warning -MVN_EXIT=$? -set -e +# 3. 按模块分组,提取模块内相对路径 +declare -A module_files +for file in $CHANGED_FILES; do + # 提取第一级目录作为模块名(例如 base, app, core 等) + module="${file%%/*}" + # 如果模块名为空或文件在根目录,跳过 + if [ -z "$module" ] || [ "$module" == "$file" ]; then + echo "⚠️ 忽略根目录文件: $file" + continue + fi + # 去掉模块前缀,得到相对路径 + rel="${file#$module/}" + # 追加到对应模块的列表中(逗号分隔) + if [ -z "${module_files[$module]}" ]; then + module_files[$module]="$rel" + else + module_files[$module]="${module_files[$module]},$rel" + fi +done -# 额外生成 HTML 报告(不受违规影响,始终执行) -echo "📄 生成 HTML 报告..." -mvn -pl base checkstyle:checkstyle \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.outputFormat=html \ - -Dcheckstyle.violationSeverity=warning - -# 5. 确定报告路径(根据项目结构调整) -REPORT_FILE="base/target/checkstyle-result.xml" -if [ ! -f "$REPORT_FILE" ]; then - echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" +if [ ${#module_files[@]} -eq 0 ]; then + echo "⚠️ 没有识别到任何模块,跳过检查。" exit 0 fi -# 6. 统计违规数 -VIOLATIONS=$(grep -c '//' | \ - sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ - while read -r line; do - echo " $line" - done + echo "⚠️ 总计发现 $total_violations 个违规。" fi -# 7. 输出到 GitHub Step Summary +# 6. 输出到 Step Summary(可选) if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 报告" + echo "## 📋 Checkstyle 汇总报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $VIOLATIONS -eq 0 ]; then - echo "| 违规数 | ✅ **0** |" + if [ $total_violations -eq 0 ]; then + echo "| 总违规数 | ✅ **0** |" else - echo "| 违规数 | ⚠️ **$VIOLATIONS** |" + echo "| 总违规数 | ⚠️ **$total_violations** |" fi - echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" - echo "| 检查方式 | 对变更文件进行完整扫描 |" + echo "| 涉及模块 | ${!module_files[*]} |" echo "" - echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" + echo "📥 完整报告已作为 Artifact 上传。" } >> "$GITHUB_STEP_SUMMARY" - echo "✅ Step Summary 已更新" fi -# 8. 始终以成功状态退出 -# ================================================ -# 7. 根据违规数决定构建状态(拦截 PR) -# ================================================ -if [ $VIOLATIONS -eq 0 ]; then +# 7. 根据违规数决定构建状态 +if [ $total_violations -eq 0 ]; then echo "✅ 检查通过,构建成功。" exit 0 else - echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" - # 为了让 GitHub Actions 标记为失败,退出码设为 1 + echo "❌ 发现 $total_violations 个违规,构建失败。" exit 1 fi \ No newline at end of file diff --git a/.github/scripts/pmd-pr.sh b/.github/scripts/pmd-pr.sh new file mode 100644 index 00000000..15796f4f --- /dev/null +++ b/.github/scripts/pmd-pr.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# ============================================================ +# pmd-pr.sh - PMD 增量扫描脚本 +# 功能:只扫描本次提交中变更的 Java 文件 +# 生成报告到 target/pmd-report.xml(或自定义路径) +# ============================================================ + +set -e + +echo "========================================" +echo " PMD 增量扫描" +echo " 扫描范围:本次变更的 Java 文件" +echo "========================================" + +# 1. 确定目标分支 +if [ -n "$GITHUB_BASE_REF" ]; then + BASE_BRANCH="origin/$GITHUB_BASE_REF" +elif [ -n "$GITHUB_REF" ] && [ "$GITHUB_EVENT_NAME" == "push" ]; then + BASE_BRANCH="HEAD^" +else + if git rev-parse --verify origin/main >/dev/null 2>&1; then + BASE_BRANCH="origin/main" + elif git rev-parse --verify origin/develop >/dev/null 2>&1; then + BASE_BRANCH="origin/develop" + else + echo "❌ 无法确定目标分支,请设置 BASE_BRANCH 环境变量。" + exit 1 + fi + echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" +fi + +# 2. 获取变更的 Java 文件 +CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) + +if [ -z "$CHANGED_FILES" ]; then + echo "✅ 没有 Java 文件变更,跳过 PMD 扫描。" + exit 0 +fi + +echo "📝 变更的 Java 文件:" +echo "$CHANGED_FILES" +echo "----------------------------------------" + +# 3. 生成文件列表(绝对路径) +FILE_LIST="changed-files.txt" +> "$FILE_LIST" +for file in $CHANGED_FILES; do + echo "$PWD/$file" >> "$FILE_LIST" +done + +echo "📄 文件列表已生成:$FILE_LIST" +echo "----------------------------------------" + +# 4. 准备 PMD(如果未安装) +PMD_VERSION="6.55.0" +PMD_HOME="./pmd" +if [ ! -d "$PMD_HOME" ]; then + echo "⬇️ 下载 PMD $PMD_VERSION ..." + curl -L "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip" -o pmd.zip + unzip -q pmd.zip + mv pmd-bin-${PMD_VERSION} "$PMD_HOME" + rm pmd.zip +fi +PMD_CMD="$PMD_HOME/bin/run.sh" +chmod +x "$PMD_CMD" + +# 5. 执行 PMD 扫描(使用 -filelist) +echo "🚀 执行 PMD 扫描..." +REPORT_FILE="target/pmd-report.xml" +set +e +"$PMD_CMD" pmd --no-cache \ + -filelist "$FILE_LIST" \ + -f xml \ + -R category/java/quickstart.xml \ + -r "$REPORT_FILE" +EXIT_CODE=$? +set -e + +# 6. 检查是否生成报告 +if [ -f "$REPORT_FILE" ]; then + echo "✅ PMD 报告已生成:$REPORT_FILE" +else + echo "⚠️ PMD 未生成报告,可能无违规或出错。" +fi + +# 7. 清理临时文件 +rm -f "$FILE_LIST" + +# 8. 始终以成功状态退出(违规由 YAML 汇总步骤决定) +exit 0 \ No newline at end of file diff --git a/.github/scripts/spotbugs-incremental.sh b/.github/scripts/spotbugs-incremental.sh new file mode 100644 index 00000000..65f76802 --- /dev/null +++ b/.github/scripts/spotbugs-incremental.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# ============================================================ +# spotbugs-incremental.sh - 增量 SpotBugs 扫描 +# 功能:只分析本次变更的 Java 文件对应的类 +# ============================================================ + +set -e + +echo "========================================" +echo " SpotBugs 增量扫描" +echo "========================================" + +# 确定目标分支 +if [ -n "$GITHUB_BASE_REF" ]; then + BASE_BRANCH="origin/$GITHUB_BASE_REF" +elif [ -n "$GITHUB_REF" ] && [ "$GITHUB_EVENT_NAME" == "push" ]; then + BASE_BRANCH="HEAD^" +else + if git rev-parse --verify origin/main >/dev/null 2>&1; then + BASE_BRANCH="origin/main" + elif git rev-parse --verify origin/develop >/dev/null 2>&1; then + BASE_BRANCH="origin/develop" + else + echo "❌ 无法确定目标分支,请设置 BASE_BRANCH 环境变量。" + exit 1 + fi + echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" +fi + +# 获取变更的 Java 文件 +CHANGED_JAVA=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) + +if [ -z "$CHANGED_JAVA" ]; then + echo "✅ 没有 Java 文件变更,跳过 SpotBugs 扫描。" + exit 0 +fi + +echo "📝 变更的 Java 文件:" +echo "$CHANGED_JAVA" + +# 提取类名列表 +class_list="" +for file in $CHANGED_JAVA; do + # 文件可能已被删除,跳过 + if [ ! -f "$file" ]; then + continue + fi + # 提取包名(假设文件中有 package 声明) + pkg=$(grep '^package' "$file" | sed -E 's/package\s+([^;]+);.*/\1/' | head -1) + if [ -z "$pkg" ]; then + echo "⚠️ 跳过 $file(未找到 package 声明)" + continue + fi + # 提取类名(不含 .java 后缀) + classname=$(basename "$file" .java) + fqdn="$pkg.$classname" + if [ -z "$class_list" ]; then + class_list="$fqdn" + else + class_list="$class_list,$fqdn" + fi +done + +if [ -z "$class_list" ]; then + echo "⚠️ 未能提取到任何有效的类名,跳过 SpotBugs。" + exit 0 +fi + +echo "📋 待分析的类:$class_list" +echo "----------------------------------------" + +# 执行 SpotBugs 增量分析 +echo "🚀 执行 SpotBugs 增量扫描..." +mvn spotbugs:check -Dspotbugs.onlyAnalyze="$class_list" \ No newline at end of file diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 0c5f02af..33f85518 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -56,6 +56,75 @@ jobs: echo "Also check reports directory:" ls -la base/target/reports/ || echo "base/target/reports not found" + - name: Compile project + run: mvn compile -DskipTests + + - name: Run PMD (incremental) + id: pmd + continue-on-error: true + run: bash .github/scripts/pmd-pr.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} + + - name: Prepare SpotBugs onlyAnalyze list + run: bash .github/scripts/spotbugs-only-analyze.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} + + - name: Debug reports + if: always() + run: | + echo "Current directory: $(pwd)" + echo "=== Find all report files ===" + find . -type f \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) + + - name: Summarize violations + id: summary + run: | + total=0 + for report in $(find . -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml"); do + if [ -f "$report" ]; then + count=0 + if [[ "$report" == *"spotbugsXml.xml" ]]; then + count=$(grep -c '> $GITHUB_OUTPUT + echo "总违规数: $total" + + - name: Fail if violations found + if: steps.summary.outputs.total_violations > 0 + run: | + echo "❌ 发现 ${{ steps.summary.outputs.total_violations }} 个违规,构建失败。" + exit 1 + + - name: Install sarif-tools and convert to HTML + run: | + pip install sarif-tools + sarif html pmd-report.sarif --output pmd-report.html + + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v4 + with: + sarif_file: pmd-report.sarif + + - name: Upload SARIF file as artifact + uses: actions/upload-artifact@v7 + with: + name: pmd-sarif-report # 给工件起一个有意义的名字 + path: pmd-report.sarif + + - name: Upload HTML report + uses: actions/upload-artifact@v7 + with: + name: pmd-html-report + path: pmd-report.html + # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 @@ -66,5 +135,8 @@ jobs: **/target/checkstyle-result.xml **/target/checkstyle-checker.xml **/target/reports/ + **/target/spotbugsXml.xml + **/target/spotbugs.html + **/target/pmd.xml if-no-files-found: warn diff --git a/pom.xml b/pom.xml index 0e3e03c3..1343065b 100644 --- a/pom.xml +++ b/pom.xml @@ -311,7 +311,7 @@ com.github.spotbugs spotbugs-maven-plugin - 4.7.3.0 + 4.7.3.1 spotbugs-check @@ -326,8 +326,12 @@ Low true true + true + ${project.build.directory}/spotbugs-reports + + From f8b20fb54252a8ea583efebc3dd179cf7f03c459 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 18:28:42 -0700 Subject: [PATCH 121/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 150 ++++++++++++------------------- 1 file changed, 56 insertions(+), 94 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 27feafed..0daab3c1 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -1,15 +1,15 @@ #!/bin/bash # ============================================================ -# checkstyle-pr.sh - Checkstyle 增量扫描(多模块,包含测试) -# 功能:只扫描本次提交中变更的 Java 文件(所有模块,src/main 和 src/test) -# 生成报告,根据违规数决定退出码 +# checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) +# 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 +# 不阻断构建,生成完整报告 # ============================================================ set -e echo "========================================" -echo " Checkstyle 增量扫描(多模块)" -echo " 扫描范围:所有模块的变更 Java 文件(包含测试)" +echo " Checkstyle 增量检查" +echo " 扫描范围:本次变更的 Java 文件(完整文件)" echo "========================================" # 1. 确定目标分支 @@ -29,7 +29,7 @@ else echo "🔍 本地运行模式,对比分支: $BASE_BRANCH" fi -# 2. 获取变更的 Java 文件(所有模块) +# 2. 获取变更的 Java 文件 CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" HEAD 2>/dev/null | grep '\.java$' || true) if [ -z "$CHANGED_FILES" ]; then @@ -41,117 +41,79 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 按模块分组,提取模块内相对路径 -declare -A module_files -for file in $CHANGED_FILES; do - # 提取第一级目录作为模块名(例如 base, app, core 等) - module="${file%%/*}" - # 如果模块名为空或文件在根目录,跳过 - if [ -z "$module" ] || [ "$module" == "$file" ]; then - echo "⚠️ 忽略根目录文件: $file" - continue - fi - # 去掉模块前缀,得到相对路径 - rel="${file#$module/}" - # 追加到对应模块的列表中(逗号分隔) - if [ -z "${module_files[$module]}" ]; then - module_files[$module]="$rel" - else - module_files[$module]="${module_files[$module]},$rel" - fi -done +# 3. 将文件列表转为逗号分隔 +FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') + +# 4. 执行 Checkstyle 扫描(生成完整报告) +echo "🚀 执行 Checkstyle 扫描(完整文件)..." +echo "FILES_LIST: $FILES_LIST" +set +e +mvn -pl base checkstyle:check \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.violationSeverity=warning +MVN_EXIT=$? +set -e -if [ ${#module_files[@]} -eq 0 ]; then - echo "⚠️ 没有识别到任何模块,跳过检查。" +# 额外生成 HTML 报告(不受违规影响,始终执行) +echo "📄 生成 HTML 报告..." +mvn -pl base checkstyle:checkstyle \ + -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ + -Dcheckstyle.outputFormat=html \ + -Dcheckstyle.violationSeverity=warning + +# 5. 确定报告路径(根据项目结构调整) +REPORT_FILE="base/target/checkstyle-result.xml" +if [ ! -f "$REPORT_FILE" ]; then + echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 fi -echo "📝 按模块分组后的相对路径:" -for module in "${!module_files[@]}"; do - echo " $module: ${module_files[$module]}" -done -echo "----------------------------------------" +# 6. 统计违规数 +VIOLATIONS=$(grep -c '//' | \ + sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ + while read -r line; do + echo " $line" + done fi -# 6. 输出到 Step Summary(可选) +# 7. 输出到 GitHub Step Summary if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 汇总报告" + echo "## 📋 Checkstyle 报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $total_violations -eq 0 ]; then - echo "| 总违规数 | ✅ **0** |" + if [ $VIOLATIONS -eq 0 ]; then + echo "| 违规数 | ✅ **0** |" else - echo "| 总违规数 | ⚠️ **$total_violations** |" + echo "| 违规数 | ⚠️ **$VIOLATIONS** |" fi - echo "| 涉及模块 | ${!module_files[*]} |" + echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" + echo "| 检查方式 | 对变更文件进行完整扫描 |" echo "" - echo "📥 完整报告已作为 Artifact 上传。" + echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" } >> "$GITHUB_STEP_SUMMARY" + echo "✅ Step Summary 已更新" fi -# 7. 根据违规数决定构建状态 -if [ $total_violations -eq 0 ]; then +# 8. 始终以成功状态退出 +# ================================================ +# 7. 根据违规数决定构建状态(拦截 PR) +# ================================================ +if [ $VIOLATIONS -eq 0 ]; then echo "✅ 检查通过,构建成功。" exit 0 else - echo "❌ 发现 $total_violations 个违规,构建失败。" + echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" + # 为了让 GitHub Actions 标记为失败,退出码设为 1 exit 1 fi \ No newline at end of file From cfb89c0f84f6edc0b3d7240292215c1e7afffb0d Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 18:33:57 -0700 Subject: [PATCH 122/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 33f85518..b96aa782 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -67,7 +67,7 @@ jobs: GITHUB_BASE_REF: ${{ github.base_ref }} - name: Prepare SpotBugs onlyAnalyze list - run: bash .github/scripts/spotbugs-only-analyze.sh + run: bash .github/scripts/spotbugs-incremental.sh env: GITHUB_BASE_REF: ${{ github.base_ref }} From fae1519541b6d23da42166a09248e58bbf811350 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 18:56:28 -0700 Subject: [PATCH 123/137] fix:code check test --- .github/workflows/checkstyle.yml | 72 -------------------------------- 1 file changed, 72 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index b96aa782..0c5f02af 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -56,75 +56,6 @@ jobs: echo "Also check reports directory:" ls -la base/target/reports/ || echo "base/target/reports not found" - - name: Compile project - run: mvn compile -DskipTests - - - name: Run PMD (incremental) - id: pmd - continue-on-error: true - run: bash .github/scripts/pmd-pr.sh - env: - GITHUB_BASE_REF: ${{ github.base_ref }} - - - name: Prepare SpotBugs onlyAnalyze list - run: bash .github/scripts/spotbugs-incremental.sh - env: - GITHUB_BASE_REF: ${{ github.base_ref }} - - - name: Debug reports - if: always() - run: | - echo "Current directory: $(pwd)" - echo "=== Find all report files ===" - find . -type f \( -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) - - - name: Summarize violations - id: summary - run: | - total=0 - for report in $(find . -name "checkstyle-result.xml" -o -name "pmd.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml"); do - if [ -f "$report" ]; then - count=0 - if [[ "$report" == *"spotbugsXml.xml" ]]; then - count=$(grep -c '> $GITHUB_OUTPUT - echo "总违规数: $total" - - - name: Fail if violations found - if: steps.summary.outputs.total_violations > 0 - run: | - echo "❌ 发现 ${{ steps.summary.outputs.total_violations }} 个违规,构建失败。" - exit 1 - - - name: Install sarif-tools and convert to HTML - run: | - pip install sarif-tools - sarif html pmd-report.sarif --output pmd-report.html - - - name: Upload SARIF file - uses: github/codeql-action/upload-sarif@v4 - with: - sarif_file: pmd-report.sarif - - - name: Upload SARIF file as artifact - uses: actions/upload-artifact@v7 - with: - name: pmd-sarif-report # 给工件起一个有意义的名字 - path: pmd-report.sarif - - - name: Upload HTML report - uses: actions/upload-artifact@v7 - with: - name: pmd-html-report - path: pmd-report.html - # 如果检查失败,仍然上传报告供查看 - name: Upload Checkstyle report if: always() # 即使失败也上传报告 @@ -135,8 +66,5 @@ jobs: **/target/checkstyle-result.xml **/target/checkstyle-checker.xml **/target/reports/ - **/target/spotbugsXml.xml - **/target/spotbugs.html - **/target/pmd.xml if-no-files-found: warn From f0229ebc7ac57e8a838997a24651af0d44ff8472 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 19:04:18 -0700 Subject: [PATCH 124/137] fix:code check test --- .github/workflows/checkstyle.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 0c5f02af..54d930b6 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -40,6 +40,23 @@ jobs: run: bash .github/scripts/checkstyle-pr.sh env: GITHUB_BASE_REF: ${{ github.base_ref }} + # ==================== 编译(PMD 和 SpotBugs 需要) ==================== + - name: Compile project + run: mvn compile -DskipTests + # ==================== PMD 增量扫描 ==================== + - name: Run PMD (incremental) + id: pmd + continue-on-error: true + run: bash .github/scripts/pmd-pr.sh + env: + GITHUB_BASE_REF: ${{ github.base_ref }} + # ==================== 调试:列出所有报告 ==================== + - name: Debug - list all reports + if: always() + run: | + echo "当前工作目录: $(pwd)" + echo "=== 查找所有检查报告 ===" + find . -type f \( -name "checkstyle-result.xml" -o -name "pmd-report.xml" -o -name "cpd.xml" -o -name "spotbugsXml.xml" \) - name: Debug - list all checkstyle reports run: | From 19f30745993d8f0283ef1646cec7f96a3b05a5f2 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 19:09:52 -0700 Subject: [PATCH 125/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 0daab3c1..980d9a32 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -79,10 +79,10 @@ else echo "" echo "📋 违规摘要(前 30 条):" grep '//' | \ - sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ + sed 's|line="|行号: |g; s|column="|列: |g; s|severity="|严重性: |g; s|message="|信息: |g; s|source="||g' | \ while read -r line; do echo " $line" - done + done || true # 忽略管道错误 fi # 7. 输出到 GitHub Step Summary From 4f6ae1b543eb439385f63c32649105de59cf0cfa Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 19:18:10 -0700 Subject: [PATCH 126/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 980d9a32..1714be28 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -62,7 +62,7 @@ mvn -pl base checkstyle:checkstyle \ -Dcheckstyle.violationSeverity=warning # 5. 确定报告路径(根据项目结构调整) -REPORT_FILE="base/target/checkstyle-result.xml" +REPORT_FILE="**/target/checkstyle-result.xml" if [ ! -f "$REPORT_FILE" ]; then echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 From ae30f1905f3132421636ee6d3dd5feae18b46d32 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 19:21:46 -0700 Subject: [PATCH 127/137] fix:code check test --- .github/workflows/checkstyle.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 54d930b6..d396e1f6 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -46,7 +46,6 @@ jobs: # ==================== PMD 增量扫描 ==================== - name: Run PMD (incremental) id: pmd - continue-on-error: true run: bash .github/scripts/pmd-pr.sh env: GITHUB_BASE_REF: ${{ github.base_ref }} From a3db57fdd1e908857f1a85168cf538cbd570bd71 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 19:24:38 -0700 Subject: [PATCH 128/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 1714be28..980d9a32 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -62,7 +62,7 @@ mvn -pl base checkstyle:checkstyle \ -Dcheckstyle.violationSeverity=warning # 5. 确定报告路径(根据项目结构调整) -REPORT_FILE="**/target/checkstyle-result.xml" +REPORT_FILE="base/target/checkstyle-result.xml" if [ ! -f "$REPORT_FILE" ]; then echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" exit 0 From a569a50f201a6c27c873cdf4914d7461036d17e1 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Thu, 6 Aug 2026 23:22:45 -0700 Subject: [PATCH 129/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 141 ++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 48 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 980d9a32..0ddfde6f 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -41,79 +41,124 @@ echo "📝 变更的 Java 文件:" echo "$CHANGED_FILES" echo "----------------------------------------" -# 3. 将文件列表转为逗号分隔 -FILES_LIST=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//') - -# 4. 执行 Checkstyle 扫描(生成完整报告) -echo "🚀 执行 Checkstyle 扫描(完整文件)..." -echo "FILES_LIST: $FILES_LIST" -set +e -mvn -pl base checkstyle:check \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.violationSeverity=warning -MVN_EXIT=$? -set -e +# 按模块分组 +declare -A module_files +for file in $CHANGED_FILES; do + module="${file%%/*}" + if [ -z "$module" ] || [ "$module" == "$file" ]; then + echo "⚠️ 忽略根目录文件: $file" + continue + fi + rel="${file#$module/}" + if [ -z "${module_files[$module]}" ]; then + module_files[$module]="$rel" + else + module_files[$module]="${module_files[$module]},$rel" + fi +done -# 额外生成 HTML 报告(不受违规影响,始终执行) -echo "📄 生成 HTML 报告..." -mvn -pl base checkstyle:checkstyle \ - -Dcheckstyle.config.location=checkstyle/huawei-checkstyle.xml \ - -Dcheckstyle.outputFormat=html \ - -Dcheckstyle.violationSeverity=warning - -# 5. 确定报告路径(根据项目结构调整) -REPORT_FILE="base/target/checkstyle-result.xml" -if [ ! -f "$REPORT_FILE" ]; then - echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" +if [ ${#module_files[@]} -eq 0 ]; then + echo "⚠️ 没有识别到任何模块,跳过检查。" exit 0 fi -# 6. 统计违规数 -VIOLATIONS=$(grep -c '//' | \ - sed 's|line="|行号: |g; s|column="|列: |g; s|severity="|严重性: |g; s|message="|信息: |g; s|source="||g' | \ - while read -r line; do - echo " $line" - done || true # 忽略管道错误 + for module in "${!module_files[@]}"; do + report_file="$module/target/checkstyle-result.xml" + if [ -f "$report_file" ] && [ $(grep -c '//' | \ + sed 's|line="|行号: |g; s|column="|列: |g; s|severity="|严重性: |g; s|message="|信息: |g; s|source="||g' | \ + while read -r line; do + echo " $line" + done || true + break + fi + done fi -# 7. 输出到 GitHub Step Summary +# Step Summary if [ -n "$GITHUB_STEP_SUMMARY" ]; then { - echo "## 📋 Checkstyle 报告" + echo "## 📋 Checkstyle 汇总报告" echo "" echo "| 指标 | 结果 |" echo "|------|------|" - if [ $VIOLATIONS -eq 0 ]; then - echo "| 违规数 | ✅ **0** |" + if [ $total_violations -eq 0 ]; then + echo "| 总违规数 | ✅ **0** |" else - echo "| 违规数 | ⚠️ **$VIOLATIONS** |" + echo "| 总违规数 | ⚠️ **$total_violations** |" fi - echo "| 扫描文件 | **$(echo "$CHANGED_FILES" | wc -l)** 个变更 Java 文件 |" - echo "| 检查方式 | 对变更文件进行完整扫描 |" + echo "| 涉及模块 | ${!module_files[*]} |" echo "" - echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" + echo "📥 完整报告已作为 Artifact 上传。" } >> "$GITHUB_STEP_SUMMARY" - echo "✅ Step Summary 已更新" fi -# 8. 始终以成功状态退出 -# ================================================ -# 7. 根据违规数决定构建状态(拦截 PR) -# ================================================ -if [ $VIOLATIONS -eq 0 ]; then +# 根据违规数决定退出码 +if [ $total_violations -eq 0 ]; then echo "✅ 检查通过,构建成功。" exit 0 else - echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" - # 为了让 GitHub Actions 标记为失败,退出码设为 1 + echo "❌ 发现 $total_violations 个违规,构建失败。" exit 1 fi \ No newline at end of file From d7a3834365fdd058bc04c7b186861c9c4588d92c Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 00:49:21 -0700 Subject: [PATCH 130/137] fix:code check test --- .github/workflows/checkstyle.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index d396e1f6..d76b16a4 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -34,15 +34,16 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- + # 新增:安装所有模块到本地仓库,解决依赖解析 + - name: Install project (for dependency resolution) + run: mvn install -DskipTests -Dmaven.test.skip=true # 直接运行 Checkstyle 检查(不执行完整的 package) - name: Run Checkstyle run: bash .github/scripts/checkstyle-pr.sh env: GITHUB_BASE_REF: ${{ github.base_ref }} - # ==================== 编译(PMD 和 SpotBugs 需要) ==================== - - name: Compile project - run: mvn compile -DskipTests + # ==================== PMD 增量扫描 ==================== - name: Run PMD (incremental) id: pmd From 71e0e738ea1e7459ed1a0f3f42e51c93f33d5534 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 01:10:11 -0700 Subject: [PATCH 131/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index d76b16a4..94149805 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -36,7 +36,7 @@ jobs: ${{ runner.os }}-maven- # 新增:安装所有模块到本地仓库,解决依赖解析 - name: Install project (for dependency resolution) - run: mvn install -DskipTests -Dmaven.test.skip=true + run: mvn install -DskipTests -Dmaven.test.skip=true -Dcheckstyle.skip=true # 直接运行 Checkstyle 检查(不执行完整的 package) - name: Run Checkstyle From 344f69daaedf3b4503a961862e9878b34b7e52c1 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 01:15:22 -0700 Subject: [PATCH 132/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 94149805..50e35414 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -36,7 +36,7 @@ jobs: ${{ runner.os }}-maven- # 新增:安装所有模块到本地仓库,解决依赖解析 - name: Install project (for dependency resolution) - run: mvn install -DskipTests -Dmaven.test.skip=true -Dcheckstyle.skip=true + run: mvn install -DskipTests -Dmaven.test.skip=true -Dcheckstyle.skip=true -Dpmd.skip=true -Dspotbugs.skip=true # 直接运行 Checkstyle 检查(不执行完整的 package) - name: Run Checkstyle From b49067ec9b79b0cb8a8f235a2b0f0be6e8630257 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 01:20:12 -0700 Subject: [PATCH 133/137] fix:code check test --- .github/workflows/checkstyle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 50e35414..8c0a161d 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -36,7 +36,7 @@ jobs: ${{ runner.os }}-maven- # 新增:安装所有模块到本地仓库,解决依赖解析 - name: Install project (for dependency resolution) - run: mvn install -DskipTests -Dmaven.test.skip=true -Dcheckstyle.skip=true -Dpmd.skip=true -Dspotbugs.skip=true + run: mvn install -DskipTests -Dmaven.test.skip=true -Dcheckstyle.skip=true -Dpmd.skip=true -Dspotbugs.skip=true -Dcpd.skip=true # 直接运行 Checkstyle 检查(不执行完整的 package) - name: Run Checkstyle From 1f3cbceab8fa250b0afcd4031cf1990621cc9de7 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 01:37:02 -0700 Subject: [PATCH 134/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 0ddfde6f..6899a825 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -83,7 +83,7 @@ for module in "${!module_files[@]}"; do echo " - 生成 XML 报告..." set +e - (cd "$module" && mvn checkstyle:check \ + (cd "$module" && mvn checkstyle:check -X ... 2>&1 | grep "Loading checkstyle configuration" \ -Dcheckstyle.config.location=../checkstyle/huawei-checkstyle.xml \ -Dcheckstyle.includes="$file_list" \ -Dcheckstyle.violationSeverity=warning) From d4511744cc2729de7b3c320a26d40821d9dea531 Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 01:57:10 -0700 Subject: [PATCH 135/137] fix:code check test --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1343065b..a13d7c73 100644 --- a/pom.xml +++ b/pom.xml @@ -242,7 +242,8 @@ 3.6.0 - ./checkstyle/huawei-checkstyle.xml + + ${session.executionRootDirectory}/checkstyle/huawei-checkstyle.xml true warning From b2ca0526f9578edd81b1c430928da26a39c207ad Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 02:08:40 -0700 Subject: [PATCH 136/137] fix:code check test --- .github/scripts/checkstyle-pr.sh | 6 ++---- pom.xml | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/scripts/checkstyle-pr.sh b/.github/scripts/checkstyle-pr.sh index 6899a825..cce8116a 100644 --- a/.github/scripts/checkstyle-pr.sh +++ b/.github/scripts/checkstyle-pr.sh @@ -106,11 +106,9 @@ for module in "${!module_files[@]}"; do report_file="$module/target/checkstyle-result.xml" if [ -f "$report_file" ]; then - count=$(grep -c '/dev/null || true) else - echo " ⚠️ 模块 $module 未生成报告" + count=0 fi echo "" done diff --git a/pom.xml b/pom.xml index a13d7c73..732d35d8 100644 --- a/pom.xml +++ b/pom.xml @@ -241,9 +241,6 @@ maven-checkstyle-plugin 3.6.0 - - - ${session.executionRootDirectory}/checkstyle/huawei-checkstyle.xml true warning From 954899aaf6bd28627d5b62162c3b5f94adcd40ed Mon Sep 17 00:00:00 2001 From: msslulu <1484036491@qq.com> Date: Fri, 7 Aug 2026 02:13:45 -0700 Subject: [PATCH 137/137] fix:code check test --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index 732d35d8..a13d7c73 100644 --- a/pom.xml +++ b/pom.xml @@ -241,6 +241,9 @@ maven-checkstyle-plugin 3.6.0 + + + ${session.executionRootDirectory}/checkstyle/huawei-checkstyle.xml true warning