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 01/41] 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 02/41] 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 03/41] 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 04/41] 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 05/41] 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 07/41] 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 08/41] 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 10/41] 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 11/41] 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 12/41] 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 13/41] 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 15/41] 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 16/41] 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 17/41] 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 18/41] 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 19/41] 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 20/41] 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 21/41] 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 22/41] 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 23/41] 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 24/41] 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 25/41] 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 26/41] 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 27/41] 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 28/41] 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 29/41] 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 30/41] 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 31/41] 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 32/41] 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 33/41] 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 34/41] 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 35/41] 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 36/41] 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 37/41] 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 38/41] 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 39/41] 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 40/41] 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 41/41] 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 */