-
Notifications
You must be signed in to change notification settings - Fork 3
57 lines (46 loc) · 1.82 KB
/
unit-testing.yml
File metadata and controls
57 lines (46 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Java SDK - Coverage Check
on:
pull_request:
branches:
- development
- staging
- master
jobs:
test-and-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: maven
- name: Run Tests and Generate JaCoCo Report
working-directory: contentstack-java
run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true
- name: Verify Coverage Thresholds
working-directory: contentstack-java
run: |
echo "Checking JaCoCo coverage thresholds..."
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}')
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}')
echo "Instruction Coverage: $INSTRUCTION_COVERAGE%"
echo "Branch Coverage: $BRANCH_COVERAGE%"
MIN_INSTRUCTION=90
MIN_BRANCH=80
if (( ${INSTRUCTION_COVERAGE%.*} < MIN_INSTRUCTION )); then
echo "❌ Instruction coverage below $MIN_INSTRUCTION%"
exit 1
fi
if (( ${BRANCH_COVERAGE%.*} < MIN_BRANCH )); then
echo "❌ Branch coverage below $MIN_BRANCH%"
exit 1
fi
echo "✅ Coverage thresholds met."
- name: Upload JaCoCo HTML Report (Artifact)
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: contentstack-java/target/site/jacoco/