Skip to content

Commit 03f2f74

Browse files
Enhance Java 17 CI workflow with improved logging and coverage reporting
- Added better logging for coverage percentages - Improved error handling for missing coverage report - Standardized PR comment format with Java 11 and 21 CI - Ensured proper workflow consistency Signed-off-by: Brijeshthummar02 <[email protected]>
1 parent 605b1cb commit 03f2f74

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

.github/workflows/java-17.yml

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
# Copyright 2023-2023 the original author or authors.
1+
# Copyright 2023-2023 the original author or authors.
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
7+
# http://www.apache.org/licenses/LICENSE-2.0
148
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
1514
#
1615
#
1716

@@ -20,25 +19,68 @@ name: Java 17 CI with Maven
2019
on:
2120
push:
2221
branches: [ main ]
23-
# Each pull request is important to us, doesn't matter from which branch.
24-
# Furthermore, we do not want to build on just the default GitHub Action
25-
# events, we also want to react onto `labeled` events for our extended
26-
# build execution
2722
pull_request:
2823
types: [ labeled, opened, synchronize, reopened ]
2924

3025
jobs:
3126
build:
32-
3327
runs-on: ubuntu-latest
3428

3529
steps:
3630
- uses: actions/checkout@v3
31+
3732
- name: Set up JDK 17
3833
uses: actions/setup-java@v3
3934
with:
4035
distribution: 'temurin'
4136
java-version: 17
4237
cache: maven
38+
4339
- name: Build with Maven
44-
run: mvn -B verify -P java-17,run-its
40+
run: mvn -B verify -P java-17,run-its
41+
42+
- name: Generate JaCoCo badge
43+
id: jacoco
44+
uses: cicirello/[email protected]
45+
with:
46+
badges-directory: .github/badges
47+
generate-branches-badge: true
48+
generate-summary: true
49+
summary-filename: coverage-summary_java-17.json
50+
coverage-badge-filename: jacoco_java-17.svg
51+
branches-badge-filename: branches_java-17.svg
52+
coverage-endpoint-filename: jacoco_java-17.json
53+
branches-endpoint-filename: branches_java-17.json
54+
55+
- name: Log coverage percentages to workflow output
56+
run: |
57+
echo "(java-17) coverage = ${{ steps.jacoco.outputs.coverage }}%"
58+
echo "(java-17) branches = ${{ steps.jacoco.outputs.branches }}%"
59+
60+
- name: Upload JaCoCo coverage report
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: jacoco-report-java-17
64+
path: target/site/jacoco/
65+
66+
- name: Deploy to Coverage Branch
67+
if: ${{ github.event_name != 'pull_request' }}
68+
uses: crazy-max/ghaction-github-pages@v4
69+
with:
70+
target_branch: coverage
71+
build_dir: .github/badges
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Comment on PR with coverage percentages
76+
if: ${{ github.event_name == 'pull_request' }}
77+
run: |
78+
REPORT=$(<.github/badges/coverage-summary_java-17.json)
79+
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
80+
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
81+
NEWLINE=$'\n'
82+
BODY="## JaCoCo Test Coverage Summary Statistics (java-17) ${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
83+
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
84+
continue-on-error: true
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)