-
Notifications
You must be signed in to change notification settings - Fork 88
fix:Checkstyle check #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msslulu
wants to merge
104
commits into
opentiny:develop
Choose a base branch
from
msslulu:feat/codeCheckStyle
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix:Checkstyle check #324
Changes from all commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
e5cde1b
fix:Checkstyle check
msslulu 95b5fb3
fix:Checkstyle check
msslulu e48f78a
fix:Checkstyle check
msslulu f7978be
fix:Checkstyle check
msslulu 4269943
fix:Checkstyle check
msslulu d3fd7b7
fix:Checkstyle check
msslulu b58e79f
fix:Checkstyle check
msslulu 45714f7
fix:Checkstyle check
msslulu 051cdc9
fix:Checkstyle check
msslulu 7d23198
fix:Checkstyle check
msslulu 35a3220
fix:Checkstyle check
msslulu 35bfea8
fix:Checkstyle check
msslulu 3843ac1
fix:Checkstyle check
msslulu 3a1b0c9
fix:Checkstyle check
msslulu c52edf3
fix:Checkstyle check
msslulu 929462f
fix:Checkstyle check
msslulu 989abaf
fix:Checkstyle check
msslulu c97a525
fix:Checkstyle check
msslulu 082e950
fix:Checkstyle check
msslulu 8ed95e0
fix:Checkstyle check
msslulu 5e47b0f
fix:Checkstyle check
msslulu ec22270
fix:Checkstyle check
msslulu f9fd623
fix:Checkstyle check test
msslulu 9025582
fix:Checkstyle check test
msslulu 8a82ac0
fix:Checkstyle check test
msslulu 2bee0b1
fix:Checkstyle check test
msslulu 4bf7806
fix:Checkstyle check test
msslulu 4102cc6
fix:Checkstyle check test
msslulu 9c654e9
fix:Checkstyle check test
msslulu 9c1e5c8
fix:Checkstyle check test
msslulu b1e0c25
fix:Checkstyle check test
msslulu 81d4c6b
fix:Checkstyle check test
msslulu 3e5b3ad
fix:Checkstyle check test
msslulu e5e0688
fix:Checkstyle check test
msslulu 44ab636
fix:Checkstyle check test
msslulu 08a2166
fix:Checkstyle check test
msslulu fc0c465
fix:Checkstyle check test
msslulu f931007
fix:Checkstyle check test
msslulu 625f4e9
fix:Checkstyle check test
msslulu 0ed0206
fix:Checkstyle check test
msslulu 2730cfc
fix:Checkstyle check test
msslulu a06b694
fix:Checkstyle check test
msslulu c0b8620
fix:Checkstyle check test
msslulu 63a64b9
fix:Checkstyle check test
msslulu 9b13999
fix:Checkstyle check test
msslulu 8413433
fix:Checkstyle check test
msslulu 9fb67ea
fix:Checkstyle check test
msslulu 22022b4
fix:Checkstyle check test
msslulu 3ceae07
fix:Checkstyle check test
msslulu 024bd39
fix:Checkstyle check test
msslulu 2f7db20
fix:Checkstyle check test
msslulu 05cb819
fix:Checkstyle check test
msslulu 70b30c9
fix:Checkstyle check test
msslulu 5d3ad7f
fix:Checkstyle check test
msslulu ccbc2c9
fix:Checkstyle check test
msslulu f3eecf9
fix:pmd test
msslulu 4384f22
fix:pmd test
msslulu eac5e85
fix:pmd test
msslulu f6012b6
fix:pmd test
msslulu b632204
fix:pmd test
msslulu 1a260c1
fix:pmd test
msslulu 4e52367
fix:pmd test
msslulu 81a56c3
fix:pmd test
msslulu 2cdffc4
fix:pmd test
msslulu aae082d
fix:pmd test
msslulu 1f12a91
fix:pmd test
msslulu fc02bcb
fix:pmd test
msslulu 3b63a2b
fix:pmd test
msslulu 1654700
fix:pmd test
msslulu b38b50a
fix:pmd test
msslulu 96e63c7
fix:pmd test
msslulu 8e5fb54
fix:pmd test
msslulu c8355ae
fix:pmd test
msslulu 424842f
fix:pmd test
msslulu 1ff2d9f
fix:pmd test
msslulu c6d5bb4
fix:pmd test
msslulu 1a7a165
fix:pmd test
msslulu 2ede5e4
fix:pmd test
msslulu 6937a69
fix:pmd test
msslulu 3afd810
fix:pmd test
msslulu 5580474
fix:pmd test
msslulu dec82dd
fix:pmd test
msslulu 631f8a1
fix:pmd test
msslulu 82a65e3
fix:pmd test
msslulu f55422b
fix:pmd test
msslulu a18fcdc
fix:pmd test
msslulu 9fc20ad
fix:pmd test
msslulu 6f87f7a
fix:pmd test
msslulu 472d06b
fix:pmd test
msslulu 0203930
fix:pmd test
msslulu c5e762c
fix:pmd test
msslulu 8506a6c
fix:pmd test
msslulu d766de0
fix:pmd test
msslulu 09fa71f
fix:pmd test
msslulu dceff4f
fix:pmd test
msslulu 7979afe
fix:pmd test
msslulu 3c9faf2
fix:code check test
msslulu 11b9e95
fix:code check test
msslulu 474acef
fix:code check test
msslulu ff97070
fix:code check test
msslulu cc7d855
fix:code check test
msslulu 5811ddc
fix:code check test
msslulu 8b81772
fix:code check test
msslulu 790c02c
fix:code check test
msslulu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/bin/bash | ||
| # ============================================================ | ||
| # checkstyle-pr.sh - 增量检查(扫描整个变更文件,不过滤行号) | ||
| # 功能:对本次提交中变更的 Java 文件执行完整的 Checkstyle 检查 | ||
| # 不阻断构建,生成完整报告 | ||
| # ============================================================ | ||
|
|
||
| set -e | ||
|
|
||
| echo "========================================" | ||
| echo " Checkstyle 增量检查" | ||
| 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 文件变更,跳过检查。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| 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.includes="**/testCheckstyle.java" \ | ||
| -Dcheckstyle.violationSeverity=warning | ||
| 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 | ||
| echo "❌ 未生成 Checkstyle 报告,请检查 Maven 配置。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # 6. 统计违规数 | ||
| VIOLATIONS=$(grep -c '<error' "$REPORT_FILE" || true) | ||
|
|
||
| echo "----------------------------------------" | ||
| if [ $VIOLATIONS -eq 0 ]; then | ||
| echo "✅ 所有变更文件未发现违规!" | ||
| else | ||
| echo "⚠️ 发现 $VIOLATIONS 个违规项(完整文件扫描)" | ||
| echo "" | ||
| echo "📋 违规摘要(前 30 条):" | ||
| grep '<error' "$REPORT_FILE" | head -30 | sed 's/<error //; s/\/>//' | \ | ||
| sed 's/line="/行号: /; s/column="/列: /; s/severity="/严重性: /; s=message="=信息: =; s=source="//' | \ | ||
| while read -r line; do | ||
| echo " $line" | ||
| done | ||
| fi | ||
|
|
||
| # 7. 输出到 GitHub Step Summary | ||
| 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 "| 检查方式 | 对变更文件进行完整扫描 |" | ||
| echo "" | ||
| echo "📥 完整报告已作为 Artifact 上传,请在工作流运行页面下载。" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
| echo "✅ Step Summary 已更新" | ||
| fi | ||
|
|
||
| # 8. 始终以成功状态退出 | ||
| # ================================================ | ||
| # 7. 根据违规数决定构建状态(拦截 PR) | ||
| # ================================================ | ||
| if [ $VIOLATIONS -eq 0 ]; then | ||
| echo "✅ 检查通过,构建成功。" | ||
| exit 0 | ||
| else | ||
| echo "❌ 发现 $VIOLATIONS 个违规,构建失败。" | ||
| # 为了让 GitHub Actions 标记为失败,退出码设为 1 | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,69 @@ | ||
| name: Checkstyle Code Quality | ||
| name: Checkstyle Code Quality1 | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - develop # 或者你想要检查的分支 | ||
| - develop | ||
| pull_request: | ||
| branches: | ||
| - develop # 你可以在 PR 时检查代码 | ||
| - develop | ||
|
|
||
| jobs: | ||
| check: | ||
| checkstyle: | ||
| runs-on: ubuntu-24.04 | ||
| env: | ||
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | ||
|
|
||
| steps: | ||
| # 检出代码 | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # 必须拉取完整历史,才能比较分支差异 | ||
|
|
||
| # 设置 JDK(如果是 Java 项目) | ||
| - name: Set up JDK 17.* | ||
| uses: actions/setup-java@v4 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| java-version: '17.*' | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| # 安装依赖并运行 Checkstyle(如果是 Maven 项目) | ||
| - name: Install dependencies and run Checkstyle | ||
| # 缓存 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: | | ||
| mvn clean package | ||
| 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" | ||
|
|
||
| # 查看 Checkstyle 检查报告 | ||
| # 如果检查失败,仍然上传报告供查看 | ||
| - name: Upload Checkstyle report | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() # 即使失败也上传报告 | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: checkstyle-report | ||
| path: target/checkstyle-result.xml # 这个路径应该是 Maven 生成的检查报告路径 | ||
| path: | | ||
| **/target/checkstyle-result.xml | ||
| **/target/checkstyle-checker.xml | ||
| **/target/reports/ | ||
| if-no-files-found: warn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 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 | ||
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
|
||
|
Comment on lines
+13
to
+74
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.