1818 test :
1919 runs-on : ubuntu-latest
2020
21+ strategy :
22+ matrix :
23+ service : [main, notification, gateway]
24+
2125 steps :
2226 - name : Checkout code
2327 uses : actions/checkout@v4
@@ -40,101 +44,110 @@ jobs:
4044 - name : Verify Docker is running
4145 run : docker info
4246
43- - name : Run all tests
44- run : ./gradlew test --info
45-
46- - name : Generate service-specific coverage reports
47- run : ./gradlew jacocoAllServiceReports --info
48-
49- - name : Upload coverage to Codecov (Main)
47+ - name : Run tests for ${{ matrix.service }} service
48+ run : |
49+ if [ "${{ matrix.service }}" = "main" ]; then
50+ ./gradlew :dms-main:test jacocoMainServiceReport --info
51+ elif [ "${{ matrix.service }}" = "notification" ]; then
52+ ./gradlew :dms-notification:test jacocoNotificationServiceReport --info
53+ elif [ "${{ matrix.service }}" = "gateway" ]; then
54+ ./gradlew :dms-gateway:test jacocoGatewayServiceReport --info
55+ fi
56+
57+ - name : Upload coverage for ${{ matrix.service }}
5058 uses : codecov/codecov-action@v4
5159 with :
5260 token : ${{ secrets.CODECOV_TOKEN }}
53- files : build/reports/jacoco/main -service/jacocoTestReport.xml
54- flags : main -service
55- name : main -service-coverage
61+ files : build/reports/jacoco/${{ matrix.service }} -service/jacocoTestReport.xml
62+ flags : ${{ matrix.service }} -service
63+ name : ${{ matrix.service }} -service-coverage
5664 fail_ci_if_error : false
5765 verbose : true
5866
59- - name : Upload coverage to Codecov (Notification)
60- uses : codecov/codecov-action@v4
67+ test-all :
68+ runs-on : ubuntu-latest
69+ needs : test
70+
71+ steps :
72+ - name : Checkout code
73+ uses : actions/checkout@v4
6174 with :
62- token : ${{ secrets.CODECOV_TOKEN }}
63- files : build/reports/jacoco/notification-service/jacocoTestReport.xml
64- flags : notification-service
65- name : notification-service-coverage
66- fail_ci_if_error : false
67- verbose : true
75+ fetch-depth : 0
6876
69- - name : Upload coverage to Codecov (Gateway)
70- uses : codecov/codecov-action @v4
77+ - name : Set up Java
78+ uses : actions/setup-java @v4
7179 with :
72- token : ${{ secrets.CODECOV_TOKEN }}
73- files : build/reports/jacoco/gateway-service/jacocoTestReport.xml
74- flags : gateway-service
75- name : gateway-service-coverage
76- fail_ci_if_error : false
77- verbose : true
80+ java-version : ' 17'
81+ distribution : ' zulu'
82+ cache : ' gradle'
83+
84+ - name : Setup Gradle
85+ uses : gradle/gradle-build-action@v2
86+
87+ - name : Grant execute permission for gradlew
88+ run : chmod +x gradlew
89+
90+ - name : Verify Docker is running
91+ run : docker info
92+
93+ - name : Run all tests
94+ run : ./gradlew test --info
7895
79- - name : Delete previous coverage comments
96+ - name : Generate service-specific coverage reports
97+ run : ./gradlew jacocoAllServiceReports --info
98+
99+ - name : Verify Jacoco reports exist
100+ run : |
101+ echo "=== Looking for service-specific Jacoco reports ==="
102+ echo "=== Main service report ==="
103+ ls -la build/reports/jacoco/main-service/ || echo "No main service report found"
104+ echo "=== Notification service report ==="
105+ ls -la build/reports/jacoco/notification-service/ || echo "No notification service report found"
106+ echo "=== Gateway service report ==="
107+ ls -la build/reports/jacoco/gateway-service/ || echo "No gateway service report found"
108+
109+ - name : Delete previous JaCoCo comments
80110 if : github.event_name == 'pull_request'
81111 run : |
82- gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
83- --jq '.[] | select(.body | contains("## 📊 Test Coverage Summary")) | .id' | \
84- while read comment_id; do
112+ COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
113+ --jq '.[] | select(.body | contains("Coverage Report")) | .id')
114+
115+ for comment_id in $COMMENTS; do
116+ echo "Deleting comment $comment_id"
85117 gh api repos/${{ github.repository }}/issues/comments/$comment_id -X DELETE
86118 done
87119 env :
88120 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
89121
90- - name : Generate coverage comment
122+ - name : Comment PR with main service coverage
91123 if : github.event_name == 'pull_request'
92- run : |
93- parse_coverage() {
94- local xml_file=$1
95- if [ ! -f "$xml_file" ]; then
96- echo "N/A"
97- return
98- fi
99-
100- local missed=$(grep -o 'type="INSTRUCTION"[^>]*' "$xml_file" | grep -o 'missed="[0-9]*"' | head -1 | grep -o '[0-9]*')
101- local covered=$(grep -o 'type="INSTRUCTION"[^>]*' "$xml_file" | grep -o 'covered="[0-9]*"' | head -1 | grep -o '[0-9]*')
102-
103- if [ -z "$missed" ] || [ -z "$covered" ]; then
104- echo "N/A"
105- return
106- fi
107-
108- local total=$((missed + covered))
109- if [ $total -eq 0 ]; then
110- echo "0.00%"
111- else
112- local coverage=$(awk "BEGIN {printf \"%.2f\", ($covered / $total) * 100}")
113- echo "${coverage}%"
114- fi
115- }
116-
117- MAIN_COVERAGE=$(parse_coverage "build/reports/jacoco/main-service/jacocoTestReport.xml")
118- NOTIFICATION_COVERAGE=$(parse_coverage "build/reports/jacoco/notification-service/jacocoTestReport.xml")
119- GATEWAY_COVERAGE=$(parse_coverage "build/reports/jacoco/gateway-service/jacocoTestReport.xml")
120-
121- COMMENT_BODY=$(cat << 'EOF'
122- ## 📊 Test Coverage Summary
123-
124- | Service | Overall Coverage |
125- |---------|------------------|
126- | Main | MAIN_COV |
127- | Notification | NOTIFICATION_COV |
128- | Gateway | GATEWAY_COV |
129-
130- > Coverage reports generated by JaCoCo
131- EOF
132- )
133-
134- COMMENT_BODY="${COMMENT_BODY//MAIN_COV/$MAIN_COVERAGE}"
135- COMMENT_BODY="${COMMENT_BODY//NOTIFICATION_COV/$NOTIFICATION_COVERAGE}"
136- COMMENT_BODY="${COMMENT_BODY//GATEWAY_COV/$GATEWAY_COVERAGE}"
137-
138- gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT_BODY"
139- env :
140- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124+ uses : madrapps/jacoco-report@v1.6.1
125+ with :
126+ paths : |
127+ build/reports/jacoco/main-service/jacocoTestReport.xml
128+ token : ${{ secrets.GITHUB_TOKEN }}
129+ min-coverage-overall : 24
130+ min-coverage-changed-files : 50
131+ title : ' 📊 Main Service Coverage Report'
132+
133+ - name : Comment PR with notification service coverage
134+ if : github.event_name == 'pull_request'
135+ uses : madrapps/jacoco-report@v1.6.1
136+ with :
137+ paths : |
138+ build/reports/jacoco/notification-service/jacocoTestReport.xml
139+ token : ${{ secrets.GITHUB_TOKEN }}
140+ min-coverage-overall : 25
141+ min-coverage-changed-files : 50
142+ title : ' 📊 Notification Service Coverage Report'
143+
144+ - name : Comment PR with gateway service coverage
145+ if : github.event_name == 'pull_request'
146+ uses : madrapps/jacoco-report@v1.6.1
147+ with :
148+ paths : |
149+ build/reports/jacoco/gateway-service/jacocoTestReport.xml
150+ token : ${{ secrets.GITHUB_TOKEN }}
151+ min-coverage-overall : 0
152+ min-coverage-changed-files : 50
153+ title : ' 📊 Gateway Service Coverage Report'
0 commit comments