|
11 | 11 | - "release-notes/*" |
12 | 12 | permissions: |
13 | 13 | contents: read |
| 14 | + pull-requests: write |
14 | 15 |
|
15 | 16 | jobs: |
16 | 17 | build: |
@@ -60,16 +61,69 @@ jobs: |
60 | 61 | CI_DEPLOY_PASSWORD: ${{ secrets.CENTRAL_DEPLOY_PASSWORD }} |
61 | 62 | # MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
62 | 63 | run: ./mvnw -B -q -ff -DskipTests -ntp source:jar deploy |
63 | | - - name: Generate code coverage |
64 | | - if: ${{ matrix.release_build && github.event_name != 'pull_request' }} |
65 | | - run: ./mvnw -B -q -ff -ntp test |
| 64 | + - name: Generate code coverage |
| 65 | + if: ${{ matrix.release_build }} |
| 66 | + run: ./mvnw -B -q -ff -ntp test jacoco:report |
66 | 67 | - name: Publish code coverage |
67 | 68 | if: ${{ matrix.release_build && github.event_name != 'pull_request' }} |
68 | 69 | uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 |
69 | 70 | with: |
70 | 71 | token: ${{ secrets.CODECOV_TOKEN }} |
71 | 72 | files: ./target/site/jacoco/jacoco.xml |
72 | 73 | flags: unittests |
| 74 | + - name: Generate coverage summary |
| 75 | + if: ${{ matrix.release_build && github.event_name == 'pull_request' }} |
| 76 | + id: jacoco |
| 77 | + |
| 78 | + with: |
| 79 | + jacoco-csv-file: target/site/jacoco/jacoco.csv |
| 80 | + generate-coverage-badge: false |
| 81 | + generate-branches-badge: false |
| 82 | + generate-summary: true |
| 83 | + - name: Add coverage comment to PR |
| 84 | + if: ${{ matrix.release_build && github.event_name == 'pull_request' }} |
| 85 | + run: | |
| 86 | + # Convert decimal to percentage and round to 1 decimal place |
| 87 | + COVERAGE=$(awk -v cov="${{ steps.jacoco.outputs.coverage }}" 'BEGIN { printf "%.1f", cov * 100 }') |
| 88 | + BRANCHES=$(awk -v br="${{ steps.jacoco.outputs.branches }}" 'BEGIN { printf "%.1f", br * 100 }') |
| 89 | +
|
| 90 | + # Determine color for coverage badge using awk (more portable than bc) |
| 91 | + COV_COLOR=$(awk -v cov="$COVERAGE" 'BEGIN { |
| 92 | + if (cov >= 80) print "brightgreen" |
| 93 | + else if (cov >= 60) print "green" |
| 94 | + else if (cov >= 40) print "yellow" |
| 95 | + else print "red" |
| 96 | + }') |
| 97 | +
|
| 98 | + BR_COLOR=$(awk -v br="$BRANCHES" 'BEGIN { |
| 99 | + if (br >= 80) print "brightgreen" |
| 100 | + else if (br >= 60) print "green" |
| 101 | + else if (br >= 40) print "yellow" |
| 102 | + else print "red" |
| 103 | + }') |
| 104 | +
|
| 105 | + COMMENT_BODY="## :test_tube: Code Coverage Report |
| 106 | +
|
| 107 | + | Metric | Coverage | |
| 108 | + |--------|----------| |
| 109 | + | **Instructions** |  **${COVERAGE}%** | |
| 110 | + | **Branches** |  **${BRANCHES}%** | |
| 111 | +
|
| 112 | + > Coverage data generated from JaCoCo test results |
| 113 | +
|
| 114 | + <!-- jacoco-coverage-comment -->" |
| 115 | +
|
| 116 | + # Find and delete existing coverage comment |
| 117 | + COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.body | contains("<!-- jacoco-coverage-comment -->")) | .id' | head -1) |
| 118 | +
|
| 119 | + if [ -n "$COMMENT_ID" ]; then |
| 120 | + gh api -X DELETE "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" |
| 121 | + fi |
| 122 | +
|
| 123 | + # Post new comment |
| 124 | + gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT_BODY" |
| 125 | + env: |
| 126 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
73 | 127 |
|
74 | 128 | trigger-dep-build-v2: |
75 | 129 | name: Trigger v2 dep builds |
|
0 commit comments