Skip to content

Commit 1532936

Browse files
committed
test: add coverage percentages in pom.xml file, add ci steps for coverage badge, add tests information in readmes.md
1 parent 91dade7 commit 1532936

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

.github/workflows/mvn-build-ci.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414
pull-requests: write
1515

1616
jobs:
17-
build:
17+
test-coverage:
1818
runs-on: ubuntu-latest
1919

2020
services:
@@ -49,6 +49,44 @@ jobs:
4949
- name: Build with Maven
5050
run: ./mvnw clean -B package --file pom.xml -Dspring.profiles.active=dev
5151

52+
- name: Switch to coverage-badge branch
53+
run: |
54+
git config --global user.name 'github-actions'
55+
git config --global user.email 'github-actions@github.com'
56+
git fetch origin coverage-badge || echo "Branch not found, creating a new one"
57+
if git rev-parse --verify origin/coverage-badge; then
58+
echo "Branch 'coverage-badge' exists, switching to it."
59+
git checkout coverage-badge
60+
else
61+
echo "Branch 'coverage-badge' does not exist, creating and switching to it."
62+
git checkout --orphan coverage-badge
63+
fi
64+
65+
- name: Generate coverage badge
66+
uses: cicirello/jacoco-badge-generator@v2
67+
with:
68+
jacoco-csv-file: target/jacoco-report/jacoco.csv
69+
badges-directory: .github/badges
70+
71+
- name: Commit and push badge (only if changed)
72+
run: |
73+
git add .github/badges/jacoco.svg
74+
git status
75+
76+
if git diff --cached --quiet; then
77+
echo "No changes to commit"
78+
else
79+
git commit -m "Update test coverage badge"
80+
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/tennyros/subscription-service.git coverage-badge --force
81+
fi
82+
83+
- name: Upload Jacoco coverage report
84+
if: github.actor != 'nektos/act' # check for local GitHub act
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: jacoco-report
88+
path: target/jacoco-report/
89+
5290
- name: Send Telegram notification
5391
if: always()
5492
env:

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Subscription Service
22

33
![CI Status](https://github.com/tennyros/subscription-service/workflows/CI%20Pipeline%20with%20Maven/badge.svg)
4+
![Coverage](https://github.com/tennyros/subscription-service/raw/coverage-badge/.github/badges/jacoco.svg)
45
![Java 17](https://img.shields.io/badge/Java-17-blue)
56
![Spring Boot 3.4.5](https://img.shields.io/badge/Spring_Boot-3.4.5-brightgreen)
67

@@ -48,6 +49,13 @@ Source code structure (branch: dev):
4849
│ ├── application.yml # Main configuration
4950
│ └── application-dev.yml # Development configuration
5051
├── test/ # Tests
52+
│ ├── java/
53+
│ │ └── com/github/tennyros/subscription_service/
54+
│ │ ├── controller/ # Controller layer unit/integration tests
55+
│ │ ├── mapper/ # Mapper unit tests
56+
│ │ └── service/ # Service layer unit tests
57+
│ └── resources/
58+
│ └── application-test.yml # Test configuration
5159
pom.xml
5260
5361
Built artifacts:

README_RUS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Subscription Service
22

33
![CI Status](https://github.com/tennyros/subscription-service/workflows/CI%20Pipeline%20with%20Maven/badge.svg)
4+
![Coverage](https://github.com/tennyros/subscription-service/raw/coverage-badge/.github/badges/jacoco.svg)
45
![Java 17](https://img.shields.io/badge/Java-17-blue)
56
![Spring Boot 3.4.5](https://img.shields.io/badge/Spring_Boot-3.4.5-brightgreen)
67

@@ -48,6 +49,13 @@
4849
│ ├── application.yml # Основная конфигурация
4950
│ └── application-dev.yml # Конфиг для разработки
5051
├── test/ # Тесты
52+
│ ├── java/
53+
│ │ └── com/github/tennyros/subscription_service/
54+
│ │ ├── controller/ # Юнит/интеграционные тесты контроллер слоя
55+
│ │ ├── mapper/ # Юнит тесты мапперов
56+
│ │ └── service/ # Юнит тесты бизнес слоя
57+
│ └── resources/
58+
│ └── application-test.yml # Конфигурация для тестирования
5159
pom.xml
5260
5361
Собранные артефакты:

pom.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
2525
<spring-cloud.version>2024.0.1</spring-cloud.version>
2626
<jacoco.plugin>0.8.13</jacoco.plugin>
27-
<!-- target for instructions 0.8 -->
28-
<jacoco.instructions.cov>0.0</jacoco.instructions.cov>
29-
<!-- target for branches 0.7 -->
30-
<jacoco.branch.cov>0.0</jacoco.branch.cov>
31-
<!-- target for lines 0.75 -->
32-
<jacoco.line.cov>0.0</jacoco.line.cov>
27+
<jacoco.instructions.cov>0.75</jacoco.instructions.cov>
28+
<jacoco.branch.cov>0.7</jacoco.branch.cov>
29+
<jacoco.line.cov>0.75</jacoco.line.cov>
3330
</properties>
3431

3532
<dependencies>

0 commit comments

Comments
 (0)