|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Error Prone Analysis |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: [ main ] |
| 23 | + pull_request: |
| 24 | + branches: [ main ] |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + errorprone: |
| 35 | + runs-on: ubuntu-22.04 |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Set up JDK 11 |
| 40 | + uses: actions/setup-java@v4 |
| 41 | + with: |
| 42 | + java-version: '11' |
| 43 | + distribution: 'adopt' |
| 44 | + architecture: x64 |
| 45 | + cache: maven |
| 46 | + |
| 47 | + - name: Run Error Prone Static Analysis (Strict Mode) |
| 48 | + run: | |
| 49 | + echo "::group::Error Prone Analysis" |
| 50 | + # Temporarily remove -XepAllErrorsAsWarnings to run in strict mode |
| 51 | + sed -i 's/-Xplugin:ErrorProne -XepAllErrorsAsWarnings/-Xplugin:ErrorProne/g' pom.xml |
| 52 | + mvn clean compile -DskipTests -T$(nproc) 2>&1 | tee errorprone.log |
| 53 | + BUILD_RESULT=$? |
| 54 | + echo "::endgroup::" |
| 55 | + exit $BUILD_RESULT |
| 56 | + continue-on-error: true |
| 57 | + |
| 58 | + - name: Check for Error Prone Issues |
| 59 | + id: check-errors |
| 60 | + run: | |
| 61 | + if grep -q "error: \[" errorprone.log; then |
| 62 | + echo "has_errors=true" >> $GITHUB_OUTPUT |
| 63 | + echo "::error::Error Prone found issues in the code" |
| 64 | + echo "" |
| 65 | + echo "=== Error Prone Issues Found ===" |
| 66 | + grep -B 2 "error: \[" errorprone.log | head -50 |
| 67 | + echo "" |
| 68 | + |
| 69 | + # Create job summary |
| 70 | + echo "## ⚠️ Error Prone Analysis Failed" >> $GITHUB_STEP_SUMMARY |
| 71 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 72 | + echo "Error Prone static analysis detected issues in this PR." >> $GITHUB_STEP_SUMMARY |
| 73 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 74 | + echo "### Issues Found (first 50):" >> $GITHUB_STEP_SUMMARY |
| 75 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 76 | + grep -B 2 "error: \[" errorprone.log | head -50 >> $GITHUB_STEP_SUMMARY |
| 77 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 78 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 79 | + echo "See the [Error Prone documentation](https://errorprone.info/) for details on each bug pattern." >> $GITHUB_STEP_SUMMARY |
| 80 | + else |
| 81 | + echo "has_errors=false" >> $GITHUB_OUTPUT |
| 82 | + echo "✅ No Error Prone issues found" |
| 83 | + |
| 84 | + # Create success summary |
| 85 | + echo "## ✅ Error Prone Analysis Passed" >> $GITHUB_STEP_SUMMARY |
| 86 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 87 | + echo "No issues detected by Error Prone static analysis." >> $GITHUB_STEP_SUMMARY |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Fail if errors found |
| 91 | + if: steps.check-errors.outputs.has_errors == 'true' |
| 92 | + run: exit 1 |
| 93 | + |
0 commit comments