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