Skip to content

Commit 74b997d

Browse files
Update unit testing workflow: change JDK version to 9, enhance coverage checks with output variables, and add PR comment for coverage summary.
1 parent fb503b7 commit 74b997d

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

.github/workflows/unit-testing.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,68 @@ on:
1010
jobs:
1111
test-and-coverage:
1212
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
pull-requests: write
1316

1417
steps:
1518
- name: Checkout Repository
1619
uses: actions/checkout@v4
1720

18-
- name: Set up JDK 17
21+
- name: Set up JDK 9
1922
uses: actions/setup-java@v4
2023
with:
2124
distribution: 'temurin'
22-
java-version: '17'
25+
java-version: '9'
2326
cache: maven
2427

2528
- name: Run Tests and Generate JaCoCo Report
2629
working-directory: contentstack-java
2730
run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true
2831

29-
- name: Verify Coverage Thresholds
32+
- name: Extract and Check Coverage Thresholds
33+
id: coverage
3034
working-directory: contentstack-java
3135
run: |
3236
echo "Checking JaCoCo coverage thresholds..."
33-
INSTRUCTION_COVERAGE=$(grep -oPm1 "(?<=<counter type=\"INSTRUCTION\" missed=\")\d+\" covered=\"\d+\"" target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
34-
BRANCH_COVERAGE=$(grep -oPm1 "(?<=<counter type=\"BRANCH\" missed=\")\d+\" covered=\"\d+\"" target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
35-
echo "Instruction Coverage: $INSTRUCTION_COVERAGE%"
36-
echo "Branch Coverage: $BRANCH_COVERAGE%"
37+
38+
# Extract coverage values from XML
39+
INSTRUCTION=$(grep -oPm1 '(?<=<counter type="INSTRUCTION" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
40+
BRANCH=$(grep -oPm1 '(?<=<counter type="BRANCH" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
41+
42+
echo "Instruction Coverage: $INSTRUCTION%"
43+
echo "Branch Coverage: $BRANCH%"
44+
45+
echo "instruction=$INSTRUCTION" >> $GITHUB_OUTPUT
46+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
3747
3848
MIN_INSTRUCTION=90
3949
MIN_BRANCH=80
4050
41-
if (( ${INSTRUCTION_COVERAGE%.*} < MIN_INSTRUCTION )); then
51+
if (( ${INSTRUCTION%.*} < MIN_INSTRUCTION )); then
4252
echo "❌ Instruction coverage below $MIN_INSTRUCTION%"
4353
exit 1
4454
fi
4555
46-
if (( ${BRANCH_COVERAGE%.*} < MIN_BRANCH )); then
56+
if (( ${BRANCH%.*} < MIN_BRANCH )); then
4757
echo "❌ Branch coverage below $MIN_BRANCH%"
4858
exit 1
4959
fi
5060
5161
echo "✅ Coverage thresholds met."
5262
53-
- name: Upload JaCoCo HTML Report (Artifact)
63+
- name: Comment Coverage Summary on PR
64+
uses: marocchino/sticky-pull-request-comment@v2
65+
with:
66+
header: "🧪 JaCoCo Coverage Report"
67+
message: |
68+
**Coverage Summary**
69+
- 📘 Instruction Coverage: `${{ steps.coverage.outputs.instruction }}%`
70+
- 🌿 Branch Coverage: `${{ steps.coverage.outputs.branch }}%`
71+
72+
✅ Minimum thresholds: 90% instruction, 80% branch
73+
74+
- name: Upload JaCoCo HTML Report
5475
uses: actions/upload-artifact@v4
5576
with:
5677
name: jacoco-report

0 commit comments

Comments
 (0)